This override to TreeNode handles the displaying of an ObjectLabel in a custom way
Inheritance: System.Windows.Forms.TreeNode
Esempio n. 1
0
 /// <summary>
 /// Add secondary nodes to tree at nodes (and check any that occur in rghvoChosen),
 /// and return the one whose hvo is hvoToSelect, or nodeRepresentingCurrentChoice
 /// if none match.
 /// </summary>
 /// <param name="node">node to be added</param>
 /// <param name="nodes">where to add it</param>
 /// <param name="nodeRepresentingCurrentChoice">The node representing current choice.</param>
 /// <param name="objToSelect">The obj to select.</param>
 /// <param name="ownershipStack">The ownership stack.</param>
 /// <param name="chosenObjs">The chosen objects.</param>
 /// <returns></returns>
 public virtual LabelNode AddSecondaryNodesAndLookForSelected(LabelNode node,
                                                              TreeNodeCollection nodes, LabelNode nodeRepresentingCurrentChoice,
                                                              ICmObject objToSelect, Stack <ICmObject> ownershipStack, IEnumerable <ICmObject> chosenObjs)
 {
     // default is to do nothing
     return(nodeRepresentingCurrentChoice);
 }
Esempio n. 2
0
 /// <summary>
 /// Checks for selection.
 /// </summary>
 /// <param name="label">The label.</param>
 /// <param name="objToSelect">The obj to select.</param>
 /// <param name="node">The node.</param>
 /// <param name="nodeRepresentingCurrentChoice">The node representing current choice.</param>
 /// <returns></returns>
 protected virtual LabelNode CheckForSelection(ObjectLabel label, ICmObject objToSelect,
                                               LabelNode node, LabelNode nodeRepresentingCurrentChoice)
 {
     if (label.Object == objToSelect)                            //make it look selected
     {
         nodeRepresentingCurrentChoice = node;
     }
     return(nodeRepresentingCurrentChoice);
 }
Esempio n. 3
0
        /// <summary>
        /// Add the children nodes of a particular node in the tree. Do this recursively if
        /// that parameter is set to true. Also set the node as Checked if is it in the set
        /// or chosenObjs.
        /// </summary>
        public void AddChildren(bool recursively, IEnumerable <ICmObject> chosenObjs)
        {
            // JohnT: if we redo this every time we open, we discard the old nodes AND THEIR VALUES.
            // Thus, collapsing and reopening a tree clears its members! But we do need to check
            // that we have a label node, we put a dummy one in to show that it can be expanded.
            if (Nodes.Count > 0 && Nodes[0] is LabelNode)
            {
                // This already has its nodes, but what about its children if recursive?
                if (!recursively)
                {
                    return;
                }
                foreach (LabelNode node in Nodes)
                {
                    node.AddChildren(true, chosenObjs);
                }
                return;
            }
            Nodes.Clear();             // get rid of the dummy.

            AddSecondaryNodes(this, Nodes, chosenObjs);
            foreach (ObjectLabel label in ((ObjectLabel)Tag).SubItems)
            {
                if (!WantNodeForLabel(label))
                {
                    continue;
                }
                LabelNode node = Create(label, m_stylesheet, m_displayUsage);
                if (chosenObjs != null)
                {
                    node.Checked = chosenObjs.Contains(label.Object);
                }
                Nodes.Add(node);
                AddSecondaryNodes(node, node.Nodes, chosenObjs);
                if (recursively)
                {
                    node.AddChildren(true, chosenObjs);
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Add the children nodes of a particular node in the tree.
        /// While adding nodes if a match is found for objToSelect then nodeRepresentingCurrentChoice assigned to it
        /// and is returned. Otherwise if no node in the tree matches objToSelect this method returns null.
        /// </summary>
        public virtual LabelNode AddChildrenAndLookForSelected(ICmObject objToSelect,
                                                               Stack <ICmObject> ownershipStack, IEnumerable <ICmObject> chosenObjs)
        {
            LabelNode nodeRepresentingCurrentChoice = null;
            // JohnT: if this.Nodes[0] is not a LabelNode, it is a dummy node we added so that
            // its parent LOOKS like something we can expand. That is the usual case for a node
            // we can expand. Therefore finding one of those, or finding more or less than one
            // node, is evidence that we haven't previously computed the real children of this,
            // and should do so.
            bool fExpanded = Nodes.Count != 1 || (Nodes[0] as LabelNode) != null;

            if (!fExpanded)
            {
                Nodes.Clear();
                nodeRepresentingCurrentChoice = AddSecondaryNodesAndLookForSelected(this,
                                                                                    Nodes, nodeRepresentingCurrentChoice, objToSelect, ownershipStack, chosenObjs);
                foreach (ObjectLabel label in ((ObjectLabel)Tag).SubItems)
                {
                    if (!WantNodeForLabel(label))
                    {
                        continue;
                    }
                    LabelNode node = Create(label, m_stylesheet, m_displayUsage);
                    if (chosenObjs != null)
                    {
                        node.Checked = chosenObjs.Contains(label.Object);
                    }
                    Nodes.Add(node);
                    nodeRepresentingCurrentChoice = CheckForSelection(label, objToSelect,
                                                                      node, nodeRepresentingCurrentChoice);
                    nodeRepresentingCurrentChoice = AddSecondaryNodesAndLookForSelected(
                        node, node.Nodes, nodeRepresentingCurrentChoice, objToSelect,
                        ownershipStack, chosenObjs);
                }
            }
            else
            {
                // Even if we don't have to create children for this, we need to search the
                // children for matches, and perhaps expand some of them.
                foreach (LabelNode node in Nodes)
                {
                    nodeRepresentingCurrentChoice = CheckForSelection(node.Label,
                                                                      objToSelect, node, nodeRepresentingCurrentChoice);
                }
            }
            if (nodeRepresentingCurrentChoice == null)
            {
                foreach (LabelNode node in Nodes)
                {
                    if (ownershipStack.Contains(node.Label.Object))
                    {
                        nodeRepresentingCurrentChoice = node.AddChildrenAndLookForSelected(
                            objToSelect, ownershipStack, chosenObjs);
                        return(nodeRepresentingCurrentChoice);
                    }
                }
            }
            else
            {
                Expand();
                nodeRepresentingCurrentChoice.EnsureVisible();
            }
            return(nodeRepresentingCurrentChoice);
        }
Esempio n. 5
0
 /// <summary>
 /// Adds the secondary nodes.
 /// </summary>
 /// <param name="node">The node.</param>
 /// <param name="nodes">The nodes.</param>
 /// <param name="chosenObjs">The chosen objects.</param>
 public virtual void AddSecondaryNodes(LabelNode node, TreeNodeCollection nodes, IEnumerable <ICmObject> chosenObjs)
 {
     // default is to do nothing
 }
Esempio n. 6
0
		/// <summary>
		/// Checks for selection.
		/// </summary>
		/// <param name="label">The label.</param>
		/// <param name="objToSelect">The obj to select.</param>
		/// <param name="node">The node.</param>
		/// <param name="nodeRepresentingCurrentChoice">The node representing current choice.</param>
		/// <returns></returns>
		protected virtual LabelNode CheckForSelection(ObjectLabel label, ICmObject objToSelect,
			LabelNode node, LabelNode nodeRepresentingCurrentChoice)
		{
			if (label.Object == objToSelect)		//make it look selected
			{
				nodeRepresentingCurrentChoice = node;
			}
			return nodeRepresentingCurrentChoice;
		}
Esempio n. 7
0
		/// <summary>
		/// Adds the secondary nodes.
		/// </summary>
		/// <param name="node">The node.</param>
		/// <param name="nodes">The nodes.</param>
		/// <param name="chosenObjs">The chosen objects.</param>
		public virtual void AddSecondaryNodes(LabelNode node, TreeNodeCollection nodes, IEnumerable<ICmObject> chosenObjs)
		{
			// default is to do nothing
		}
Esempio n. 8
0
		/// <summary>
		/// Add secondary nodes to tree at nodes (and check any that occur in rghvoChosen),
		/// and return the one whose hvo is hvoToSelect, or nodeRepresentingCurrentChoice
		/// if none match.
		/// </summary>
		/// <param name="node">node to be added</param>
		/// <param name="nodes">where to add it</param>
		/// <param name="nodeRepresentingCurrentChoice">The node representing current choice.</param>
		/// <param name="objToSelect">The obj to select.</param>
		/// <param name="ownershipStack">The ownership stack.</param>
		/// <param name="chosenObjs">The chosen objects.</param>
		/// <returns></returns>
		public virtual LabelNode AddSecondaryNodesAndLookForSelected(LabelNode node,
			TreeNodeCollection nodes, LabelNode nodeRepresentingCurrentChoice,
			ICmObject objToSelect, Stack<ICmObject> ownershipStack, IEnumerable<ICmObject> chosenObjs)
		{
			// default is to do nothing
			return nodeRepresentingCurrentChoice;
		}
			/// --------------------------------------------------------------------------------
			/// <summary>
			/// Adds the secondary nodes.
			/// </summary>
			/// <param name="node">The node.</param>
			/// <param name="nodes">The nodes.</param>
			/// <param name="rghvoChosen">The rghvo chosen.</param>
			/// --------------------------------------------------------------------------------
			public override void AddSecondaryNodes(LabelNode node, TreeNodeCollection nodes, List<int> rghvoChosen)
			{
				AddSecondaryNodesAndLookForSelected(node, nodes, null, 0, null, rghvoChosen);
			}
Esempio n. 10
0
			/// --------------------------------------------------------------------------------
			/// <summary>
			/// Add secondary nodes to tree at nodes (and check any that occur in rghvoChosen),
			/// and return the one whose hvo is hvoToSelect, or nodeRepresentingCurrentChoice
			/// if none match.
			/// </summary>
			/// <param name="node">node to be added</param>
			/// <param name="nodes">where to add it</param>
			/// <param name="nodeRepresentingCurrentChoice">The node representing current choice.</param>
			/// <param name="hvoToSelect">The hvo to select.</param>
			/// <param name="ownershipStack">The ownership stack.</param>
			/// <param name="rghvoChosen">The rghvo chosen.</param>
			/// <returns></returns>
			/// --------------------------------------------------------------------------------
			public override LabelNode AddSecondaryNodesAndLookForSelected(LabelNode node, TreeNodeCollection nodes,
				LabelNode nodeRepresentingCurrentChoice, int hvoToSelect, Stack ownershipStack, List<int> rghvoChosen)
			{
				LabelNode result = nodeRepresentingCurrentChoice; // result unless we match hvoToSelect
				ObjectLabel label = (ObjectLabel)this.Tag;
				ISilDataAccess sda = label.Cache.MainCacheAccessor;
				int chvo = sda.get_VecSize(label.Hvo, m_leafFlid);
				List<int> secItems = new List<int>(chvo);
				for (int i = 0; i < chvo; i++)
					secItems.Add(sda.get_VecItem(label.Hvo, m_leafFlid, i));
				ObjectLabelCollection secLabels = new ObjectLabelCollection(label.Cache,
					new List<int>(secItems),
					"ShortNameTSS", "analysis vernacular"); // Enhance JohnT: may want to make these configurable one day...
				foreach (ObjectLabel secLabel in secLabels)
				{
					// Perversely, we do NOT want a LeafLabelNode for the leaves, because their HVOS are the leaf type,
					// and therefore objects that do NOT possess the leaf property!
					LabelNode secNode = new LabelNode(secLabel, m_stylesheet);
					if (rghvoChosen != null)
						secNode.Checked = (rghvoChosen.BinarySearch(secLabel.Hvo) >= 0);
					node.Nodes.Add(secNode);
					if (secLabel.Hvo == hvoToSelect)
						result = secNode;
				}
				return result;
			}
Esempio n. 11
0
			/// --------------------------------------------------------------------------------
			/// <summary>
			/// Checks for selection.
			/// </summary>
			/// <param name="label">The label.</param>
			/// <param name="hvoToSelect">The hvo to select.</param>
			/// <param name="node">The node.</param>
			/// <param name="nodeRepresentingCurrentChoice">The node representing current choice.</param>
			/// <param name="ownershipStack">The ownership stack.</param>
			/// <returns></returns>
			/// --------------------------------------------------------------------------------
			protected virtual LabelNode CheckForSelection(ObjectLabel label, int hvoToSelect,
				LabelNode node, LabelNode nodeRepresentingCurrentChoice, Stack ownershipStack)
			{
				if (label.Hvo == hvoToSelect)		//make it look selected
				{
					nodeRepresentingCurrentChoice = node;
				}
				return nodeRepresentingCurrentChoice;
			}
Esempio n. 12
0
			/// --------------------------------------------------------------------------------
			/// <summary>
			/// Add secondary nodes to tree at nodes (and check any that occur in rghvoChosen),
			/// and return the one whose hvo is hvoToSelect, or nodeRepresentingCurrentChoice
			/// if none match.
			/// </summary>
			/// <param name="node">node to be added</param>
			/// <param name="nodes">where to add it</param>
			/// <param name="nodeRepresentingCurrentChoice">The node representing current choice.</param>
			/// <param name="hvoToSelect">The hvo to select.</param>
			/// <param name="ownershipStack">The ownership stack.</param>
			/// <param name="rghvoChosen">The rghvo chosen.</param>
			/// <returns></returns>
			/// --------------------------------------------------------------------------------
			public virtual LabelNode AddSecondaryNodesAndLookForSelected(LabelNode node,
				TreeNodeCollection nodes, LabelNode nodeRepresentingCurrentChoice,
				int hvoToSelect, Stack ownershipStack, List<int> rghvoChosen)
			{
				// default is to do nothing
				return nodeRepresentingCurrentChoice;
			}
Esempio n. 13
0
			/// --------------------------------------------------------------------------------
			/// <summary>
			/// Adds the secondary nodes.
			/// </summary>
			/// <param name="node">The node.</param>
			/// <param name="nodes">The nodes.</param>
			/// <param name="rghvoChosen">The rghvo chosen.</param>
			/// --------------------------------------------------------------------------------
			public virtual void AddSecondaryNodes(LabelNode node, TreeNodeCollection nodes, List<int> rghvoChosen)
			{
				// default is to do nothing
			}
Esempio n. 14
0
		private void CheckChildrenForChosen(LabelNode node)
		{
			if (node == null || node.Nodes == null)
				return;
			for (int i = 0; i < node.Nodes.Count; ++i)
			{
				LabelNode x = node.Nodes[i] as LabelNode;
				if (x != null)
				{
					if (x.Checked)
						m_rghvoNewChosen.Add(x.Label.Hvo);
					CheckChildrenForChosen(x);
				}
			}
		}
Esempio n. 15
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Finds the node.
		/// </summary>
		/// <param name="searchNode">The search node.</param>
		/// <param name="hvo">The hvo.</param>
		/// <returns></returns>
		/// ------------------------------------------------------------------------------------
		protected LabelNode FindNode(LabelNode searchNode, int hvo)
		{
			//is it me?
			if (searchNode.Label.Hvo == hvo)
				return searchNode;

			//no, so look in my descendants
			searchNode.AddChildren(true, m_rghvoChosen);
			foreach (LabelNode node in searchNode.Nodes)
			{
				LabelNode n = FindNode(node, hvo);
				if (n!=null)
					return n;
			}
			return null;
		}