protected void RecurseCollection(NodeDef node, dynamic collection, TreeNode tnCurrent) { if (node.Nodes.Count > 0) { // Collection is a Dictionary<string, dynamic> where dynamic is a List<T> // obj is a KeyValuePair<string, dynamic> foreach (var kvp in collection.Collection) { string collectionName = kvp.Key; var collectionItems = kvp.Value; // Doesn't matter what nodeDef we find, this is only to get the TypeName and number of child nodes on recursion. // But it does allow us to separate the serialization order from the tree definition order. List <NodeDef> matchingNodes = node.Nodes.FindAll(t => t.TypeName.Contains(collectionName)); NodeDef nodeDef = node.Nodes.Find(t => t.TypeName.Contains(collectionName)); foreach (var item in collectionItems) { // Do not create new instances for the items, as they have already been created! IXtreeNode controller = (IXtreeNode)Activator.CreateInstance(Type.GetType(nodeDef.TypeName), new object[] { false }); controller.Item = item; TreeNode tn = View.AddNode(controller, tnCurrent); string name = ((IHasCollection)item).Name; tn.Text = (String.IsNullOrWhiteSpace(name) ? tn.Text : name); RecurseCollection(nodeDef, item, tn); } } } }
/// <summary> /// Recursively copy the tree at src into dest. /// </summary> protected void CopyNodes(TreeNode dest, TreeNode src) { foreach (TreeNode childSrcNode in src.Nodes) { NodeInstance childInst = (NodeInstance)childSrcNode.Tag; Symbol childInstSymbol = (Symbol)childInst.Instance.Item; // Create a new controller. IXtreeNode controller = (IXtreeNode)Activator.CreateInstance(Type.GetType(childInst.NodeDef.TypeName), new object[] { false }); // Create a new symbol. Symbol item = new Symbol() { Name = childInstSymbol.Name, Structure = childInstSymbol.Structure }; controller.Item = item; // Add the new symbol to the destination symbol collection. ((Symbol)((NodeInstance)dest.Tag).Instance.Item).Symbols.Add(item); TreeNode childDestNode = View.AddNode(controller, dest); // TODO: Yuck. Clean this up so the model is king, and drives any controller, and remove the inc/dec from the respective view! ApplicationController.SymbolListController.IfNotNull(ctrl => ctrl.AddSymbol(item.Name)).Else(() => ApplicationModel.IncrementSymbolReference(item.Name)); ApplicationController.StructureListController.IfNotNull(ctrl => ctrl.AddStructure(item.Structure)).Else(() => ApplicationModel.IncrementStructureReference(item.Structure)); // Recurse. CopyNodes(childDestNode, childSrcNode); } }
public IXtreeNode CreateImplementingType(IXtreeNode parent) { IXtreeNode inst = null; inst = (IXtreeNode)Activator.CreateInstance(ImplementingType); inst.Parent = parent; return(inst); }
public override bool AddNode(IXtreeNode parentInstance, string tag) { IGenericController ctrl = (IGenericController)parentInstance; ctrl.Collection[GenericTypeName].Add(Instance); return(true); }
public override bool AutoDeleteNode(IXtreeNode parentInstance) { IGenericController ctrl = (IGenericController)parentInstance; ctrl.Collection[GenericTypeName].Remove(Instance); return(true); }
public override bool DeleteNode(IXtreeNode parentInstance) { // TODO: Inject the ability to confirm the delete operation. IGenericController ctrl = (IGenericController)parentInstance; ctrl.Collection[GenericTypeName].Remove(Instance); return(true); }
protected void RecurseCollection(NodeDef node, dynamic collection, TreeNode tnCurrent) { if (node.Nodes.Count > 0) { // Collection is a Dictionary<string, dynamic> where dynamic is a List<T> // obj is a KeyValuePair<string, dynamic> foreach (var kvp in collection.Collection) { string collectionName = kvp.Key; var collectionItems = kvp.Value; // Doesn't matter what nodeDef we find, this is only to get the TypeName and number of child nodes on recursion. // But it does allow us to separate the serialization order from the tree definition order. List <NodeDef> matchingNodes = node.Nodes.FindAll(t => t.TypeName.Contains(collectionName)); NodeDef nodeDef = node.Nodes.Find(t => t.TypeName.Contains(collectionName)); foreach (var item in collectionItems) { // Do not create new instances for the items, as they have already been created! IXtreeNode controller = (IXtreeNode)Activator.CreateInstance(Type.GetType(nodeDef.TypeName), new object[] { false }); controller.Item = item; TreeNode tn = View.AddNode(controller, tnCurrent); // If the item is a symbol, then we want to also show in the symbol and structure lists the associated symbol and structure! if (item is Symbol) { // TODO: Yuck. Clean this up so the model is king, and drives any controller, and remove the inc/dec from the respective view! ApplicationController.SymbolListController.IfNotNull(ctrl => ctrl.AddSymbol(item.Name)).Else(() => ApplicationModel.IncrementSymbolReference(item.Name)); ApplicationController.StructureListController.IfNotNull(ctrl => ctrl.AddStructure(item.Structure)).Else(() => ApplicationModel.IncrementStructureReference(item.Structure)); } else { if (!String.IsNullOrEmpty(item.Name)) { tn.Text = item.Name; } } // string name = ((IHasCollection)item).Name; // tn.Text = (String.IsNullOrWhiteSpace(name) ? tn.Text : name); RecurseCollection(nodeDef, item, tn); } } } }
public virtual void MoveTo(IXtreeNode newParent, IXtreeNode oldParent, int idx, TreeNode movingNode) { int oldIdx = oldParent.Index(this); idx = AdjustIndex(newParent, movingNode, idx); // Make sure indexing is supported by the controller. if (oldIdx != -1) { // If we're moving the node internally to our own parent... if (newParent == oldParent) { // Get the old index. bool ret = AutoDeleteNode(oldParent); // If this is before the new insert point, we can delete the old index // and insert at idx-1, since everything is shifted back one entry. // If the controller did not delete the node, then the insertion point // is "idx", not "idx-1" if ((oldIdx < idx) && (ret)) { InsertNode(oldParent, idx - 1); } else { // the oldIdx occurs after the new point, so we can delete the old entry // and insert the new one without changing the new index point. InsertNode(oldParent, idx); } } else { // parent is different, so delete our node... AutoDeleteNode(oldParent); // Insert our field in the new parent. InsertNode(newParent, idx); } } }
public virtual void MoveTo(IXtreeNode newParent, IXtreeNode oldParent, int idx, TreeNode movingNode) { int oldIdx = oldParent.Index(this); idx=AdjustIndex(newParent, movingNode, idx); // Make sure indexing is supported by the controller. if (oldIdx != -1) { // If we're moving the node internally to our own parent... if (newParent == oldParent) { // Get the old index. bool ret=AutoDeleteNode(oldParent); // If this is before the new insert point, we can delete the old index // and insert at idx-1, since everything is shifted back one entry. // If the controller did not delete the node, then the insertion point // is "idx", not "idx-1" if ( (oldIdx < idx) && (ret) ) { InsertNode(oldParent, idx - 1); } else { // the oldIdx occurs after the new point, so we can delete the old entry // and insert the new one without changing the new index point. InsertNode(oldParent, idx); } } else { // parent is different, so delete our node... AutoDeleteNode(oldParent); // Insert our field in the new parent. InsertNode(newParent, idx); } } }
public NewNodeEventArgs(IXtreeNode instanceNode, NodeDef nodeDef, TreeNode treeNode) { this.instanceNode = instanceNode; this.nodeDef = nodeDef; this.treeNode = treeNode; }
public DeletingNodeEventArgs(IXtreeNode instanceNode) { this.instanceNode = instanceNode; }
public NodeInstance(TreeNode tn, NodeDef def, IXtreeNode instance) { this.tn = tn; nodeDef = def; this.instance = instance; }
public TreeNode AddNode(IXtreeNode inst, TreeNode parent) { TreeNode node = TreeView.AddNode(inst, parent); return(node); }
public abstract bool AddNode(IXtreeNode parentInstance, string tag);
public TreeNode CreateNodeAndRequiredChildren(NodeDef nodeDef, IXtreeNode parentInst) { TreeNode tn = CreateNode(nodeDef, parentInst); UpdateImageList(tn, nodeDef, parentInst); foreach (NodeDef child in nodeDef.Nodes) { // If the current node is recursive, then ignore nodes from the parent // that are NOT recursive. In other words, the current node should only // select itself. This prevents required nodes of the parent from being added. if ((nodeDef.Recurse) && (!child.Recurse)) { continue; } if (child.IsRequired) { IXtreeNode inst = child.CreateImplementingType(parentInst); // Set the qualifier to distinguish a generic controller with a concrete type that it manages. inst.TypeData = child.TypeData; TreeNode tnChild = CreateNodeAndRequiredChildren(child, inst); bool success = inst.AddNode(parentInst, null); OnNewNode(new NewNodeEventArgs(inst, nodeDef, tnChild)); tn.Nodes.Add(tnChild); tn.Expand(); } } return tn; }
protected void ReadNode(XmlDocument xdoc, XmlNode node, TreeNodeCollection nodes, IXtreeNode parent) { foreach (XmlNode xn in node.ChildNodes) { IXtreeNode inst = nodeList[xn.Name].CreateImplementingType(parent); // Set the qualifier to distinguish a generic controller with a concrete type that it manages. inst.TypeData = nodeList[xn.Name].TypeData; TreeNode tn = CreateNode(nodeList[xn.Name], inst); nodes.Add(tn); ReadNode(xdoc, xn, tn.Nodes, inst); if (Convert.ToBoolean(xn.Attributes["IsExpanded"].Value)) { tn.Expand(); } } }
public void MoveTo(IXtreeNode newParent, IXtreeNode oldParent, int idx, TreeNode movingNode) { }
public virtual int AdjustIndex(IXtreeNode newParent, TreeNode movingNode, int idx) { return idx; }
public bool AddNode(IXtreeNode parentInstance, string tag) { return(true); }
public bool AutoDeleteNode(IXtreeNode parentInstance) { return(true); }
public bool AutoDeleteNode(IXtreeNode parentInstance) { return true; }
public bool AddNode(IXtreeNode parentInstance, string tag) { return true; }
public TreeNode AddNode(IXtreeNode inst, TreeNode parent) { NodeDef nodeDef = null; // System.Diagnostics.Debug.WriteLine("Searching for TypeName: "+inst.GetType().AssemblyQualifiedName); // System.Diagnostics.Debug.WriteLine("controllerToNodeDefMap.Count==" + controllerToNodeDefMap.Count); ControllerInfo ci = new ControllerInfo(inst.GetType(), inst.TypeData); bool found = controllerToNodeDefMap.TryGetValue(ci, out nodeDef); if (!found) { throw new ApplicationException("The controller instance "+inst.GetType().AssemblyQualifiedName+" is expected but not defined in a TypeName attribute of the tree schema."); } TreeNode tn = CreateNodeAndRequiredChildren(nodeDef, inst); if (parent != null) { parent.Nodes.Add(tn); } else { Nodes.Add(tn); } // Fire event that a node has been created. OnNewNode(new NewNodeEventArgs(inst, nodeDef, tn)); return tn; }
public TreeNode CreateNode(NodeDef nodeDef, IXtreeNode inst) { TreeNode tn = new TreeNode(); tn.Text = nodeDef.Text; // If no controller is specified, use the text in the NodeDef. if (!(inst is PlaceholderInstance)) { // Otherwise, get the text from the controller... if (inst.Name != null) { // if it's not null! tn.Text = inst.Name; } } tn.Tag = new NodeInstance(tn, nodeDef, inst); UpdateImageList(tn, nodeDef, inst); return tn; }
public TreeNode AddNode(IXtreeNode inst, TreeNode parent) { TreeNode node = TreeView.AddNode(inst, parent); return node; }
protected void UpdateImageList(TreeNode tn, NodeDef nodeDef, IXtreeNode inst) { if (nodeDef.ImageList != null) { // Have images been loaded into the TreeView's image list? if (nodeDef.ImageOffset == -1) { // No. Load them and save the offset. nodeDef.ImageOffset = ImageList.Images.Count; foreach (Image img in nodeDef.ImageList.Images) { ImageList.Images.Add(img); } } // Yes, just update the indices. tn.ImageIndex = nodeDef.ImageOffset + inst.IconIndex; tn.SelectedImageIndex = nodeDef.ImageOffset + inst.SelectedIconIndex; } }
public virtual int AdjustIndex(IXtreeNode newParent, TreeNode movingNode, int idx) { return(idx); }
/// <summary> /// Handles clicking on a node and either editing the label (double click) or /// calling the controller's Select method. /// </summary> /// <param name="e"></param> protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); selNode = GetNodeAt(e.Location); if (selNode != null) { if (e.Button == MouseButtons.Left) { if (e.Clicks == 2) { if (TreeDoubleClick != null) { TreeDoubleClick(this, EventArgs.Empty); } } // clicked twice on the same node? if (selNode == SelectedNode) { // Is writeable? if (!((NodeInstance)selNode.Tag).NodeDef.IsReadOnly) { // Not currently editing? if (!selNode.IsEditing) { // Then begin edit of the label. LabelEdit = true; selNode.BeginEdit(); } } else { // Re-select the same node, in case we're binding to a property grid that has // displayed some other information, we now want to update any dependent controls. ((NodeInstance)selNode.Tag).Instance.Select(selNode); } } else { // Clicked on a different node. Select it and call // the controller's Select method. SelectedNode = selNode; ((NodeInstance)selNode.Tag).Instance.Select(selNode); } } else { // Other mouse button. Still select the node. SelectedNode = selNode; ((NodeInstance)selNode.Tag).Instance.Select(selNode); } // Get the backing node instance of the selected node. selectedNodeInstance = ((NodeInstance)SelectedNode.Tag).Instance; } }
public abstract void InsertNode(IXtreeNode parentInstance, int idx);
public abstract bool AutoDeleteNode(IXtreeNode parentInstance);
public IXtreeNode CreateImplementingType(IXtreeNode parent) { IXtreeNode inst = null; inst = (IXtreeNode)Activator.CreateInstance(ImplementingType); inst.Parent = parent; return inst; }
public override void InsertNode(IXtreeNode parentInstance, int idx) { throw new NotImplementedException(); }