public void ContextMenu_GroupingTag()
        {
            PutInOrgView(ORGANIZATION_VIEW);
            try
            {
                foreach (VirtualTreeNode node in GetAllTreeNodes())
                {
                    GroupingTag gt = node.Tag as GroupingTag;
                    if (gt != null)
                    {
                        var expectedItems = new List <ExpectedMenuItem>();

                        if (gt.Grouping is PropertyGrouping <string> )
                        {
                            expectedItems.Add(new ExpectedTextMenuItem("&Delete Tag...", true));
                            expectedItems.Add(new ExpectedTextMenuItem("&Rename Tag...", true));
                        }

                        AddExpectedExpandAndCollapseItems(node, expectedItems);

                        VerifyContextMenu(gt, expectedItems.ToArray());
                    }
                }
            }
            finally
            {
                PutInOrgView(INFRASTRUCTURE_VIEW);
            }
        }
Example #2
0
        public void ContextMenu_GroupingTag()
        {
            PutInNavigationMode(NavigationPane.NavigationMode.Tags);
            try
            {
                var nodes = GetAllTreeNodes().Where(n => n.Parent != null);

                foreach (VirtualTreeNode node in nodes)
                {
                    GroupingTag gt = node.Tag as GroupingTag;
                    if (gt != null)
                    {
                        var expectedItems = new List <ExpectedMenuItem>();

                        if (gt.Grouping is PropertyGrouping <string> )
                        {
                            expectedItems.Add(new ExpectedTextMenuItem("&Delete Tag...", true));
                            expectedItems.Add(new ExpectedTextMenuItem("&Rename Tag...", true));
                        }

                        AddExpectedExpandAndCollapseItems(node, expectedItems);

                        VerifyContextMenu(gt, expectedItems.ToArray());
                    }
                }
            }
            finally
            {
                PutInNavigationMode(NavigationPane.NavigationMode.Infrastructure);
            }
        }
Example #3
0
        private void treeView_SelectionsChanged(object sender, EventArgs e)
        {
            // this is fired when the selection of the main treeview changes.
            VirtualTreeNode     rootNode = treeView.Nodes.Count > 0 ? treeView.Nodes[0] : null;
            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)
                {
                    items.Add(new SelectedItem(xenObject, xenObject.Connection,
                                               HostAncestorOfNode(node), PoolAncestorOfNode(node),
                                               GroupAncestorOfNode(node), rootNode));
                }
                else
                {
                    items.Add(new SelectedItem(groupingTag, rootNode));
                }
            }

            selectionManager.SetSelection(items);

            if (TreeViewSelectionChanged != null)
            {
                TreeViewSelectionChanged();
            }
        }
Example #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SelectedItem"/> class.
 /// </summary>
 /// <param name="xenObject">The xen object that is selected.</param>
 /// <param name="connection">The connection of the xen object.</param>
 /// <param name="hostAncestor">The host ancestor of the xen object in the tree.</param>
 /// <param name="poolAncestor">The pool ancestor of the xen object in the tree.</param>
 /// <param name="groupAncestor">In Objects view this is the type under which
 /// the object is grouped.</param>
 /// <param name="rootNode"></param>
 public SelectedItem(IXenObject xenObject, IXenConnection connection, Host hostAncestor,
                     Pool poolAncestor, GroupingTag groupAncestor, VirtualTreeNode rootNode)
     : this(xenObject, connection, hostAncestor, poolAncestor)
 {
     _groupAncestor = groupAncestor;
     _rootNode      = rootNode;
 }
Example #5
0
        private IEnumerable <SelectedItemCollection> GetSelections()
        {
            List <object> output = new List <object>();

            for (int i = 0; i < 2; i++)
            {
                foreach (VirtualTreeNode n in GetAllTreeNodes())
                {
                    if (!output.Contains(n.Tag))
                    {
                        output.Add(n.Tag);

                        GroupingTag gt = n.Tag as GroupingTag;
                        if (gt != null)
                        {
                            yield return(new SelectedItemCollection(new[] { new SelectedItem(gt) }));
                        }
                        else
                        {
                            yield return(new SelectedItemCollection(new[] { new SelectedItem(n.Tag as IXenObject) }));
                        }
                    }
                }
                MW(() => PutInOrgView(NativeView));
            }
        }
Example #6
0
        protected override bool CanExecuteCore()
        {
            List <IXenObject> draggedObjects = GetDraggedItemsAsXenObjects <IXenObject>();
            GroupingTag       gt             = GetTargetNodeAncestorAsXenObjectOrGroupingTag <GroupingTag>();

            if (Program.MainWindow.TreeSearchBoxMode == TreeSearchBox.Mode.Organization &&
                gt != null && draggedObjects.Count > 0)
            {
                foreach (IXenObject xenObject in draggedObjects)
                {
                    // can't tag folders.
                    if (xenObject is Folder)
                    {
                        return(false);
                    }
                    // can't tag StorageLink objects
                    if (xenObject is IStorageLinkObject)
                    {
                        return(false);
                    }
                }

                return(gt.Grouping.GroupingName == Messages.TAGS && !string.IsNullOrEmpty(gt.Group as string));
            }
            return(false);
        }
Example #7
0
 private static bool IsTagInOrgMode(VirtualTreeNode node)
 {
     if (node != null)
     {
         GroupingTag gt = node.Tag as GroupingTag;
         return(gt != null && gt.Grouping.GroupingName == Messages.TAGS);
     }
     return(false);
 }
        public void Test()
        {
            foreach (SelectedItemCollection selection in RunTest())
            {
                Folder folder = (Folder)selection[0].XenObject;

                // choose new folder name
                string newFolderName = Guid.NewGuid().ToString();

                if (folder == null)
                {
                    GroupingTag tag = selection[0].GroupingTag;

                    if (tag != null && tag.Grouping is OrganizationViewFolders)
                    {
                        HandleModalDialog("New Folder", Command.Execute, delegate(NameAndConnectionPromptWrapper p)
                        {
                            p.NameTextBox.Text = newFolderName;
                            p.OKButton.PerformClick();
                        });
                    }
                }
                else
                {
                    if (folder.IsRootFolder)
                    {
                        HandleModalDialog("New Folder", Command.Execute, delegate(NameAndConnectionPromptWrapper p)
                        {
                            p.NameTextBox.Text = newFolderName;
                            p.OKButton.PerformClick();
                        });
                    }
                    else
                    {
                        HandleModalDialog("New Folder", Command.Execute, delegate(InputPromptDialogWrapper p)
                        {
                            p.NameTextBox.Text = newFolderName;
                            p.OKButton.PerformClick();
                        });
                    }
                }

                // now check to see if new folder exists and is selected, and is visible.
                MWWaitFor(delegate
                {
                    VirtualTreeNode n = MainWindowWrapper.TreeView.SelectedNode;
                    Folder f          = n == null ? null : n.Tag as Folder;
                    return(f != null &&
                           n.Text == newFolderName &&
                           f.Name == newFolderName &&
                           n.AllParentsAreExpanded);
                }, "Couldn't find new folder.");
            }
        }
        private IEnumerable <SelectedItemCollection> GetSelections()
        {
            // just delete one tag for this test as it's quite slow.

            PutInOrgView(ORGANIZATION_VIEW);

            VirtualTreeNode node = GetAllTreeNodes().Find(delegate(VirtualTreeNode n)
            {
                GroupingTag g = n.Tag as GroupingTag;
                return(g != null && n.Parent.Tag is GroupingTag && g.Grouping.GroupingName == "Tags");
            });

            GroupingTag gt = (GroupingTag)node.Tag;


            yield return(new SelectedItemCollection(new[] { new SelectedItem(gt) }));
        }
Example #10
0
        private IEnumerable <SelectedItemCollection> GetSelections()
        {
            // just delete one tag for this test as it's quite slow.

            PutInNavigationMode(NativeMode);

            VirtualTreeNode node = GetAllTreeNodes().Find(n =>
            {
                GroupingTag g = n.Tag as GroupingTag;
                return(g != null && n.Parent != null && g.Grouping.GroupingName == "Tags");
            });

            GroupingTag gt = (GroupingTag)node.Tag;

            var rootNode = GetAllTreeNodes().Find(n => n.Parent == null);

            yield return(new SelectedItemCollection(new SelectedItem(gt, rootNode)));
        }
Example #11
0
        protected override bool CanExecuteCore()
        {
            List <IXenObject> draggedObjects = GetDraggedItemsAsXenObjects <IXenObject>();
            GroupingTag       gt             = GetTargetNodeAncestorAsXenObjectOrGroupingTag <GroupingTag>();

            if (gt != null && draggedObjects.Count > 0)
            {
                foreach (IXenObject xenObject in draggedObjects)
                {
                    // can't tag folders.
                    if (xenObject is Folder)
                    {
                        return(false);
                    }
                }

                return(gt.Grouping.GroupingName == Messages.TAGS && !string.IsNullOrEmpty(gt.Group as string));
            }
            return(false);
        }
Example #12
0
        private IEnumerable <SelectedItemCollection> GetSelections()
        {
            List <object> output   = new List <object>();
            var           rootNode = GetAllTreeNodes().Find(n => n.Parent == null);

            foreach (VirtualTreeNode n in GetAllTreeNodes())
            {
                if (!output.Contains(n.Tag))
                {
                    output.Add(n.Tag);

                    GroupingTag gt = n.Tag as GroupingTag;
                    if (gt != null)
                    {
                        yield return(new SelectedItemCollection(new[] { new SelectedItem(gt, rootNode) }));
                    }
                    else
                    {
                        yield return(new SelectedItemCollection(new[] { new SelectedItem(n.Tag as IXenObject) }));
                    }
                }
            }
        }
        internal override Command CreateCommand()
        {
            PutInNavigationMode(NativeMode);

            _node = GetAllTreeNodes().Find(delegate(VirtualTreeNode n)
            {
                GroupingTag groupingTag = n.Parent == null ? null : n.Parent.Tag as GroupingTag;

                if (n.Tag is IXenObject && groupingTag != null && groupingTag.Grouping.GroupingName == "Tags")
                {
                    _tag = (string)groupingTag.Group;
                    return(true);
                }
                return(false);
            });


            MW(() => _node.EnsureVisible());

            return(new UntagCommand(Program.MainWindow, new List <VirtualTreeNode> {
                _node
            }));
        }
Example #14
0
 private static bool IsValid(GroupingTag groupingTag)
 {
     return(groupingTag.Grouping.GroupingName == Messages.TAGS);
 }
Example #15
0
 private static bool IsValid(GroupingTag groupingTag)
 {
     return groupingTag.Grouping.GroupingName == Messages.TAGS;
 }
Example #16
0
        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)
            {
                Program.Invoke(this, delegate
                {
                    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)
                {
                    RenameFolderCommand cmd = new RenameFolderCommand(Program.MainWindow, folder, e.Label);
                    command = cmd;
                    cmd.Completed += completed;
                    newTag = new Folder(null, e.Label);
                }
                else if (groupingTag != null)
                {
                    RenameTagCommand cmd = new RenameTagCommand(Program.MainWindow, groupingTag.Group.ToString(), e.Label);
                    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;
            }
        }
Example #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SelectedItem"/> class.
 /// </summary>
 /// <param name="xenObject">The xen object that is selected.</param>
 /// <param name="connection">The connection of the xen object.</param>
 /// <param name="hostAncestor">The host ancestor of the xen object in the tree.</param>
 /// <param name="poolAncestor">The pool ancestor of the xen object in the tree.</param>
 /// <param name="groupAncestor">In Objects view this is the type under which
 /// the object is grouped.</param>
 public SelectedItem(IXenObject xenObject, IXenConnection connection, Host hostAncestor,
     Pool poolAncestor, GroupingTag groupAncestor, VirtualTreeNode rootNode)
     : this(xenObject, connection, hostAncestor, poolAncestor)
 {
     _groupAncestor = groupAncestor;
     _rootNode = rootNode;
 }
Example #18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SelectedItem"/> class.
 /// </summary>
 /// <param name="groupingTag">The grouping tag that is selected.</param>
 public SelectedItem(GroupingTag groupingTag, VirtualTreeNode rootNode)
 {
     _groupingTag = groupingTag;
     _rootNode = rootNode;
 }
Example #19
0
 private bool TagExists(GroupingTag tag)
 {
     return(GetAllTreeNodes().ConvertAll(n => n.Tag as GroupingTag).Contains(tag));
 }
Example #20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SelectedItem"/> class.
 /// </summary>
 /// <param name="groupingTag">The grouping tag that is selected.</param>
 public SelectedItem(GroupingTag groupingTag)
 {
     _groupingTag = groupingTag;
 }
Example #21
0
        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)
            {
                Program.Invoke(this, delegate
                {
                    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)
                {
                    RenameFolderCommand cmd = new RenameFolderCommand(Program.MainWindow, folder, e.Label);
                    command        = cmd;
                    cmd.Completed += completed;
                    newTag         = new Folder(null, e.Label);
                }
                else if (groupingTag != null)
                {
                    RenameTagCommand cmd = new RenameTagCommand(Program.MainWindow, groupingTag.Group.ToString(), e.Label);
                    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;
            }
        }
Example #22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SelectedItem"/> class.
 /// </summary>
 /// <param name="groupingTag">The grouping tag that is selected.</param>
 public SelectedItem(GroupingTag groupingTag)
 {
     _groupingTag = groupingTag;
 }
Example #23
0
 private static bool CanExecute(GroupingTag groupingTag)
 {
     return groupingTag.Grouping.GroupingName == Messages.TAGS;
 }
Example #24
0
 private static bool CanExecute(GroupingTag groupingTag)
 {
     return(groupingTag.Grouping.GroupingName == Messages.TAGS);
 }
Example #25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SelectedItem"/> class.
 /// </summary>
 /// <param name="groupingTag">The grouping tag that is selected.</param>
 /// <param name="rootNode"></param>
 public SelectedItem(GroupingTag groupingTag, VirtualTreeNode rootNode)
 {
     _groupingTag = groupingTag;
     _rootNode    = rootNode;
 }