Beispiel #1
0
		/// <summary>
		/// Метод, вызывающий событие NeedImageIndex.
		/// </summary>
		/// <param name="node">Узел, для которого определяется индекс изображения.</param>
		/// <param name="imageIndex">Предполагаемый индекс изображения.</param>
		/// <returns></returns>
		protected int OnNeedImageIndex(SimTreeNode node, int imageIndex)
		{
			if(NeedImageIndex == null)
				return node.TreeItem.IsRoot ? 0 : nodeItemsImageIndex;
			NeedImageIndexEventArgs args = new NeedImageIndexEventArgs(node.TreeItem, imageIndex);
			NeedImageIndex(this, args);
			return args.ImageIndex;
		}
Beispiel #2
0
		//-------------------------------------------------------------------------------------
		#region << SimTree Handlers >>
		void tree_ItemAdded(object sender, CollectionChangeNotifyEventArgs args)
		{
			try
			{
				ITreeItem item = (ITreeItem)args.Item;
				if(isUpdated)
					return;
				if(item.Parent == null)
				{
					SimTreeNode node = new SimTreeNode(item, NodeTextPropName);
					if(item.HasChildren)
					{
						if(needImageIndexEventTarget == NeedImageIndexEventTarget.AllNodes)
							node.ImageIndex = OnNeedImageIndex(node, closedImageIndex);
						else
							node.ImageIndex = node.SelectedImageIndex = closedImageIndex;
					}
					else
						node.SelectedImageIndex = node.ImageIndex = OnNeedImageIndex(node);
					treeView.Nodes.Add(node);
				}
				else  //if(item.Parent.Props.ContainsParam("Node"))
				{
					SimTreeNode pNode = treeView.Nodes.Find(item.Parent);
					if(pNode != null)
						if(pNode.Nodes.Count == 1 && pNode.Nodes[0].Name == "-1")
						{
							pNode.Nodes.Clear();
							foreach(ITreeItem key in item.Parent.Children)
							{
								SimTreeNode node = new SimTreeNode(key, NodeTextPropName);
								if(key.HasChildren)
									node.Nodes.Add("-1", "hidden");
								if(treeView.ImageList != null)
									if(key.HasChildren)
									{
										if(needImageIndexEventTarget == NeedImageIndexEventTarget.AllNodes)
											node.ImageIndex = OnNeedImageIndex(node, closedImageIndex);
										else
											node.ImageIndex = node.SelectedImageIndex = closedImageIndex;
									}
									else
										node.SelectedImageIndex = node.ImageIndex = OnNeedImageIndex(node);
								pNode.Nodes.Add(node);
							}
						}
						else
						{ 
							SimTreeNode node = new SimTreeNode(item, NodeTextPropName);
							if(item.HasChildren)
								node.Nodes.Add("-1", "hidden");
							if(treeView.ImageList != null)
								if(item.IsGroup)  
								{
									if(needImageIndexEventTarget == NeedImageIndexEventTarget.AllNodes)
										node.ImageIndex = OnNeedImageIndex(node, closedImageIndex);
									else
										node.ImageIndex = node.SelectedImageIndex = closedImageIndex;
								}
								else
									node.SelectedImageIndex = node.ImageIndex = OnNeedImageIndex(node);
							pNode.Nodes.Add(node);
						} 
				}
			}
			catch(Exception Err)
			{
				ErrorBox.Show(Err);
			}
			//throw new Exception("The method or operation is not implemented.");
		}
Beispiel #3
0
		private void RecursSetNodesChecked(SimTreeNode node, CheckState check)
		{
			node.CheckState = check;
			node.StateImageIndex = (int)check;
			foreach(SimTreeNode n in node.Nodes)
				RecursSetNodesChecked(n, check );
		}
Beispiel #4
0
		/// <summary>
		/// Переустанавливает состояния для указанного элемента и всех его дочерних элементов.
		/// </summary>
		/// <param name="node"></param>
		public void ResetNodeState(SimTreeNode node)
		{
			if(chType == CheckBoxesType.None && node.StateImageIndex == -1)
				return;
		
			for (int a = 0; a < node.Nodes.Count; a++)
				ResetNodeState(node.Nodes[a]);

			if(chType == CheckBoxesType.None)
				node.StateImageIndex = -1;
			else if(chType == CheckBoxesType.ThreeState)
			{
				if(node.TreeItem.HasChildren)
				{
					CheckState ii = node.Nodes[0].CheckState;
					foreach(SimTreeNode n in node.Nodes)
						if(n.CheckState != ii)
						{
							ii = CheckState.Indeterminate;
							break;
						}
					node.CheckState = ii;
				} 
				node.StateImageIndex = (int)node.CheckState;
			}
			else
			{
				node.CheckState = (node.CheckState == CheckState.Checked ? CheckState.Checked : CheckState.Unchecked);
				node.StateImageIndex = (int)node.CheckState;
			}
		}
Beispiel #5
0
		//-------------------------------------------------------------------------------------
		void tree_BeforeExpand(object sender, TreeViewCancelEventArgs e)
		{
			try
			{
				SimTreeNode node = (SimTreeNode)e.Node;

				if(node.TreeItem.HasChildren && node.Nodes[0].Name != "-1")
				{
					treeView.ResetNodeState(node);
					if(treeView.ImageList != null && node.TreeItem.HasChildren)
					{
						if(needImageIndexEventTarget == NeedImageIndexEventTarget.AllNodes)
							node.ImageIndex = OnNeedImageIndex(node, openedImageIndex);
						else
							node.ImageIndex = node.SelectedImageIndex = openedImageIndex;
					}
					return;
				}
				node.Nodes.Clear();
				ITreeItem item = (ITreeItem)node.TreeItem;
				List<SimTreeNode> nodes = new List<SimTreeNode>(item.Children.Count());
				foreach(ITreeItem key in item.Children)
				{
					SimTreeNode n = new SimTreeNode(key, NodeTextPropName);
					if(key.HasChildren)
						n.Nodes.Add("-1", "hidden");
					if(treeView.ImageList != null)
						if(key.HasChildren)
						{
							if(needImageIndexEventTarget == NeedImageIndexEventTarget.AllNodes)
								n.ImageIndex = OnNeedImageIndex(n, closedImageIndex);
							else
								n.ImageIndex = n.SelectedImageIndex = closedImageIndex;
						} 
						else
							n.SelectedImageIndex = n.ImageIndex = OnNeedImageIndex(n);
					nodes.Add(n);
				}
				node.Nodes.AddRange(nodes);
				if(treeView.ImageList != null && node.TreeItem.HasChildren)
					if(needImageIndexEventTarget == NeedImageIndexEventTarget.AllNodes)
						node.ImageIndex = OnNeedImageIndex(node, openedImageIndex);
					else
						node.ImageIndex = node.SelectedImageIndex = openedImageIndex;
				treeView.ResetNodeState(node);
			}
			catch(Exception Err)
			{
				ErrorBox.Show(Err);
			}
		}
Beispiel #6
0
		/// <summary>
		/// Вызывает событие NodeCheckStateChanged.
		/// </summary>
		/// <param name="node"></param>
		protected void OnNodeCheckStateChanged(SimTreeNode node)
		{
			if(NodeCheckStateChanged != null)
				NodeCheckStateChanged(this, node);
		}
Beispiel #7
0
		//-------------------------------------------------------------------------------------
		#region Tree Methods
		/// <summary>
		/// Строит начальное дерево.
		/// </summary>
		private void BuildTree()
		{
			try
			{
				List<SimTreeNode> nodes = new List<SimTreeNode>();
				foreach(ITreeItem pid in tree.GetRootItems())
				{
					SimTreeNode node = new SimTreeNode(pid, NodeTextPropName);
					if(pid.HasChildren)
						node.Nodes.Add("-1", "hidden");
					if(treeView.ImageList != null)
						if(pid.HasChildren)
						{
							if(needImageIndexEventTarget == NeedImageIndexEventTarget.AllNodes)
								node.ImageIndex = OnNeedImageIndex(node, closedImageIndex);
							else
								node.ImageIndex = node.SelectedImageIndex = closedImageIndex;
						}
						else
							node.SelectedImageIndex = node.ImageIndex = OnNeedImageIndex(node);
					nodes.Add(node);
				}
				treeView.BeginUpdate();
				treeView.Nodes.Clear();
				treeView.Nodes.AddRange(nodes);

				if(treeView.Nodes.Count > 0)
					treeView.Nodes[0].Expand();

				btnFind.Enabled = true;
				treeView.ResetStates();
				treeView.EndUpdate();
			}
			catch(Exception Err)
			{
				ErrorBox.Show(Err);
			}
		}