public JsTreeNode Build(Node node, IEnumerable <T> entities) { JsTreeNode root = BuildNode(node, entities); ISet <int> set = new HashSet <int>(); node.Summarize(ref set); var unused = entities.Where(n => !set.Contains(GetContent(n))); foreach (var entity in unused) { root.AddChild(new JsTreeNode { text = GetText(entity), data = new JsTreeNodeData { content = GetContent(entity), elements = GetElements == null ? null : GetElements(entity) }, state = new JsTreeNodeState { opened = true } }); } return(root); }
public void AddChild(JsTreeNode node) { if (this.children == null) { this.children = new List <JsTreeNode>(); } this.children.Add(node); }
public Node Parse(int tree, JsTreeNode jsTreeNode) { int id = 0; Node root = null; ParseNode(tree, jsTreeNode, ref root, ref id); return(root); }
public Node Parse(int tree, IList <JsTreeNode> nodes) { JsTreeNode root = new JsTreeNode { children = nodes, data = new JsTreeNodeData() }; return(Parse(tree, root)); }
private JsTreeNode BuildNode(Node node, IEnumerable <T> entities) { JsTreeNode jsTreeNode = null; if (node.Parent == null) // root node is a dummy node. { jsTreeNode = new JsTreeNode(); } else { var entity = entities.SingleOrDefault(n => GetContent(n) == node.Data); if (entity != null) // if entity has been deleted, tree node is also obsoleted. { jsTreeNode = new JsTreeNode { text = GetText(entity), data = new JsTreeNodeData { content = GetContent(entity), elements = GetElements == null ? null : GetElements(entity) }, state = new JsTreeNodeState { opened = true } }; } } if (jsTreeNode != null && node.Children != null && node.Children.Count > 0) { foreach (Node child in node.Children) { var childJsTreeNode = BuildNode(child, entities); if (childJsTreeNode != null) { jsTreeNode.AddChild(childJsTreeNode); } } } return(jsTreeNode); }
private void ParseNode(int tree, JsTreeNode jsTreeNode, ref Node parent, ref int id) { Node node = null; if (parent == null) { node = new Node(tree, id++); parent = node; } else { node = new Node(tree, id++, parent.Id, jsTreeNode.data.content, jsTreeNode.data.elements); parent.AddChild(node); } if (jsTreeNode.children != null && jsTreeNode.children.Count > 0) { foreach (var child in jsTreeNode.children) { ParseNode(tree, child, ref node, ref id); } } }