public ExtensionNode ReadNode(TreeNode tnode, string addin, ExtensionNodeType ntype, ExtensionNodeDescription elem, ModuleDescription module) { try { if (ntype.Type == null) { if (!InitializeNodeType (ntype)) return null; } ExtensionNode node; node = Activator.CreateInstance (ntype.Type) as ExtensionNode; if (node == null) { addinEngine.ReportError ("Extension node type '" + ntype.Type + "' must be a subclass of ExtensionNode", addin, null, false); return null; } tnode.AttachExtensionNode (node); node.SetData (addinEngine, addin, ntype, module); node.Read (elem); return node; } catch (Exception ex) { addinEngine.ReportError ("Could not read extension node of type '" + ntype.Type + "' from extension path '" + tnode.GetPath() + "'", addin, ex, false); return null; } }
internal void SetTreeNode (TreeNode node) { treeNode = node; }
void LoadExtensionElement(TreeNode tnode, string addin, ExtensionNodeDescriptionCollection extension, ModuleDescription module, ref int curPos, BaseCondition parentCondition, bool inComplextCondition, ArrayList addedNodes) { foreach (ExtensionNodeDescription elem in extension) { if (inComplextCondition) { parentCondition = ReadComplexCondition (elem, parentCondition); inComplextCondition = false; continue; } if (elem.NodeName == "ComplexCondition") { LoadExtensionElement (tnode, addin, elem.ChildNodes, module, ref curPos, parentCondition, true, addedNodes); continue; } if (elem.NodeName == "Condition") { Condition cond = new Condition (AddinEngine, elem, parentCondition); LoadExtensionElement (tnode, addin, elem.ChildNodes, module, ref curPos, cond, false, addedNodes); continue; } var pnode = tnode; ExtensionPoint extensionPoint = null; while (pnode != null && (extensionPoint = pnode.ExtensionPoint) == null) pnode = pnode.Parent; string after = elem.GetAttribute ("insertafter"); if (after.Length == 0 && extensionPoint != null && curPos == -1) after = extensionPoint.DefaultInsertAfter; if (after.Length > 0) { int i = tnode.Children.IndexOfNode (after); if (i != -1) curPos = i+1; } string before = elem.GetAttribute ("insertbefore"); if (before.Length == 0 && extensionPoint != null && curPos == -1) before = extensionPoint.DefaultInsertBefore; if (before.Length > 0) { int i = tnode.Children.IndexOfNode (before); if (i != -1) curPos = i; } // If node position is not explicitly set, add the node at the end if (curPos == -1) curPos = tnode.Children.Count; // Find the type of the node in this extension ExtensionNodeType ntype = addinEngine.FindType (tnode.ExtensionNodeSet, elem.NodeName, addin); if (ntype == null) { addinEngine.ReportError ("Node '" + elem.NodeName + "' not allowed in extension: " + tnode.GetPath (), addin, null, false); continue; } string id = elem.GetAttribute ("id"); if (id.Length == 0) id = AutoIdPrefix + (++internalId); TreeNode cnode = new TreeNode (addinEngine, id); ExtensionNode enode = ReadNode (cnode, addin, ntype, elem, module); if (enode == null) continue; cnode.Condition = parentCondition; cnode.ExtensionNodeSet = ntype; tnode.InsertChildNode (curPos, cnode); addedNodes.Add (cnode); if (cnode.Condition != null) Context.RegisterNodeCondition (cnode, cnode.Condition); // Load children if (elem.ChildNodes.Count > 0) { int cp = 0; LoadExtensionElement (cnode, addin, elem.ChildNodes, module, ref cp, parentCondition, false, addedNodes); } curPos++; } if (Context.FireEvents) tnode.NotifyChildrenChanged (); }
public void InsertChildNode (int n, TreeNode node) { node.parent = this; if (childrenList == null) childrenList = new ArrayList (); childrenList.Insert (n, node); // Dont call NotifyChildrenChanged here. It is called by ExtensionTree, // after inserting all children of the node. }
public TreeNode GetNode (string path, bool buildPath) { if (path.StartsWith ("/")) path = path.Substring (1); string[] parts = path.Split ('/'); TreeNode curNode = this; foreach (string part in parts) { int i = curNode.Children.IndexOfNode (part); if (i != -1) { curNode = curNode.Children [i]; continue; } if (buildPath) { TreeNode newNode = new TreeNode (addinEngine, part); curNode.AddChildNode (newNode); curNode = newNode; } else return null; } return curNode; }
public void AddChildNode (TreeNode node) { node.parent = this; if (childrenList == null) childrenList = new ArrayList (); childrenList.Add (node); }
TreeNode GetNode (string path) { TreeNode node = tree.GetNode (path); if (node != null || parentContext == null) return node; TreeNode supNode = parentContext.tree.GetNode (path); if (supNode == null) return null; if (path.StartsWith ("/")) path = path.Substring (1); string[] parts = path.Split ('/'); TreeNode srcNode = parentContext.tree; TreeNode dstNode = tree; foreach (string part in parts) { // Look for the node in the source tree int i = srcNode.Children.IndexOfNode (part); if (i != -1) srcNode = srcNode.Children [i]; else return null; // Now get the node in the target tree int j = dstNode.Children.IndexOfNode (part); if (j != -1) { dstNode = dstNode.Children [j]; } else { // Create if not found TreeNode newNode = new TreeNode (part); dstNode.AddChildNode (newNode); dstNode = newNode; // Copy extension data dstNode.ExtensionNodeSet = srcNode.ExtensionNodeSet; dstNode.ExtensionPoint = srcNode.ExtensionPoint; dstNode.Condition = srcNode.Condition; if (dstNode.Condition != null) RegisterNodeCondition (dstNode, dstNode.Condition); } } return dstNode; }
internal void UnregisterNodeCondition (TreeNode node, BaseCondition cond) { ArrayList list = (ArrayList) conditionsToNodes [cond]; if (list == null) return; list.Remove (node); if (list.Count == 0) { conditionsToNodes.Remove (cond); ArrayList conditionTypeIds = new ArrayList (); cond.GetConditionTypes (conditionTypeIds); foreach (string cid in conditionTypes.Keys) { ConditionInfo info = conditionTypes [cid] as ConditionInfo; if (info != null && info.BoundConditions != null) info.BoundConditions.Remove (cond); } } }
internal void RegisterNodeCondition (TreeNode node, BaseCondition cond) { ArrayList list = (ArrayList) conditionsToNodes [cond]; if (list == null) { list = new ArrayList (); conditionsToNodes [cond] = list; ArrayList conditionTypeIds = new ArrayList (); cond.GetConditionTypes (conditionTypeIds); foreach (string cid in conditionTypeIds) { // Make sure the condition is properly created GetCondition (cid); ConditionInfo info = CreateConditionInfo (cid); if (info.BoundConditions == null) info.BoundConditions = new ArrayList (); info.BoundConditions.Add (cond); } } list.Add (node); }
void LoadExtensionElement (TreeNode tnode, string addin, ExtensionNodeDescriptionCollection extension, ref int curPos, BaseCondition parentCondition, bool inComplextCondition, ArrayList addedNodes) { foreach (ExtensionNodeDescription elem in extension) { if (inComplextCondition) { parentCondition = ReadComplexCondition (elem, parentCondition); inComplextCondition = false; continue; } if (elem.NodeName == "ComplexCondition") { LoadExtensionElement (tnode, addin, elem.ChildNodes, ref curPos, parentCondition, true, addedNodes); continue; } if (elem.NodeName == "Condition") { Condition cond = new Condition (elem, parentCondition); LoadExtensionElement (tnode, addin, elem.ChildNodes, ref curPos, cond, false, addedNodes); continue; } string after = elem.GetAttribute ("insertafter"); if (after.Length > 0) { int i = tnode.Children.IndexOfNode (after); if (i != -1) curPos = i+1; } string before = elem.GetAttribute ("insertbefore"); if (before.Length > 0) { int i = tnode.Children.IndexOfNode (before); if (i != -1) curPos = i; } // Find the type of the node in this extension ExtensionNodeType ntype = AddinManager.SessionService.FindType (tnode.ExtensionNodeSet, elem.NodeName, addin); if (ntype == null) { AddinManager.ReportError ("Node '" + elem.NodeName + "' not allowed in extension: " + tnode.GetPath (), addin, null, false); continue; } string id = elem.GetAttribute ("id"); if (id.Length == 0) id = AutoIdPrefix + (++internalId); TreeNode cnode = new TreeNode (id); ExtensionNode enode = ReadNode (cnode, addin, ntype, elem); if (enode == null) continue; cnode.Condition = parentCondition; cnode.ExtensionNodeSet = ntype; tnode.InsertChildNode (curPos, cnode); addedNodes.Add (cnode); if (cnode.Condition != null) Context.RegisterNodeCondition (cnode, cnode.Condition); // Load children if (elem.ChildNodes.Count > 0) { int cp = 0; LoadExtensionElement (cnode, addin, elem.ChildNodes, ref cp, parentCondition, false, addedNodes); } curPos++; } if (Context.FireEvents) tnode.NotifyChildrenChanged (); }