2013-08-23 13:23:35 +02:00
|
|
|
|
/* Copyright (c) Citrix Systems Inc.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms,
|
|
|
|
|
* with or without modification, are permitted provided
|
|
|
|
|
* that the following conditions are met:
|
|
|
|
|
*
|
|
|
|
|
* * Redistributions of source code must retain the above
|
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
|
* following disclaimer.
|
|
|
|
|
* * Redistributions in binary form must reproduce the above
|
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
|
* following disclaimer in the documentation and/or other
|
|
|
|
|
* materials provided with the distribution.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
|
|
|
|
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
|
|
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
2013-08-24 18:00:32 +02:00
|
|
|
|
using System.Diagnostics;
|
2013-08-23 13:23:35 +02:00
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
2013-08-24 18:00:32 +02:00
|
|
|
|
using XenAdmin.Commands;
|
|
|
|
|
using XenAdmin.Core;
|
|
|
|
|
using XenAdmin.Model;
|
|
|
|
|
using XenAdmin.Network;
|
|
|
|
|
using XenAdmin.XenSearch;
|
|
|
|
|
|
|
|
|
|
using XenAPI;
|
|
|
|
|
|
2013-08-23 13:23:35 +02:00
|
|
|
|
namespace XenAdmin.Controls.MainWindowControls
|
|
|
|
|
{
|
|
|
|
|
public partial class NavigationView : UserControl
|
|
|
|
|
{
|
2013-08-24 18:00:32 +02:00
|
|
|
|
#region Private fields
|
|
|
|
|
|
|
|
|
|
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
|
|
|
|
2013-08-26 12:42:32 +02:00
|
|
|
|
private readonly SelectionManager selectionManager = new SelectionManager();
|
2013-08-24 18:00:32 +02:00
|
|
|
|
private readonly MainWindowTreeBuilder treeBuilder;
|
2013-08-25 15:06:03 +02:00
|
|
|
|
private readonly UpdateManager treeViewUpdateManager = new UpdateManager(30 * 1000);
|
2013-08-24 18:00:32 +02:00
|
|
|
|
|
|
|
|
|
private VirtualTreeNode _highlightedDragTarget;
|
|
|
|
|
private int ignoreRefreshTreeView;
|
|
|
|
|
private bool calledRefreshTreeView;
|
2013-08-25 13:42:38 +02:00
|
|
|
|
private bool inMajorChange;
|
2013-08-24 18:00:32 +02:00
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Events
|
|
|
|
|
|
|
|
|
|
[Browsable(true)]
|
2013-08-26 12:42:32 +02:00
|
|
|
|
public event Action TreeViewSelectionChanged;
|
2013-08-24 18:00:32 +02:00
|
|
|
|
|
|
|
|
|
[Browsable(true)]
|
|
|
|
|
public event Action TreeNodeBeforeSelected;
|
|
|
|
|
|
|
|
|
|
[Browsable(true)]
|
|
|
|
|
public event Action TreeNodeClicked;
|
|
|
|
|
|
|
|
|
|
[Browsable(true)]
|
|
|
|
|
public event Action TreeNodeRightClicked;
|
|
|
|
|
|
|
|
|
|
[Browsable(true)]
|
|
|
|
|
public event Action TreeViewRefreshed;
|
|
|
|
|
|
|
|
|
|
[Browsable(true)]
|
|
|
|
|
public event Action TreeViewRefreshSuspended;
|
|
|
|
|
|
|
|
|
|
[Browsable(true)]
|
|
|
|
|
public event Action TreeViewRefreshResumed;
|
|
|
|
|
|
2013-11-12 13:44:19 +01:00
|
|
|
|
internal event Action<string> DragDropCommandActivated;
|
|
|
|
|
|
2013-08-24 18:00:32 +02:00
|
|
|
|
#endregion
|
|
|
|
|
|
2013-08-23 13:23:35 +02:00
|
|
|
|
public NavigationView()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2013-08-24 18:00:32 +02:00
|
|
|
|
|
2013-11-07 16:31:13 +01:00
|
|
|
|
panel1.BackColor = Program.TitleBarBorderColor;
|
|
|
|
|
|
2013-08-24 18:00:32 +02:00
|
|
|
|
treeView.ImageList = Images.ImageList16;
|
|
|
|
|
if (treeView.ItemHeight < 18)
|
|
|
|
|
treeView.ItemHeight = 18;
|
|
|
|
|
//otherwise it's too close together on XP and the icons crash into each other
|
|
|
|
|
|
|
|
|
|
VirtualTreeNode n = new VirtualTreeNode(Messages.XENCENTER);
|
|
|
|
|
n.NodeFont = Program.DefaultFont;
|
|
|
|
|
treeView.Nodes.Add(n);
|
|
|
|
|
treeView.SelectedNode = treeView.Nodes[0];
|
|
|
|
|
|
|
|
|
|
treeBuilder = new MainWindowTreeBuilder(treeView);
|
2013-08-25 15:06:03 +02:00
|
|
|
|
treeViewUpdateManager.Update += treeViewUpdateManager_Update;
|
2013-08-23 13:23:35 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-28 15:44:46 +02:00
|
|
|
|
#region Accessors
|
|
|
|
|
|
2013-08-26 12:42:32 +02:00
|
|
|
|
public NavigationPane.NavigationMode NavigationMode { get; set; }
|
2013-08-23 13:32:14 +02:00
|
|
|
|
|
2013-08-24 18:00:32 +02:00
|
|
|
|
public Search CurrentSearch { get; set; }
|
|
|
|
|
|
2013-08-25 13:42:38 +02:00
|
|
|
|
public bool InSearchMode { get; set; }
|
|
|
|
|
|
2013-08-26 12:42:32 +02:00
|
|
|
|
internal SelectionBroadcaster SelectionManager
|
|
|
|
|
{
|
|
|
|
|
get { return selectionManager; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2013-08-25 13:42:38 +02:00
|
|
|
|
#region Connection
|
|
|
|
|
|
|
|
|
|
public void XenConnectionCollectionChanged(CollectionChangeEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
IXenConnection connection = (IXenConnection)e.Element;
|
|
|
|
|
if (connection == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (e.Action == CollectionChangeAction.Add)
|
|
|
|
|
{
|
|
|
|
|
connection.BeforeMajorChange += Connection_BeforeMajorChange;
|
|
|
|
|
connection.AfterMajorChange += Connection_AfterMajorChange;
|
|
|
|
|
}
|
|
|
|
|
else if (e.Action == CollectionChangeAction.Remove)
|
|
|
|
|
{
|
|
|
|
|
connection.BeforeMajorChange -= Connection_BeforeMajorChange;
|
|
|
|
|
connection.AfterMajorChange -= Connection_AfterMajorChange;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Connection_BeforeMajorChange(object sender, ConnectionMajorChangeEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2015-04-16 15:17:02 +02:00
|
|
|
|
Program.Invoke(this, () =>
|
2013-08-25 13:42:38 +02:00
|
|
|
|
{
|
|
|
|
|
if (!e.Background)
|
|
|
|
|
{
|
|
|
|
|
if (inMajorChange)
|
|
|
|
|
return;
|
|
|
|
|
inMajorChange = true;
|
|
|
|
|
}
|
|
|
|
|
SuspendRefreshTreeView();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exn)
|
|
|
|
|
{
|
|
|
|
|
log.Error(exn, exn);
|
|
|
|
|
// Can do nothing more about this.
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Connection_AfterMajorChange(object sender, ConnectionMajorChangeEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2015-04-16 15:17:02 +02:00
|
|
|
|
Program.Invoke(this, () =>
|
2013-08-25 13:42:38 +02:00
|
|
|
|
{
|
|
|
|
|
ResumeRefreshTreeView();
|
|
|
|
|
|
|
|
|
|
if (!e.Background)
|
|
|
|
|
inMajorChange = false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exn)
|
|
|
|
|
{
|
|
|
|
|
log.Error(exn, exn);
|
|
|
|
|
// Can do nothing more about this.
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2013-08-23 13:32:14 +02:00
|
|
|
|
#region SearchBox
|
|
|
|
|
|
2013-08-23 13:23:35 +02:00
|
|
|
|
public void ResetSeachBox()
|
|
|
|
|
{
|
|
|
|
|
searchTextBox.Reset();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void searchTextBox_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2013-08-25 15:06:03 +02:00
|
|
|
|
RequestRefreshTreeView();
|
2013-08-23 13:23:35 +02:00
|
|
|
|
}
|
2013-08-23 13:32:14 +02:00
|
|
|
|
|
|
|
|
|
#endregion
|
2013-08-24 18:00:32 +02:00
|
|
|
|
|
|
|
|
|
#region TreeView
|
|
|
|
|
|
2013-08-25 15:06:03 +02:00
|
|
|
|
private void treeViewUpdateManager_Update(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Program.AssertOffEventThread();
|
|
|
|
|
RefreshTreeView();
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-26 12:42:32 +02:00
|
|
|
|
|
2013-08-25 13:42:38 +02:00
|
|
|
|
public void MajorChange(MethodInvoker f)
|
|
|
|
|
{
|
|
|
|
|
Program.AssertOnEventThread();
|
|
|
|
|
|
|
|
|
|
if (inMajorChange)
|
|
|
|
|
{
|
|
|
|
|
f();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
inMajorChange = true;
|
|
|
|
|
SuspendRefreshTreeView();
|
|
|
|
|
f();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
log.Debug("Exception thrown by target of MajorChange.", e);
|
|
|
|
|
log.Debug(e, e);
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
ResumeRefreshTreeView();
|
|
|
|
|
inMajorChange = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SaveAndRestoreTreeViewFocus(MethodInvoker f)
|
2013-08-24 18:00:32 +02:00
|
|
|
|
{
|
2013-08-25 13:42:38 +02:00
|
|
|
|
bool treeViewHasFocus = treeView.ContainsFocus;
|
2013-08-26 12:42:32 +02:00
|
|
|
|
searchTextBox.SaveState();
|
2013-08-25 13:42:38 +02:00
|
|
|
|
|
|
|
|
|
f();
|
|
|
|
|
|
|
|
|
|
if (!InSearchMode && treeViewHasFocus)
|
|
|
|
|
FocusTreeView();
|
|
|
|
|
|
2013-08-26 12:42:32 +02:00
|
|
|
|
searchTextBox.RestoreState();
|
2013-08-24 18:00:32 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Selects the specified object in the treeview.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="o">The object to be selected.</param>
|
|
|
|
|
/// <param name="expand">A value specifying whether the node should be expanded when it's found.
|
|
|
|
|
/// If false, the node is left in the state it's found in.</param>
|
|
|
|
|
/// <returns>A value indicating whether selection was successful.</returns>
|
|
|
|
|
public bool SelectObject(IXenObject o, bool expand)
|
|
|
|
|
{
|
|
|
|
|
bool cancelled = false;
|
|
|
|
|
if (treeView.Nodes.Count == 0)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
bool success = treeView.SelectObject(o, treeView.Nodes[0], expand, ref cancelled);
|
|
|
|
|
|
2013-08-26 12:42:32 +02:00
|
|
|
|
if (!success && !cancelled && searchTextBox.Text.Length > 0)
|
2013-08-24 18:00:32 +02:00
|
|
|
|
{
|
|
|
|
|
// if the node could not be found and the node *is* selectable then it means that
|
|
|
|
|
// node isn't visible with the current search. So clear the search and try and
|
|
|
|
|
// select the object again.
|
|
|
|
|
|
|
|
|
|
// clear search.
|
|
|
|
|
ResetSeachBox();
|
|
|
|
|
|
|
|
|
|
// update the treeview
|
|
|
|
|
RefreshTreeView();
|
|
|
|
|
|
|
|
|
|
// and try again.
|
|
|
|
|
return treeView.SelectObject(o, treeView.Nodes[0], expand, ref cancelled);
|
|
|
|
|
}
|
|
|
|
|
return success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool TryToSelectNewNode(Predicate<object> tagMatch, bool selectNode, bool expandNode, bool ensureNodeVisible)
|
|
|
|
|
{
|
|
|
|
|
return treeView.TryToSelectNewNode(tagMatch, selectNode, expandNode, ensureNodeVisible);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void EditSelectedNode()
|
|
|
|
|
{
|
2013-08-25 15:06:03 +02:00
|
|
|
|
SuspendRefreshTreeView();
|
2013-08-24 18:00:32 +02:00
|
|
|
|
treeView.LabelEdit = true;
|
|
|
|
|
treeView.SelectedNode.BeginEdit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void FocusTreeView()
|
|
|
|
|
{
|
|
|
|
|
treeView.Focus();
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-29 16:13:39 +02:00
|
|
|
|
public void ForceTreeViewSelectionsChanged()
|
|
|
|
|
{
|
|
|
|
|
treeView.ForceSelectionsChanged();
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-26 12:42:32 +02:00
|
|
|
|
public void RequestRefreshTreeView()
|
|
|
|
|
{
|
CA-147941: Fixed the RPU wizard hang in "Reconnecting Storage" and connecting action stuck in progress state
In some cases calling Control.Invoke() from a background thread causes that thread to go in a "sleep, wait, or join" mode, while waiting for Invoke to happen, although the UI thread is running normally.
If the Control is the MainWindow, it works as expected, but we've seen it happening while connecting or disconnecting from a large pool, on calling Invoke on controls like NavigationView, AlertSummaryPage, HistoryPage, etc.
To fix this, we call the Invoke on the MainWindow in all the places where we've seen the issue.
With this changes, the previous fix for CA-148245 (call RequestRefreshTreeView on CacheClearing event) is not needed anymore, so I removed that call.
Signed-off-by: Mihaela Stoica <mihaela.stoica@citrix.com>
2014-10-10 14:16:50 +02:00
|
|
|
|
Program.BeginInvoke(Program.MainWindow, treeViewUpdateManager.RequestUpdate);
|
2013-08-26 12:42:32 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-25 15:06:03 +02:00
|
|
|
|
private void SuspendRefreshTreeView()
|
2013-08-24 18:00:32 +02:00
|
|
|
|
{
|
|
|
|
|
Program.AssertOnEventThread();
|
|
|
|
|
|
|
|
|
|
if (ignoreRefreshTreeView == 0)
|
|
|
|
|
calledRefreshTreeView = false;
|
|
|
|
|
ignoreRefreshTreeView++;
|
|
|
|
|
|
|
|
|
|
if (TreeViewRefreshSuspended != null)
|
|
|
|
|
TreeViewRefreshSuspended();
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-25 15:06:03 +02:00
|
|
|
|
private void ResumeRefreshTreeView()
|
2013-08-24 18:00:32 +02:00
|
|
|
|
{
|
|
|
|
|
Program.AssertOnEventThread();
|
|
|
|
|
|
|
|
|
|
ignoreRefreshTreeView--;
|
|
|
|
|
if (ignoreRefreshTreeView == 0 && calledRefreshTreeView)
|
2013-08-25 15:06:03 +02:00
|
|
|
|
RequestRefreshTreeView();
|
2013-08-24 18:00:32 +02:00
|
|
|
|
|
|
|
|
|
if (TreeViewRefreshResumed != null)
|
|
|
|
|
TreeViewRefreshResumed();
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-01 18:51:17 +02:00
|
|
|
|
// Normally you should call RequestRefreshTreeView() instead of this function
|
2014-10-01 18:43:03 +02:00
|
|
|
|
public void RefreshTreeView()
|
2013-08-24 18:00:32 +02:00
|
|
|
|
{
|
2014-03-05 11:45:39 +01:00
|
|
|
|
if (Disposing || IsDisposed || Program.Exiting)
|
|
|
|
|
return;
|
|
|
|
|
|
CA-147941: Fixed the RPU wizard hang in "Reconnecting Storage" and connecting action stuck in progress state
In some cases calling Control.Invoke() from a background thread causes that thread to go in a "sleep, wait, or join" mode, while waiting for Invoke to happen, although the UI thread is running normally.
If the Control is the MainWindow, it works as expected, but we've seen it happening while connecting or disconnecting from a large pool, on calling Invoke on controls like NavigationView, AlertSummaryPage, HistoryPage, etc.
To fix this, we call the Invoke on the MainWindow in all the places where we've seen the issue.
With this changes, the previous fix for CA-148245 (call RequestRefreshTreeView on CacheClearing event) is not needed anymore, so I removed that call.
Signed-off-by: Mihaela Stoica <mihaela.stoica@citrix.com>
2014-10-10 14:16:50 +02:00
|
|
|
|
Program.Invoke(Program.MainWindow, () =>
|
2013-08-24 18:00:32 +02:00
|
|
|
|
{
|
|
|
|
|
if (ignoreRefreshTreeView > 0)
|
|
|
|
|
{
|
|
|
|
|
calledRefreshTreeView = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ignoreRefreshTreeView++; // Some events can be ignored while rebuilding the tree
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2013-08-28 15:44:46 +02:00
|
|
|
|
var newRootNode = treeBuilder.CreateNewRootNode(CurrentSearch.AddFullTextFilter(searchTextBox.Text), NavigationMode);
|
2013-08-26 12:42:32 +02:00
|
|
|
|
treeBuilder.RefreshTreeView(newRootNode, searchTextBox.Text, NavigationMode);
|
2013-08-24 18:00:32 +02:00
|
|
|
|
}
|
|
|
|
|
catch (Exception exn)
|
|
|
|
|
{
|
|
|
|
|
log.Error(exn, exn);
|
|
|
|
|
#if DEBUG
|
|
|
|
|
if (Debugger.IsAttached)
|
|
|
|
|
throw;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
ignoreRefreshTreeView--;
|
|
|
|
|
}
|
2013-08-28 15:44:46 +02:00
|
|
|
|
|
2013-08-24 18:00:32 +02:00
|
|
|
|
if (TreeViewRefreshed != null)
|
2013-08-28 15:44:46 +02:00
|
|
|
|
TreeViewRefreshed();
|
2013-08-24 18:00:32 +02:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static Pool PoolAncestorOfNode(VirtualTreeNode node)
|
|
|
|
|
{
|
|
|
|
|
while (node != null)
|
|
|
|
|
{
|
|
|
|
|
var pool = node.Tag as Pool;
|
|
|
|
|
if (pool != null)
|
|
|
|
|
return pool;
|
|
|
|
|
|
|
|
|
|
node = node.Parent;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static Host HostAncestorOfNode(VirtualTreeNode node)
|
|
|
|
|
{
|
|
|
|
|
while (node != null)
|
|
|
|
|
{
|
|
|
|
|
var host = node.Tag as Host;
|
|
|
|
|
if (host != null)
|
|
|
|
|
return host;
|
|
|
|
|
|
|
|
|
|
node = node.Parent;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-08 11:17:57 +02:00
|
|
|
|
private static GroupingTag GroupAncestorOfNode(VirtualTreeNode node)
|
|
|
|
|
{
|
|
|
|
|
while (node != null)
|
|
|
|
|
{
|
|
|
|
|
var group = node.Tag as GroupingTag;
|
|
|
|
|
if (group != null)
|
|
|
|
|
return group;
|
|
|
|
|
|
|
|
|
|
node = node.Parent;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-24 18:00:32 +02:00
|
|
|
|
private bool CanDrag()
|
|
|
|
|
{
|
2013-08-26 14:08:23 +02:00
|
|
|
|
if (NavigationMode == NavigationPane.NavigationMode.Infrastructure
|
2013-08-30 14:35:32 +02:00
|
|
|
|
|| NavigationMode == NavigationPane.NavigationMode.SavedSearch)
|
2013-08-24 18:00:32 +02:00
|
|
|
|
{
|
2013-08-30 14:35:32 +02:00
|
|
|
|
return Program.MainWindow.SelectionManager.Selection.AllItemsAre<Host>()
|
|
|
|
|
|| Program.MainWindow.SelectionManager.Selection.AllItemsAre<VM>(vm => !vm.is_a_template);
|
2013-08-24 18:00:32 +02:00
|
|
|
|
}
|
2013-08-26 14:08:23 +02:00
|
|
|
|
|
2013-08-24 18:00:32 +02:00
|
|
|
|
foreach (SelectedItem item in Program.MainWindow.SelectionManager.Selection)
|
|
|
|
|
{
|
|
|
|
|
if (item.XenObject == null || item.Connection == null || !item.Connection.IsConnected)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<DragDropCommand> GetDragDropCommands(VirtualTreeNode targetNode, IDataObject dragData)
|
|
|
|
|
{
|
|
|
|
|
List<DragDropCommand> commands = new List<DragDropCommand>();
|
2014-01-22 13:39:32 +01:00
|
|
|
|
commands.Add(new DragDropAddHostToPoolCommand(Program.MainWindow, targetNode, dragData));
|
|
|
|
|
commands.Add(new DragDropMigrateVMCommand(Program.MainWindow, targetNode, dragData));
|
|
|
|
|
commands.Add(new DragDropRemoveHostFromPoolCommand(Program.MainWindow, targetNode, dragData));
|
2015-04-20 11:48:11 +02:00
|
|
|
|
commands.Add(new DragDropCrossPoolMoveHaltedVMCommand(Program.MainWindow, targetNode, dragData));
|
2013-08-24 18:00:32 +02:00
|
|
|
|
|
2013-08-26 14:08:23 +02:00
|
|
|
|
if (NavigationMode == NavigationPane.NavigationMode.Tags
|
|
|
|
|
|| NavigationMode == NavigationPane.NavigationMode.Folders
|
|
|
|
|
|| NavigationMode == NavigationPane.NavigationMode.CustomFields
|
|
|
|
|
|| NavigationMode == NavigationPane.NavigationMode.vApps)
|
2013-08-24 18:00:32 +02:00
|
|
|
|
{
|
2014-01-22 13:39:32 +01:00
|
|
|
|
commands.Add(new DragDropTagCommand(Program.MainWindow, targetNode, dragData));
|
|
|
|
|
commands.Add(new DragDropIntoFolderCommand(Program.MainWindow, targetNode, dragData));
|
2013-08-24 18:00:32 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return commands;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ClearHighlightedDragTarget()
|
|
|
|
|
{
|
|
|
|
|
if (_highlightedDragTarget != null)
|
|
|
|
|
{
|
|
|
|
|
_highlightedDragTarget.BackColor = treeView.BackColor;
|
|
|
|
|
_highlightedDragTarget.ForeColor = treeView.ForeColor;
|
|
|
|
|
_highlightedDragTarget = null;
|
|
|
|
|
treeBuilder.HighlightedDragTarget = null;
|
2013-11-12 13:44:19 +01:00
|
|
|
|
|
|
|
|
|
if (DragDropCommandActivated != null)
|
|
|
|
|
DragDropCommandActivated(null);
|
2013-08-24 18:00:32 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void HandleNodeRightClick(VirtualTreeNodeMouseClickEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Button != MouseButtons.Right)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (treeView.SelectedNodes.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
treeView.SelectedNode = e.Node;
|
|
|
|
|
|
|
|
|
|
if (treeView.SelectedNode != e.Node) // if node is unselectable in TreeView_BeforeSelect: CA-26615
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (TreeNodeRightClicked != null)
|
|
|
|
|
TreeNodeRightClicked();
|
|
|
|
|
|
|
|
|
|
TreeContextMenu.Items.Clear();
|
|
|
|
|
|
|
|
|
|
if (e.Node == treeView.Nodes[0] && treeView.SelectedNodes.Count == 1)
|
|
|
|
|
{
|
2013-10-08 11:17:57 +02:00
|
|
|
|
if (e.Node.Tag == null)// XenCenter (top most)
|
|
|
|
|
{
|
2014-01-22 13:39:32 +01:00
|
|
|
|
TreeContextMenu.Items.Add(new CommandToolStripMenuItem(new AddHostCommand(Program.MainWindow), true));
|
|
|
|
|
TreeContextMenu.Items.Add(new CommandToolStripMenuItem(new NewPoolCommand(Program.MainWindow, new SelectedItem[0]), true));
|
|
|
|
|
TreeContextMenu.Items.Add(new CommandToolStripMenuItem(new ConnectAllHostsCommand(Program.MainWindow), true));
|
|
|
|
|
TreeContextMenu.Items.Add(new CommandToolStripMenuItem(new DisconnectAllHostsCommand(Program.MainWindow), true));
|
2013-10-08 11:17:57 +02:00
|
|
|
|
}
|
2013-12-31 16:47:52 +01:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var groupingTag = e.Node.Tag as GroupingTag;
|
|
|
|
|
if (groupingTag != null && groupingTag.Grouping as OrganizationViewFolders != null)
|
|
|
|
|
TreeContextMenu.Items.Add(new CommandToolStripMenuItem(
|
2014-01-22 13:39:32 +01:00
|
|
|
|
new NewFolderCommand(Program.MainWindow, new[] { new SelectedItem(groupingTag, e.Node) }),
|
2013-12-31 16:47:52 +01:00
|
|
|
|
true));
|
|
|
|
|
}
|
2013-08-24 18:00:32 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
TreeContextMenu.Items.AddRange(Program.MainWindow.ContextMenuBuilder.Build(Program.MainWindow.SelectionManager.Selection));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int insertIndex = TreeContextMenu.Items.Count;
|
|
|
|
|
|
|
|
|
|
if (TreeContextMenu.Items.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
CommandToolStripMenuItem lastItem = TreeContextMenu.Items[TreeContextMenu.Items.Count - 1] as CommandToolStripMenuItem;
|
|
|
|
|
|
|
|
|
|
if (lastItem != null && lastItem.Command is PropertiesCommand)
|
|
|
|
|
insertIndex--;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AddExpandCollapseItems(insertIndex, treeView.SelectedNodes);
|
|
|
|
|
AddOrgViewItems(insertIndex, treeView.SelectedNodes);
|
|
|
|
|
|
|
|
|
|
if (TreeContextMenu.Items.Count > 0)
|
2013-11-04 13:35:53 +01:00
|
|
|
|
{
|
|
|
|
|
TreeContextMenu.Show(treeView.PointToScreen(Point.Empty) + (Size)treeView.LastMouseDownEventPosition);
|
|
|
|
|
}
|
2013-08-24 18:00:32 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AddExpandCollapseItems(int insertIndex, IList<VirtualTreeNode> nodes)
|
|
|
|
|
{
|
|
|
|
|
if (nodes.Count == 1 && nodes[0].Nodes.Count == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2014-01-22 13:39:32 +01:00
|
|
|
|
Command cmd = new CollapseChildTreeNodesCommand(Program.MainWindow, nodes);
|
2013-08-24 18:00:32 +02:00
|
|
|
|
if (cmd.CanExecute())
|
|
|
|
|
TreeContextMenu.Items.Insert(insertIndex, new CommandToolStripMenuItem(cmd, true));
|
|
|
|
|
|
2014-01-22 13:39:32 +01:00
|
|
|
|
cmd = new ExpandTreeNodesCommand(Program.MainWindow, nodes);
|
2013-08-24 18:00:32 +02:00
|
|
|
|
if (cmd.CanExecute())
|
|
|
|
|
TreeContextMenu.Items.Insert(insertIndex, new CommandToolStripMenuItem(cmd, true));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AddOrgViewItems(int insertIndex, IList<VirtualTreeNode> nodes)
|
|
|
|
|
{
|
2013-08-26 14:08:23 +02:00
|
|
|
|
if (NavigationMode == NavigationPane.NavigationMode.Infrastructure
|
|
|
|
|
|| NavigationMode == NavigationPane.NavigationMode.SavedSearch
|
|
|
|
|
|| NavigationMode == NavigationPane.NavigationMode.Notifications
|
2013-08-24 18:00:32 +02:00
|
|
|
|
|| nodes.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-22 13:39:32 +01:00
|
|
|
|
Command cmd = new RemoveFromFolderCommand(Program.MainWindow, nodes);
|
2013-08-24 18:00:32 +02:00
|
|
|
|
|
|
|
|
|
if (cmd.CanExecute())
|
|
|
|
|
TreeContextMenu.Items.Insert(insertIndex, new CommandToolStripMenuItem(cmd, true));
|
|
|
|
|
|
2014-01-22 13:39:32 +01:00
|
|
|
|
cmd = new UntagCommand(Program.MainWindow, nodes);
|
2013-08-24 18:00:32 +02:00
|
|
|
|
|
|
|
|
|
if (cmd.CanExecute())
|
|
|
|
|
TreeContextMenu.Items.Insert(insertIndex, new CommandToolStripMenuItem(cmd, true));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void treeView_AfterLabelEdit(object sender, VirtualNodeLabelEditEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
VirtualTreeNode node = e.Node;
|
|
|
|
|
treeView.LabelEdit = false;
|
|
|
|
|
Folder folder = e.Node.Tag as Folder;
|
|
|
|
|
GroupingTag groupingTag = e.Node.Tag as GroupingTag;
|
|
|
|
|
Command command = null;
|
|
|
|
|
object newTag = null;
|
|
|
|
|
|
|
|
|
|
EventHandler<RenameCompletedEventArgs> completed = delegate(object s, RenameCompletedEventArgs ee)
|
|
|
|
|
{
|
2015-04-16 15:17:02 +02:00
|
|
|
|
Program.Invoke(this, delegate
|
2013-08-24 18:00:32 +02:00
|
|
|
|
{
|
|
|
|
|
ResumeRefreshTreeView();
|
|
|
|
|
|
|
|
|
|
if (ee.Success)
|
|
|
|
|
{
|
|
|
|
|
// the new tag is updated on the node here. This ensures that the node stays selected
|
|
|
|
|
// when the treeview is refreshed. If you don't set the tag like this, the treeview refresh code notices
|
|
|
|
|
// that the tags are different and selects the parent node instead of this node.
|
|
|
|
|
|
|
|
|
|
// if the command fails for some reason, the refresh code will correctly revert the tag back to the original.
|
|
|
|
|
node.Tag = newTag;
|
|
|
|
|
RefreshTreeView();
|
|
|
|
|
|
|
|
|
|
// since the selected node doesn't actually change, then a selectionsChanged message doesn't get fired
|
|
|
|
|
// and the selection doesn't get updated to be the new tag/folder. Do it manually here instead.
|
|
|
|
|
treeView_SelectionsChanged(treeView, EventArgs.Empty);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(e.Label))
|
|
|
|
|
{
|
|
|
|
|
if (folder != null)
|
|
|
|
|
{
|
2014-01-22 13:39:32 +01:00
|
|
|
|
RenameFolderCommand cmd = new RenameFolderCommand(Program.MainWindow, folder, e.Label);
|
2013-08-24 18:00:32 +02:00
|
|
|
|
command = cmd;
|
|
|
|
|
cmd.Completed += completed;
|
|
|
|
|
newTag = new Folder(null, e.Label);
|
|
|
|
|
}
|
|
|
|
|
else if (groupingTag != null)
|
|
|
|
|
{
|
2014-01-22 13:39:32 +01:00
|
|
|
|
RenameTagCommand cmd = new RenameTagCommand(Program.MainWindow, groupingTag.Group.ToString(), e.Label);
|
2013-08-24 18:00:32 +02:00
|
|
|
|
command = cmd;
|
|
|
|
|
cmd.Completed += completed;
|
|
|
|
|
newTag = new GroupingTag(groupingTag.Grouping, groupingTag.Parent, e.Label);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (command != null && command.CanExecute())
|
|
|
|
|
{
|
|
|
|
|
command.Execute();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ResumeRefreshTreeView();
|
|
|
|
|
e.CancelEdit = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void treeView_BeforeSelect(object sender, VirtualTreeViewCancelEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Node == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!treeView.CanSelectNode(e.Node))
|
|
|
|
|
{
|
|
|
|
|
e.Cancel = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (TreeNodeBeforeSelected != null)
|
|
|
|
|
TreeNodeBeforeSelected();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void treeView_ItemDrag(object sender, VirtualTreeViewItemDragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
foreach (VirtualTreeNode node in e.Nodes)
|
|
|
|
|
{
|
|
|
|
|
if (node == null || node.TreeView == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// select the node if it isn't already selected
|
|
|
|
|
if (e.Nodes.Count == 1 && treeView.SelectedNode != e.Nodes[0])
|
|
|
|
|
{
|
|
|
|
|
treeView.SelectedNode = e.Nodes[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (CanDrag())
|
|
|
|
|
{
|
|
|
|
|
DoDragDrop(new List<VirtualTreeNode>(e.Nodes).ToArray(), DragDropEffects.Move);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void treeView_DragDrop(object sender, DragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ClearHighlightedDragTarget();
|
|
|
|
|
|
|
|
|
|
VirtualTreeNode targetNode = treeView.GetNodeAt(treeView.PointToClient(new Point(e.X, e.Y)));
|
|
|
|
|
|
|
|
|
|
foreach (DragDropCommand cmd in GetDragDropCommands(targetNode, e.Data))
|
|
|
|
|
{
|
|
|
|
|
if (cmd.CanExecute())
|
|
|
|
|
{
|
|
|
|
|
cmd.Execute();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void treeView_DragEnter(object sender, DragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
e.Effect = DragDropEffects.None;
|
|
|
|
|
VirtualTreeNode targetNode = treeView.GetNodeAt(treeView.PointToClient(new Point(e.X, e.Y)));
|
|
|
|
|
foreach (DragDropCommand cmd in GetDragDropCommands(targetNode, e.Data))
|
|
|
|
|
{
|
|
|
|
|
if (cmd.CanExecute())
|
|
|
|
|
{
|
|
|
|
|
e.Effect = DragDropEffects.Move;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void treeView_DragLeave(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ClearHighlightedDragTarget();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void treeView_DragOver(object sender, DragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// CA-11457: When dragging in resource tree, view doesn't scroll
|
|
|
|
|
// http://www.fmsinc.com/freE/NewTips/NET/NETtip21.asp
|
|
|
|
|
|
|
|
|
|
const int SCROLL_REGION = 20;
|
|
|
|
|
|
|
|
|
|
Point pt = treeView.PointToClient(Cursor.Position);
|
|
|
|
|
VirtualTreeNode targetNode = treeView.GetNodeAt(treeView.PointToClient(new Point(e.X, e.Y)));
|
|
|
|
|
|
|
|
|
|
if ((pt.Y + SCROLL_REGION) > treeView.Height)
|
|
|
|
|
{
|
|
|
|
|
Win32.SendMessage(treeView.Handle, Win32.WM_VSCROLL, new IntPtr(1), IntPtr.Zero);
|
|
|
|
|
}
|
|
|
|
|
else if (pt.Y < SCROLL_REGION)
|
|
|
|
|
{
|
|
|
|
|
Win32.SendMessage(treeView.Handle, Win32.WM_VSCROLL, IntPtr.Zero, IntPtr.Zero);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VirtualTreeNode targetToHighlight = null;
|
2013-11-12 13:44:19 +01:00
|
|
|
|
|
|
|
|
|
string statusBarText = null;
|
2013-08-24 18:00:32 +02:00
|
|
|
|
foreach (DragDropCommand cmd in GetDragDropCommands(targetNode, e.Data))
|
|
|
|
|
{
|
|
|
|
|
if (cmd.CanExecute())
|
|
|
|
|
targetToHighlight = cmd.HighlightNode;
|
2013-11-12 13:44:19 +01:00
|
|
|
|
|
|
|
|
|
if (cmd.StatusBarText != null)
|
|
|
|
|
statusBarText = cmd.StatusBarText;
|
2013-08-24 18:00:32 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-12 13:44:19 +01:00
|
|
|
|
if (DragDropCommandActivated != null)
|
|
|
|
|
DragDropCommandActivated(statusBarText);
|
|
|
|
|
|
2013-08-24 18:00:32 +02:00
|
|
|
|
if (targetToHighlight != null)
|
|
|
|
|
{
|
|
|
|
|
if (_highlightedDragTarget != targetToHighlight)
|
|
|
|
|
{
|
|
|
|
|
ClearHighlightedDragTarget();
|
|
|
|
|
treeBuilder.HighlightedDragTarget = targetToHighlight.Tag;
|
|
|
|
|
_highlightedDragTarget = targetToHighlight;
|
|
|
|
|
_highlightedDragTarget.BackColor = SystemColors.Highlight;
|
|
|
|
|
_highlightedDragTarget.ForeColor = SystemColors.HighlightText;
|
|
|
|
|
}
|
|
|
|
|
e.Effect = DragDropEffects.Move;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ClearHighlightedDragTarget();
|
|
|
|
|
e.Effect = DragDropEffects.None;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void treeView_KeyUp(object sender, KeyEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
switch (e.KeyCode)
|
|
|
|
|
{
|
|
|
|
|
case Keys.Apps:
|
|
|
|
|
if (treeView.SelectedNode != null)
|
|
|
|
|
{
|
|
|
|
|
treeView.SelectedNode.EnsureVisible();
|
|
|
|
|
HandleNodeRightClick(new VirtualTreeNodeMouseClickEventArgs(treeView.SelectedNode,
|
|
|
|
|
MouseButtons.Right, 1,
|
|
|
|
|
treeView.SelectedNode.Bounds.X,
|
|
|
|
|
treeView.SelectedNode.Bounds.Y + treeView.SelectedNode.Bounds.Height));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Keys.F2:
|
2014-01-22 13:39:32 +01:00
|
|
|
|
var cmd = new PropertiesCommand(Program.MainWindow, Program.MainWindow.SelectionManager.Selection);
|
2013-08-24 18:00:32 +02:00
|
|
|
|
if (cmd.CanExecute())
|
|
|
|
|
cmd.Execute();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void treeView_NodeMouseClick(object sender, VirtualTreeNodeMouseClickEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (treeView.Nodes.Count > 0)
|
|
|
|
|
HandleNodeRightClick(e);
|
|
|
|
|
|
|
|
|
|
if (TreeNodeClicked != null)
|
|
|
|
|
TreeNodeClicked();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exn)
|
|
|
|
|
{
|
|
|
|
|
log.Error(exn, exn);
|
|
|
|
|
// Swallow this exception -- there's no point throwing it on.
|
|
|
|
|
#if DEBUG
|
|
|
|
|
throw;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void treeView_NodeMouseDoubleClick(object sender, VirtualTreeNodeMouseClickEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Button != MouseButtons.Left)
|
|
|
|
|
return;
|
|
|
|
|
if (e.Node == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
IXenConnection conn = e.Node.Tag as IXenConnection;
|
|
|
|
|
if (conn == null)
|
|
|
|
|
{
|
|
|
|
|
var obj = e.Node.Tag as IXenObject;
|
|
|
|
|
if (obj != null)
|
|
|
|
|
conn = obj.Connection;
|
|
|
|
|
}
|
|
|
|
|
if (conn != null && !conn.IsConnected)
|
|
|
|
|
{
|
2014-01-22 13:39:32 +01:00
|
|
|
|
new ReconnectHostCommand(Program.MainWindow, conn).Execute();
|
2013-08-24 18:00:32 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VM vm = e.Node.Tag as VM;
|
|
|
|
|
if (vm != null)
|
|
|
|
|
{
|
|
|
|
|
Command cmd = null;
|
|
|
|
|
|
|
|
|
|
if (vm.is_a_template)
|
|
|
|
|
{
|
2014-01-22 13:39:32 +01:00
|
|
|
|
cmd = new NewVMCommand(Program.MainWindow, Program.MainWindow.SelectionManager.Selection);
|
2013-08-24 18:00:32 +02:00
|
|
|
|
}
|
|
|
|
|
else if (vm.power_state == vm_power_state.Halted && vm.allowed_operations.Contains(vm_operations.start))
|
|
|
|
|
{
|
2014-01-22 13:39:32 +01:00
|
|
|
|
cmd = new StartVMCommand(Program.MainWindow, Program.MainWindow.SelectionManager.Selection);
|
2013-08-24 18:00:32 +02:00
|
|
|
|
}
|
|
|
|
|
else if (vm.power_state == vm_power_state.Suspended && vm.allowed_operations.Contains(vm_operations.resume))
|
|
|
|
|
{
|
2014-01-22 13:39:32 +01:00
|
|
|
|
cmd = new ResumeVMCommand(Program.MainWindow, Program.MainWindow.SelectionManager.Selection);
|
2013-08-24 18:00:32 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cmd != null && cmd.CanExecute())
|
|
|
|
|
{
|
|
|
|
|
treeView.SelectedNode = e.Node;
|
|
|
|
|
cmd.Execute();
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Host host = e.Node.Tag as Host;
|
|
|
|
|
if (host != null)
|
|
|
|
|
{
|
2014-01-22 13:39:32 +01:00
|
|
|
|
Command cmd = new PowerOnHostCommand(Program.MainWindow, host);
|
2013-08-24 18:00:32 +02:00
|
|
|
|
if (cmd.CanExecute())
|
|
|
|
|
{
|
|
|
|
|
treeView.SelectedNode = e.Node;
|
|
|
|
|
cmd.Execute();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void treeView_SelectionsChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// this is fired when the selection of the main treeview changes.
|
2013-10-08 11:17:57 +02:00
|
|
|
|
VirtualTreeNode rootNode = treeView.Nodes.Count > 0 ? treeView.Nodes[0] : null;
|
2013-08-24 18:00:32 +02:00
|
|
|
|
List<SelectedItem> items = new List<SelectedItem>();
|
|
|
|
|
foreach (VirtualTreeNode node in treeView.SelectedNodes)
|
|
|
|
|
{
|
|
|
|
|
GroupingTag groupingTag = node.Tag as GroupingTag;
|
|
|
|
|
IXenObject xenObject = node.Tag as IXenObject;
|
|
|
|
|
|
|
|
|
|
if (xenObject != null)
|
|
|
|
|
{
|
2013-10-08 11:17:57 +02:00
|
|
|
|
items.Add(new SelectedItem(xenObject, xenObject.Connection,
|
|
|
|
|
HostAncestorOfNode(node), PoolAncestorOfNode(node),
|
|
|
|
|
GroupAncestorOfNode(node), rootNode));
|
2013-08-24 18:00:32 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-10-08 11:17:57 +02:00
|
|
|
|
items.Add(new SelectedItem(groupingTag, rootNode));
|
2013-08-24 18:00:32 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-26 12:42:32 +02:00
|
|
|
|
selectionManager.SetSelection(items);
|
|
|
|
|
|
2013-08-24 18:00:32 +02:00
|
|
|
|
if (TreeViewSelectionChanged != null)
|
2013-08-26 12:42:32 +02:00
|
|
|
|
TreeViewSelectionChanged();
|
2013-08-24 18:00:32 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2013-08-23 13:23:35 +02:00
|
|
|
|
}
|
|
|
|
|
}
|