예제 #1
0
        public void SelectHosts(List <IXenObject> selectedObjects)
        {
            if (selectedObjects.Count == 0 || HostListTreeView.Items.Count == 0)
            {
                return;
            }

            HostListTreeView.BeginUpdate();
            HostListTreeView.ClearSelected();

            for (int index = 0; index < HostListTreeView.Items.Count; index++)
            {
                var node = HostListTreeView.Items[index] as HostCustomTreeNode;
                if (node == null)
                {
                    continue;
                }

                IXenConnection con = node.Tag as IXenConnection;
                if (con != null)
                {
                    var pool = Helpers.GetPool(con);
                    if (pool == null)
                    {
                        Host master = Helpers.GetMaster(con);
                        if (master != null && selectedObjects.Contains(master))
                        {
                            node.State = CheckState.Checked;
                        }
                    }
                    else
                    {
                        if (selectedObjects.Contains(pool))
                        {
                            foreach (var subnode in node.ChildNodes)
                            {
                                subnode.State = CheckState.Checked;
                            }
                        }
                    }
                    continue;
                }

                var host = node.Tag as Host;
                if (host != null && selectedObjects.Contains(host))
                {
                    node.State = CheckState.Checked;
                }
            }

            //focus on first checked item so the user can find it in a long list
            foreach (var node in HostListTreeView.CheckedItems())
            {
                HostListTreeView.SelectedItems.Add(node);
                break;
            }

            HostListTreeView.EndUpdate();
        }
예제 #2
0
        private void buildList()
        {
            Program.AssertOnEventThread();

            if (inupdate)
            {
                return;
            }

            inupdate = true;
            HostListTreeView.BeginUpdate();

            try
            {
                // Save old checked states to preserve across update
                var oldCheckStates = new Dictionary <string, CheckState>();
                foreach (HostCustomTreeNode node in HostListTreeView.Items)
                {
                    if (node.HostOrPoolUuid != null)
                    {
                        oldCheckStates.Add(node.HostOrPoolUuid, node.State);
                    }
                }

                HostListTreeView.ClearAllNodes();
                DeregisterEvents();

                foreach (IXenConnection connection in ConnectionsManager.XenConnectionsCopy)
                {
                    connection.ConnectionStateChanged += connection_ConnectionStateChanged;
                    connection.Cache.RegisterCollectionChanged <Host>(Host_CollectionChangedWithInvoke);
                    connection.CachePopulated += connection_CachePopulated;

                    if (!connection.IsConnected)
                    {
                        continue;  // don't show disconnected connections CA-60514
                    }
                    HostCustomTreeNode node = new HostCustomTreeNode(true)
                    {
                        Text        = Helpers.GetName(connection),
                        Tag         = connection,
                        Enabled     = true,
                        Description = "",
                        State       = CheckState.Unchecked,
                        Image       = Images.GetImage16For(connection)
                    };

                    HostListTreeView.AddNode(node);

                    // Save uuid of pool to this node
                    Pool pool = Helpers.GetPoolOfOne(connection);
                    if (pool == null)
                    {
                        continue;
                    }

                    pool.PropertyChanged += pool_PropertyChanged;

                    node.HostOrPoolUuid = pool.uuid;
                    node.State          = (oldCheckStates.ContainsKey(node.HostOrPoolUuid) && node.Enabled) ?
                                          oldCheckStates[node.HostOrPoolUuid] :
                                          CheckState.Unchecked;

                    if (Helpers.GetPool(connection) != null)
                    {
                        node.Image = Images.GetImage16For(pool);

                        foreach (Host host in connection.Cache.Hosts)
                        {
                            bool isHostLive = host.IsLive();
                            HostCustomTreeNode childnode = new HostCustomTreeNode(true)
                            {
                                Text           = Helpers.GetName(host),
                                Tag            = host,
                                HostOrPoolUuid = host.uuid,
                                Enabled        = isHostLive,
                                Description    = isHostLive ? "" : Messages.HOST_NOT_LIVE,
                                Image          = Images.GetImage16For(host)
                            };

                            childnode.State = (oldCheckStates.ContainsKey(childnode.HostOrPoolUuid) && childnode.Enabled) ?
                                              oldCheckStates[childnode.HostOrPoolUuid] :
                                              CheckState.Unchecked;

                            HostListTreeView.AddChildNode(node, childnode);

                            RegisterHostEvents(host);
                        }
                    }
                    else
                    {
                        Host master = Helpers.GetMaster(connection);
                        if (master != null)
                        {
                            bool isMasterLive = master.IsLive();
                            node.Enabled     = isMasterLive;
                            node.Description = isMasterLive ? "" : Messages.HOST_NOT_LIVE;
                            node.Image       = Images.GetImage16For(master);

                            RegisterHostEvents(master);
                        }
                    }
                }
            }
            finally
            {
                inupdate = false;
                HostListTreeView.EndUpdate();
                EnableDisableButtons();
            }
        }