/// <summary> /// Creates a node based on the supplied NodeInfo. /// </summary> public MultiSourceTreeNode CreateNode(string nodeText, NodeInfo info, HasChildrenTest test) { MultiSourceTreeNode node = new MultiSourceTreeNode(); node.AddInfoEntry(info); UpdateNode(node); node.Text = nodeText; if (test != null) { if (test.Invoke(info)) { AddDummyNode(node); } } return(node); }
/// <summary> /// Adds child nodes to a node, merging duplicates as neccessary. /// </summary> protected void AddChildNodes(MultiSourceTreeNode node, MultiSourceTreeNode[] childNodes) { foreach (MultiSourceTreeNode childNode in childNodes) { // Look for a Tree Node that contains the same name. MultiSourceTreeNode existingNode = null; foreach (MultiSourceTreeNode n in node.Nodes) { if (n.Text == childNode.Text) { existingNode = n; break; } } // If we found an existing node, just add this node's InfoEntry to it. // (if it doesn't already contain it). // Otherwise, add the node to the child nodes. if (existingNode != null) { existingNode.Checked = node.Checked; foreach (NodeInfo info in childNode.InfoEntries) { if (!existingNode.ContainsEntry(info)) { existingNode.AddInfoEntry(info); // NOTE: We are assuming that the logic in this first NodeSource // will suffice when updating the node. // If this ever becomes a problem, we will need to take into // account the type priorities across multiple sources. // This would likely require us to setup an overall source // priority when it is added to the tree. existingNode.InfoEntries[0].ParentSource.UpdateNode(existingNode); } } } else { childNode.Checked = node.Checked; node.Nodes.Add(childNode); } } node.ChildrenAdded = true; }
private MultiSourceTreeNode UpdateNode(NodeInfo info) { if (InvokeRequired) { return((MultiSourceTreeNode)(Invoke((NodeMethodDelegate) delegate { return UpdateNode(info); }))); } //Output.Write(OutputTypes.Debug, "Updating Node (" + info.NodeType.GetType() + "): " + info.Identifier); string treePath = info.NodeType.GetTreePath(info); if (treePath == "") { return(null); } MultiSourceTreeNode node = (MultiSourceTreeNode)GetNodeFromPath(treePath); if (node != null) { //Output.Write(OutputTypes.Debug, "Found node in the tree."); // Add Node Info to node. //Output.Write(OutputTypes.Debug, "Adding info entry."); if (!node.ContainsEntry(info)) { node.AddInfoEntry(info); } //else //Output.Write(OutputTypes.Debug, " - (Already contained)"); info.ParentSource.UpdateNode(node); // Recursively update the parent nodes. NodeInfo parentInfo = info.NodeType.GetParentNodeInfo(info); if (parentInfo != null) { if (parentInfo.Identifier != "") { //Output.Write(OutputTypes.Debug, "Updating parent node."); UpdateNode(parentInfo); } } return(node); } else { //Output.Write(OutputTypes.Debug, "The node does not exist in the tree."); NodeInfo parentInfo = info.NodeType.GetParentNodeInfo(info); MultiSourceTreeNode parentNode; if (parentInfo.Identifier != "") { //Output.Write(OutputTypes.Debug, "Updating parent node."); parentNode = UpdateNode(parentInfo); } else { // We've reached the root node, and the item does not exist. string parentTreePath = parentInfo.NodeType.GetTreePath(parentInfo); parentNode = (MultiSourceTreeNode)GetNodeFromPath(parentTreePath); } if (parentNode != null) { if (parentNode.ChildrenAdded) { //Output.Write(OutputTypes.Debug, "Parent node exists and its children have been added."); // Create the node. string nodeName = info.NodeType.GetNodeName(info.Identifier); node = info.ParentSource.CreateNode(nodeName, info, info.NodeType.HasChildren); //Output.Write(OutputTypes.Debug, "Manually add the new node (" + node.Text + ") to " + parentNode.Text + "."); AddChildNodes(parentNode, new MultiSourceTreeNode[] { node }); return(node); } } return(parentNode); } }