CollapseAll() public method

public CollapseAll ( ) : void
return void
Exemplo n.º 1
0
 private void toolStripButton1_Click(object sender, EventArgs e)
 {
     if (toolStripButton1.Text == "Expand All")
     {
         trvBlockSet.ExpandAll();
         toolStripButton1.Text  = "Collapse All";
         toolStripButton1.Image = Properties.Resources.gem_remove;
     }
     else
     {
         trvBlockSet.CollapseAll();
         toolStripButton1.Text  = "Expand All";
         toolStripButton1.Image = Properties.Resources.add_small;
     }
 }
Exemplo n.º 2
0
        private void LoadMasterCategories(HashSet <IPartOfSpeech> posSet)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(Path.Combine(FwDirectoryFinder.TemplateDirectory, "GOLDEtic.xml"));
            XmlElement root = doc.DocumentElement;

            AddNodes(posSet, root.SelectNodes("/eticPOSList/item"), m_tvMasterList.Nodes, m_cache);

            // The expand/collapse cycle is to ensure that all the folder icons get set
            m_tvMasterList.ExpandAll();
            m_tvMasterList.CollapseAll();

            // Select the first node in the list
            TreeNode node = m_tvMasterList.Nodes[0];

            m_tvMasterList.SelectedNode = node;
            // Then try to find a root-level node that is not yet installed and select it if we
            // can, without moving the scrollbar (see LT-7441).
            do
            {
                if (!(node.Tag is MasterCategory))
                {
                    continue;
                }
                if (!(node.Tag as MasterCategory).InDatabase)
                {
                    break;
                }
                // DownArrow moves the selection without affecting the scroll position (unless
                // the selection was at the bottom).
                Win32.SendMessage(m_tvMasterList.Handle, Win32.WinMsgs.WM_KEYDOWN,
                                  (int)Keys.Down, 0);
            } while ((node = node.NextNode) != null);
        }
Exemplo n.º 3
0
        private void checkCollapse_CheckedChanged(object sender, System.EventArgs e)
        {
            TreeNode topNode      = treeNotes.TopNode;
            TreeNode selectedNode = treeNotes.SelectedNode;

            treeNotes.BeginUpdate();
            if (checkCollapse.Checked)
            {
                while (topNode.Parent != null)               //store the topNode's root to set the topNode after collapsing all nodes
                {
                    topNode = topNode.Parent;
                }
                while (selectedNode != null && selectedNode.Parent != null)             //store the selectedNode's root to select after collapsing
                {
                    selectedNode = selectedNode.Parent;
                }
                treeNotes.CollapseAll();
            }
            else
            {
                treeNotes.ExpandAll();
            }
            treeNotes.EndUpdate();
            if (selectedNode == null)
            {
                treeNotes.TopNode = topNode; //set TopNode if there is no SelectedNode
            }
            else                             //reselect the node and ensure that it is visible after expanding or collapsing
            {
                treeNotes.SelectedNode = selectedNode;
                treeNotes.SelectedNode.EnsureVisible();
                treeNotes.Focus();
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 设置TreeView选中节点
        /// </summary>
        /// <param name="treeView"></param>
        /// <param name="selectStr">选中节点文本</param>
        public static void SelectNode2Level(TreeView treeView, string selectStr)
        {
            treeView.CollapseAll();
            treeView.Visible = true;
            treeView.Focus();
            for (int i = 0; i < treeView.Nodes.Count; i++)
            {
                if (treeView.Nodes[i].Text == selectStr)
                {
                    treeView.SelectedNode = treeView.Nodes[i];//选中
                    treeView.SelectedNode.Checked = true;
                    return;
                }

                for (int j = 0; j < treeView.Nodes[i].Nodes.Count; j++)
                {
                    if (treeView.Nodes[i].Nodes[j].Text == selectStr)
                    {
                        treeView.SelectedNode = treeView.Nodes[i].Nodes[j];//选中
                        treeView.SelectedNode.Checked = true;
                        treeView.Nodes[i].Expand();//展开父级
                        return;
                    }
                }
            }
        }
Exemplo n.º 5
0
 public void Collapse()
 {
     _tree.CollapseAll();
 }
Exemplo n.º 6
0
		public void CollapseAll_NoNodes ()
		{
			TreeView tv = new TreeView ();
			tv.CollapseAll ();
		}
Exemplo n.º 7
0
        /// <summary>
        /// Creates the tree based on element sets and quantities in exchange items
        /// passed with <see cref="PopulateExchangeItemTree">PopulateExchangeItemTree</see> method.
        /// </summary>
        public void CreateTree()
        {
            treeView1.BeginUpdate();
            treeView1.Nodes.Clear();


            string lastQuantityID = null;

            // fill tree with exchange items (if there are any because DrawTree could be called
            // before _exchangeItems was assigned )
            if (_exchangeItems != null)
            {
                foreach (IExchangeItem exchangeItem in _exchangeItems)
                {
                    TreeNode elementSetNode = null;                     // newly added node (if any)

                    // apply filters (if any)
                    if (_filterDimension != null &&
                        !Utils.CompareDimensions(_filterDimension, exchangeItem.Quantity.Dimension))
                    {
                        continue;
                    }

                    if (_filterElementSet != null &&
                        _filterElementSet.ElementType != ElementType.IDBased &&
                        (exchangeItem.ElementSet.ElementType != ElementType.IDBased ||
                         exchangeItem.ElementSet.ElementCount != _filterElementSet.ElementCount))
                    {
                        continue;
                    }


                    TreeNode quantityNode;

                    if (lastQuantityID != exchangeItem.Quantity.ID)
                    {
                        // adding new quantity node
                        quantityNode     = treeView1.Nodes.Add(exchangeItem.Quantity.ID);
                        quantityNode.Tag = exchangeItem.Quantity;
                        if (exchangeItem.Quantity.ValueType == global::OpenMI.Standard.ValueType.Scalar)
                        {
                            quantityNode.ImageIndex = quantityNode.SelectedImageIndex = 0;
                        }
                        else
                        {
                            quantityNode.ImageIndex = quantityNode.SelectedImageIndex = 1;
                        }

                        lastQuantityID = exchangeItem.Quantity.ID;
                    }
                    else
                    {
                        // last node corresponds to quantity with same ID
                        quantityNode = treeView1.Nodes[treeView1.Nodes.Count - 1];
                    }

                    // Add ElementSet node
                    elementSetNode = quantityNode.Nodes.Add(exchangeItem.ElementSet.ID);

                    Debug.Assert(0 <= (int)exchangeItem.ElementSet.ElementType && (int)exchangeItem.ElementSet.ElementType <= 9);
                    elementSetNode.ImageIndex = elementSetNode.SelectedImageIndex = (int)exchangeItem.ElementSet.ElementType + 2;

                    elementSetNode.Tag = exchangeItem.ElementSet;


                    // add DataOperation subnodes only if newly added node is IOutputExchangeItem
                    if (exchangeItem is IOutputExchangeItem)
                    {
                        IOutputExchangeItem item = (IOutputExchangeItem)exchangeItem;
                        for (int j = 0; j < item.DataOperationCount; j++)
                        {
                            TreeNode dataOperationNode = elementSetNode.Nodes.Add(item.GetDataOperation(j).ID);
                            dataOperationNode.ImageIndex = dataOperationNode.SelectedImageIndex = 12;
                            dataOperationNode.Tag        = item.GetDataOperation(j);
                        }
                    }
                }
            }

            treeView1.CollapseAll();
            treeView1.EndUpdate();

            _checkedQuantity       = null;
            _checkedElementSet     = null;
            _checkedDataOperations = new ArrayList();
        }
		private void favList_ItemDrag(object sender, System.Windows.Forms.ItemDragEventArgs e)
		{
			focusedTreeView = (e.Item as TreeNode).TreeView;
			focusedTreeView.CollapseAll();
			DoDragDrop(e.Item, DragDropEffects.Move);
		}
Exemplo n.º 9
0
 public static void collapseAll(TreeView oTreeView)
 {
     oTreeView.CollapseAll();
 }
Exemplo n.º 10
0
 internal static void ClearTreeview(TreeView tv)
 {
     try
       {
     tv.SuspendLayout();
     for (var i = 0; i < tv.Nodes.Count; i++)
     {
       var subs = tv.Nodes[i].Nodes;
       for (var j = 0; j < subs.Count; j++)
       {
     subs[j].Text = string.Empty;
       }
     }
     tv.CollapseAll();
       }
       catch (Exception e)
       {
     LogHelper.Dump(e);
       }
       finally
       {
     tv.ResumeLayout();
       }
 }
Exemplo n.º 11
0
		/// <summary>
		/// Called by the framework when the designer is being initialized with the designed control
		/// </summary>
		/// <param name="component"></param>
		public override void Initialize(IComponent component)
		{
			base.Initialize(component);

			if (Control is TreeView)
			{
				try
				{
					m_oSelectionService = (ISelectionService) GetService(typeof (ISelectionService));
				}
				catch
				{
				}
				try
				{
					m_oSelectionService.SelectionChanged += new EventHandler(this.OnSelectionServiceChanged);
				}
				catch
				{
				}
				try
				{
					m_oDesignerHost = (IDesignerHost) GetService(typeof (IDesignerHost));
				}
				catch
				{
				}
				try
				{
					m_oMenuService = (IMenuCommandService) GetService(typeof (IMenuCommandService));
				}
				catch
				{
				}
				try
				{
					m_oDesignerSerializationService = (IDesignerSerializationService) GetService(typeof (IDesignerSerializationService));
				}
				catch
				{
				}
				try
				{
					m_oToolboxService = (IToolboxService) GetService(typeof (IToolboxService));
				}
				catch
				{
				}
				try
				{
					m_oUIService = (IUIService) GetService(typeof (IUIService));
				}
				catch
				{
				}
				try
				{
					m_oComponentChangeService = (IComponentChangeService) GetService(typeof (IComponentChangeService));
				}
				catch
				{
				}

				m_oTreeView = (TreeView) Control;
				m_oTreeView.m_bFocus = true;
				m_oTreeView.ClearAllSelection();
				m_oTreeView.DesignerHost = m_oDesignerHost;
				m_oTreeView.IsDesignMode = true;

				if (m_bFirstTime == true)
				{
					OnComponentCreated(m_oTreeView);
					m_bFirstTime = false;
				}

				try
				{
					m_oComponentAddedHandler = new ComponentEventHandler(this.OnComponentAdded);
				}
				catch
				{
				}
				try
				{
					m_oComponentRemovingHandler = new ComponentEventHandler(this.OnComponentRemoving);
				}
				catch
				{
				}
				try
				{
					m_oComponentChangeService.ComponentAdded += m_oComponentAddedHandler;
				}
				catch
				{
				}
				try
				{
					m_oComponentChangeService.ComponentRemoving += m_oComponentRemovingHandler;
				}
				catch
				{
				}
				try
				{
					m_oNodeParentChanged = new EventHandler(this.OnNodeParentChanged);
				}
				catch
				{
				}

				try
				{
					m_oOldCmdCopy = m_oMenuService.FindCommand(StandardCommands.Copy);
				}
				catch
				{
				}
				try
				{
					m_oOldCmdPaste = m_oMenuService.FindCommand(StandardCommands.Paste);
				}
				catch
				{
				}
				try
				{
					m_oOldCmdCut = m_oMenuService.FindCommand(StandardCommands.Cut);
				}
				catch
				{
				}
				try
				{
					m_oOldBringFront = m_oMenuService.FindCommand(StandardCommands.BringToFront);
				}
				catch
				{
				}
				try
				{
					m_oOldSendBack = m_oMenuService.FindCommand(StandardCommands.SendToBack);
				}
				catch
				{
				}
				try
				{
					m_oOldAlignGrid = m_oMenuService.FindCommand(StandardCommands.AlignToGrid);
				}
				catch
				{
				}
				try
				{
					m_oOldLockControls = m_oMenuService.FindCommand(StandardCommands.LockControls);
				}
				catch
				{
				}
				try
				{
					m_oOldDelete = m_oMenuService.FindCommand(StandardCommands.Delete);
				}
				catch
				{
				}

				try
				{
					m_oNewCmdCopy = new MenuCommand(new EventHandler(this.OnMenuCopy), StandardCommands.Copy);
				}
				catch
				{
				}
				try
				{
					m_oNewCmdPaste = new MenuCommand(new EventHandler(this.OnMenuPaste), StandardCommands.Paste);
				}
				catch
				{
				}

				if (TreeViewDesigner.MenuAdded == false)
				{
					try
					{
						m_oMenuService.RemoveCommand(m_oOldCmdCopy);
					}
					catch
					{
					}
					try
					{
						m_oMenuService.RemoveCommand(m_oOldCmdPaste);
					}
					catch
					{
					}
					try
					{
						m_oMenuService.AddCommand(m_oNewCmdCopy);
					}
					catch
					{
					}
					try
					{
						m_oMenuService.AddCommand(m_oNewCmdPaste);
					}
					catch
					{
					}

					TreeViewDesigner.MenuAdded = true;
				}

				m_oTreeView.Invalidate();

				#region action menus

				#region node menu

				m_oActionMenuNode = new ActionMenuNative();
				m_oActionMenuNode.Width = 170;
				m_oActionMenuNode.Title = "Node Action Menu";

				ActionMenuGroup oMenuGroup = m_oActionMenuNode.AddMenuGroup("Editing");
				oMenuGroup.Expanded = true;
				m_oActionMenuNode.AddMenuItem(oMenuGroup, "Add Node");
				m_oActionMenuNode.AddMenuItem(oMenuGroup, "Delete Node");
				m_oActionMenuNode.AddMenuItem(oMenuGroup, "Add Panel");
				m_oActionMenuNode.AddMenuItem(oMenuGroup, "-");
				m_oActionMenuNode.AddMenuItem(oMenuGroup, "Clear Content");
				m_oActionMenuNode.AddMenuItem(oMenuGroup, "Delete TreeView");
				m_oActionMenuNode.AddMenuItem(oMenuGroup, "-");
				m_oActionMenuNode.AddMenuItem(oMenuGroup, "Copy");
				m_oActionMenuNode.AddMenuItem(oMenuGroup, "Paste");
				m_oActionMenuNode.AddMenuItem(oMenuGroup, "-");
				m_oActionMenuNode.AddMenuItem(oMenuGroup, "Properties");
				oMenuGroup = m_oActionMenuNode.AddMenuGroup("Arranging");
				m_oActionMenuNode.AddMenuItem(oMenuGroup, "Expand");
				m_oActionMenuNode.AddMenuItem(oMenuGroup, "Collapse");
				m_oActionMenuNode.AddMenuItem(oMenuGroup, "Move Top");
				m_oActionMenuNode.AddMenuItem(oMenuGroup, "Move Bottom");
				m_oActionMenuNode.AddMenuItem(oMenuGroup, "Move Up");
				m_oActionMenuNode.AddMenuItem(oMenuGroup, "Move Down");
				m_oActionMenuNode.AddMenuItem(oMenuGroup, "Move Left");
				m_oActionMenuNode.AddMenuItem(oMenuGroup, "Move Right");
				oMenuGroup = m_oActionMenuNode.AddMenuGroup("Color Schemes");
				m_oActionMenuNode.AddMenuItem(oMenuGroup, "Default");
				m_oActionMenuNode.AddMenuItem(oMenuGroup, "Forest");
				m_oActionMenuNode.AddMenuItem(oMenuGroup, "Gold");
				m_oActionMenuNode.AddMenuItem(oMenuGroup, "Ocean");
				m_oActionMenuNode.AddMenuItem(oMenuGroup, "Rose");
				m_oActionMenuNode.AddMenuItem(oMenuGroup, "Silver");
				m_oActionMenuNode.AddMenuItem(oMenuGroup, "Sky");
				m_oActionMenuNode.AddMenuItem(oMenuGroup, "Sunset");
				m_oActionMenuNode.AddMenuItem(oMenuGroup, "Wood");

				m_oActionMenuNode.ItemClick += new ActionMenuNative.ItemClickEventHandler(this.OnActionMenuNodeItemClicked);

				#endregion			

				#region TreeView menu

				m_oActionMenuTreeView = new ActionMenuNative();
				m_oActionMenuTreeView.Width = 170;
				m_oActionMenuTreeView.Title = "TreeView Action Menu";

				oMenuGroup = m_oActionMenuTreeView.AddMenuGroup("Editing");
				oMenuGroup.Expanded = true;
				m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "Add Node");
				m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "Color Scheme Picker...");
				m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "-");
				m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "Clear Content");
				m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "Delete TreeView");
				m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "-");
				m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "Copy");
				m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "Paste");
				m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "-");
				m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "Properties");
				oMenuGroup = m_oActionMenuTreeView.AddMenuGroup("Arranging");
				m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "Expand All");
				m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "Collapse All");
				oMenuGroup = m_oActionMenuTreeView.AddMenuGroup("Layout");
				m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "Bring to Front");
				m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "Send to Back");
				m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "Align to Grid");
				m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "Lock Controls");

				m_oActionMenuTreeView.ItemClick += new ActionMenuNative.ItemClickEventHandler(this.OnActionMenuTreeViewItemClicked);

				#endregion

				#endregion

				// enable the drag drop operations
				m_oTreeView.AllowDrop = true;
				this.EnableDragDrop(true);

				m_oTreeView.CollapseAll();
				m_oSelector.SelectionService = m_oSelectionService;
				m_oSelector.TreeView = m_oTreeView;
			}
		}
Exemplo n.º 12
0
 private void cmdCollapseAll_Click(object sender, System.EventArgs e)
 {
     tvSimple.CollapseAll();
 }
Exemplo n.º 13
0
 private void CollapseAllBtn_Click(object sender, System.EventArgs e)
 {
     tv.CollapseAll();
 }
Exemplo n.º 14
0
 /// <summary>
 /// Adds a TreeView object to the list of controls.
 /// </summary>
 /// <param name="tv">The TreeView object to be added.</param>
 public void AddTreeToControls(TreeView tv)
 {
     RemoveTreeFromControls(tv);
     tv.Dock = DockStyle.Fill;
     tv.Location = new Point(0, 45);
     tv.Size = new Size(352, 294);
     tv.ImageList = treeViewImages;
     tv.CollapseAll();
     Controls.Add(tv);
     Controls.SetChildIndex(tv, 0);
 }
Exemplo n.º 15
0
		public void ExpandCollapseStateTest ()
		{
			TreeView treeView = new TreeView ();

			TreeNode node1 = new TreeNode ("node1");
			TreeNode node2 = new TreeNode ("node2");
			
			TreeNode node1sub1 = new TreeNode ("node1 - sub1");
			TreeNode node1sub2 = new TreeNode ("node1 - sub2");
			node1.Nodes.Add (node1sub1);
			node1.Nodes.Add (node1sub2);

			TreeNode node1sub1sub1 = new TreeNode ("node1 - sub1 - sub1");
			node1sub1.Nodes.Add (node1sub1sub1);

			treeView.Nodes.AddRange (new TreeNode [] {
				node1,
				node2});

			treeView.CollapseAll ();
			
			IRawElementProviderFragmentRoot provider = (IRawElementProviderFragmentRoot)
				GetProviderFromControl (treeView);

			IRawElementProviderFragmentRoot node1Provider = (IRawElementProviderFragmentRoot)
				provider.Navigate (NavigateDirection.FirstChild);
			IRawElementProviderFragmentRoot node2Provider = (IRawElementProviderFragmentRoot)
				node1Provider.Navigate (NavigateDirection.NextSibling);
			
			IRawElementProviderFragmentRoot node1sub1Provider = (IRawElementProviderFragmentRoot)
				node1Provider.Navigate (NavigateDirection.FirstChild);
			IRawElementProviderFragmentRoot node1sub2Provider = (IRawElementProviderFragmentRoot)
				node1sub1Provider.Navigate (NavigateDirection.NextSibling);
			
			IRawElementProviderFragmentRoot node1sub1sub1Provider = (IRawElementProviderFragmentRoot)
				node1sub1Provider.Navigate (NavigateDirection.FirstChild);

			VerifyTreeNodePatterns (provider, node1Provider, node1);
			VerifyTreeNodePatterns (provider, node2Provider, node2);
			VerifyTreeNodePatterns (provider, node1sub1Provider, node1sub1);
			VerifyTreeNodePatterns (provider, node1sub2Provider, node1sub2);
			VerifyTreeNodePatterns (provider, node1sub1sub1Provider, node1sub1sub1);

			IExpandCollapseProvider node1ExpandCollapse = (IExpandCollapseProvider)
				node1Provider.GetPatternProvider (ExpandCollapsePatternIdentifiers.Pattern.Id);
			IExpandCollapseProvider node2ExpandCollapse = (IExpandCollapseProvider)
				node2Provider.GetPatternProvider (ExpandCollapsePatternIdentifiers.Pattern.Id);

			IExpandCollapseProvider node1sub1ExpandCollapse = (IExpandCollapseProvider)
				node1sub1Provider.GetPatternProvider (ExpandCollapsePatternIdentifiers.Pattern.Id);
			IExpandCollapseProvider node1sub2ExpandCollapse = (IExpandCollapseProvider)
				node1sub2Provider.GetPatternProvider (ExpandCollapsePatternIdentifiers.Pattern.Id);

			IExpandCollapseProvider node1sub1sub1ExpandCollapse = (IExpandCollapseProvider)
				node1sub1sub1Provider.GetPatternProvider (ExpandCollapsePatternIdentifiers.Pattern.Id);

			Assert.AreEqual (ExpandCollapseState.Collapsed,
			                 node1ExpandCollapse.ExpandCollapseState);
			Assert.AreEqual (ExpandCollapseState.LeafNode,
			                 node2ExpandCollapse.ExpandCollapseState);
			Assert.AreEqual (ExpandCollapseState.Collapsed,
			                 node1sub1ExpandCollapse.ExpandCollapseState);
			Assert.AreEqual (ExpandCollapseState.LeafNode,
			                 node1sub2ExpandCollapse.ExpandCollapseState);
			Assert.AreEqual (ExpandCollapseState.LeafNode,
			                 node1sub1sub1ExpandCollapse.ExpandCollapseState);

			TestProperty (node1Provider,
			              ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty,
			              ExpandCollapseState.Collapsed);
			TestProperty (node2Provider,
			              ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty,
			              ExpandCollapseState.LeafNode);
			TestProperty (node1sub1Provider,
			              ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty,
			              ExpandCollapseState.Collapsed);
			TestProperty (node1sub2Provider,
			              ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty,
			              ExpandCollapseState.LeafNode);
			TestProperty (node1sub1sub1Provider,
			              ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty,
			              ExpandCollapseState.LeafNode);

			bridge.ResetEventLists ();
			
			node1.Expand ();
			
			AutomationPropertyChangedEventTuple propertyEventTuple =
				bridge.GetAutomationPropertyEventFrom (node1Provider,
				                                       ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty.Id);
			Assert.IsNotNull (propertyEventTuple,
			                  "Expected property change event on node 1");
			Assert.AreEqual (ExpandCollapseState.Collapsed,
			                 propertyEventTuple.e.OldValue,
			                 "Old value");
			Assert.AreEqual (ExpandCollapseState.Expanded,
			                 propertyEventTuple.e.NewValue,
			                 "New value");

			Assert.AreEqual (ExpandCollapseState.Expanded,
			                 node1ExpandCollapse.ExpandCollapseState);
			Assert.AreEqual (ExpandCollapseState.LeafNode,
			                 node2ExpandCollapse.ExpandCollapseState);
			Assert.AreEqual (ExpandCollapseState.Collapsed,
			                 node1sub1ExpandCollapse.ExpandCollapseState);
			Assert.AreEqual (ExpandCollapseState.LeafNode,
			                 node1sub2ExpandCollapse.ExpandCollapseState);
			Assert.AreEqual (ExpandCollapseState.LeafNode,
			                 node1sub1sub1ExpandCollapse.ExpandCollapseState);

			TestProperty (node1Provider,
			              ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty,
			              ExpandCollapseState.Expanded);
			TestProperty (node2Provider,
			              ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty,
			              ExpandCollapseState.LeafNode);
			TestProperty (node1sub1Provider,
			              ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty,
			              ExpandCollapseState.Collapsed);
			TestProperty (node1sub2Provider,
			              ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty,
			              ExpandCollapseState.LeafNode);
			TestProperty (node1sub1sub1Provider,
			              ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty,
			              ExpandCollapseState.LeafNode);

			bridge.ResetEventLists ();
			
			node1sub1.Expand ();
			
			propertyEventTuple =
				bridge.GetAutomationPropertyEventFrom (node1sub1Provider,
				                                       ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty.Id);
			Assert.IsNotNull (propertyEventTuple,
			                  "Expected property change event on node 1 sub 1");
			Assert.AreEqual (ExpandCollapseState.Collapsed,
			                 propertyEventTuple.e.OldValue,
			                 "Old value");
			Assert.AreEqual (ExpandCollapseState.Expanded,
			                 propertyEventTuple.e.NewValue,
			                 "New value");

			Assert.AreEqual (ExpandCollapseState.Expanded,
			                 node1ExpandCollapse.ExpandCollapseState);
			Assert.AreEqual (ExpandCollapseState.LeafNode,
			                 node2ExpandCollapse.ExpandCollapseState);
			Assert.AreEqual (ExpandCollapseState.Expanded,
			                 node1sub1ExpandCollapse.ExpandCollapseState);
			Assert.AreEqual (ExpandCollapseState.LeafNode,
			                 node1sub2ExpandCollapse.ExpandCollapseState);
			Assert.AreEqual (ExpandCollapseState.LeafNode,
			                 node1sub1sub1ExpandCollapse.ExpandCollapseState);

			TestProperty (node1Provider,
			              ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty,
			              ExpandCollapseState.Expanded);
			TestProperty (node2Provider,
			              ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty,
			              ExpandCollapseState.LeafNode);
			TestProperty (node1sub1Provider,
			              ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty,
			              ExpandCollapseState.Expanded);
			TestProperty (node1sub2Provider,
			              ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty,
			              ExpandCollapseState.LeafNode);
			TestProperty (node1sub1sub1Provider,
			              ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty,
			              ExpandCollapseState.LeafNode);

			bridge.ResetEventLists ();
			
			node1.Collapse ();
			
			propertyEventTuple =
				bridge.GetAutomationPropertyEventFrom (node1Provider,
				                                       ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty.Id);
			Assert.IsNotNull (propertyEventTuple,
			                  "Expected property change event on node 1");
			Assert.AreEqual (ExpandCollapseState.Expanded,
			                 propertyEventTuple.e.OldValue,
			                 "Old value");
			Assert.AreEqual (ExpandCollapseState.Collapsed,
			                 propertyEventTuple.e.NewValue,
			                 "New value");

			Assert.AreEqual (ExpandCollapseState.Collapsed,
			                 node1ExpandCollapse.ExpandCollapseState);
			Assert.AreEqual (ExpandCollapseState.LeafNode,
			                 node2ExpandCollapse.ExpandCollapseState);
			Assert.AreEqual (ExpandCollapseState.Expanded,
			                 node1sub1ExpandCollapse.ExpandCollapseState);
			Assert.AreEqual (ExpandCollapseState.LeafNode,
			                 node1sub2ExpandCollapse.ExpandCollapseState);
			Assert.AreEqual (ExpandCollapseState.LeafNode,
			                 node1sub1sub1ExpandCollapse.ExpandCollapseState);

			TestProperty (node1Provider,
			              ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty,
			              ExpandCollapseState.Collapsed);
			TestProperty (node2Provider,
			              ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty,
			              ExpandCollapseState.LeafNode);
			TestProperty (node1sub1Provider,
			              ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty,
			              ExpandCollapseState.Expanded);
			TestProperty (node1sub2Provider,
			              ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty,
			              ExpandCollapseState.LeafNode);
			TestProperty (node1sub1sub1Provider,
			              ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty,
			              ExpandCollapseState.LeafNode);
		}
Exemplo n.º 16
0
		public void ExpandCollapseTest ()
		{
			TreeView treeView = new TreeView ();

			TreeNode node1 = new TreeNode ("node1");
			TreeNode node2 = new TreeNode ("node2");
			
			TreeNode node1sub1 = new TreeNode ("node1 - sub1");
			TreeNode node1sub2 = new TreeNode ("node1 - sub2");
			node1.Nodes.Add (node1sub1);
			node1.Nodes.Add (node1sub2);

			TreeNode node1sub1sub1 = new TreeNode ("node1 - sub1 - sub1");
			node1sub1.Nodes.Add (node1sub1sub1);

			treeView.Nodes.AddRange (new TreeNode [] {
				node1,
				node2});

			treeView.CollapseAll ();
			
			IRawElementProviderFragmentRoot provider = (IRawElementProviderFragmentRoot)
				GetProviderFromControl (treeView);

			IRawElementProviderFragmentRoot node1Provider = (IRawElementProviderFragmentRoot)
				provider.Navigate (NavigateDirection.FirstChild);
			IRawElementProviderFragmentRoot node2Provider = (IRawElementProviderFragmentRoot)
				node1Provider.Navigate (NavigateDirection.NextSibling);
			
//			IRawElementProviderFragmentRoot node1sub1Provider = (IRawElementProviderFragmentRoot)
//				node1Provider.Navigate (NavigateDirection.FirstChild);
//			IRawElementProviderFragmentRoot node1sub2Provider = (IRawElementProviderFragmentRoot)
//				node1sub1Provider.Navigate (NavigateDirection.NextSibling);
			
//			IRawElementProviderFragmentRoot node1sub1sub1Provider = (IRawElementProviderFragmentRoot)
//				node1sub1Provider.Navigate (NavigateDirection.FirstChild);

			IExpandCollapseProvider node1ExpandCollapse = (IExpandCollapseProvider)
				node1Provider.GetPatternProvider (ExpandCollapsePatternIdentifiers.Pattern.Id);
			IExpandCollapseProvider node2ExpandCollapse = (IExpandCollapseProvider)
				node2Provider.GetPatternProvider (ExpandCollapsePatternIdentifiers.Pattern.Id);

//			IExpandCollapseProvider node1sub1ExpandCollapse = (IExpandCollapseProvider)
//				node1sub1Provider.GetPatternProvider (ExpandCollapsePatternIdentifiers.Pattern.Id);
//			IExpandCollapseProvider node1sub2ExpandCollapse = (IExpandCollapseProvider)
//				node1sub2Provider.GetPatternProvider (ExpandCollapsePatternIdentifiers.Pattern.Id);

//			IExpandCollapseProvider node1sub1sub1ExpandCollapse = (IExpandCollapseProvider)
//				node1sub1sub1Provider.GetPatternProvider (ExpandCollapsePatternIdentifiers.Pattern.Id);

			Assert.IsFalse (node1.IsExpanded);
			Assert.IsFalse (node2.IsExpanded);
			Assert.IsFalse (node1sub1.IsExpanded);
			Assert.IsFalse (node1sub2.IsExpanded);
			Assert.IsFalse (node1sub1sub1.IsExpanded);

			node1ExpandCollapse.Expand ();

			// TODO: test winforms events?

			Assert.IsTrue (node1.IsExpanded);
			Assert.IsFalse (node2.IsExpanded);
			Assert.IsFalse (node1sub1.IsExpanded);
			Assert.IsFalse (node1sub2.IsExpanded);
			Assert.IsFalse (node1sub1sub1.IsExpanded);

			node1ExpandCollapse.Expand ();

			Assert.IsTrue (node1.IsExpanded);
			Assert.IsFalse (node2.IsExpanded);
			Assert.IsFalse (node1sub1.IsExpanded);
			Assert.IsFalse (node1sub2.IsExpanded);
			Assert.IsFalse (node1sub1sub1.IsExpanded);

			node1ExpandCollapse.Collapse ();

			Assert.IsFalse (node1.IsExpanded);
			Assert.IsFalse (node2.IsExpanded);
			Assert.IsFalse (node1sub1.IsExpanded);
			Assert.IsFalse (node1sub2.IsExpanded);
			Assert.IsFalse (node1sub1sub1.IsExpanded);

			node1ExpandCollapse.Collapse ();

			Assert.IsFalse (node1.IsExpanded);
			Assert.IsFalse (node2.IsExpanded);
			Assert.IsFalse (node1sub1.IsExpanded);
			Assert.IsFalse (node1sub2.IsExpanded);
			Assert.IsFalse (node1sub1sub1.IsExpanded);

			try {
				node2ExpandCollapse.Expand ();
				Assert.Fail ("Expected InvalidOperationException when Expanding a LeafNode");
			} catch (InvalidOperationException) {
				// Expected
			}

			try {
				node2ExpandCollapse.Collapse ();
				Assert.Fail ("Expected InvalidOperationException when Collapsing a LeafNode");
			} catch (InvalidOperationException) {
				// Expected
			}

			treeView.Enabled = false;
			

			try {
				node1ExpandCollapse.Expand ();
				Assert.Fail ("Expected ElementNotEnabledException when Expanding a node in a disabled TreeView");
			} catch (ElementNotEnabledException) {
				// Expected
			}

			try {
				node1ExpandCollapse.Collapse ();
				Assert.Fail ("Expected ElementNotEnabledException when Collapsing a node in a disabled TreeView");
			} catch (ElementNotEnabledException) {
				// Expected
			}
		}