} // _runTreeNodesRecursive() /// <summary> /// Generate a JObject for the tree's current node /// </summary> private CswExtTree.TreeNode _getTreeNode(ICswNbtTree Tree, CswExtTree.TreeNode Parent, CswNbtSdTrees.Contract.Request Request) { CswExtTree.TreeNode Ret; if (null != Request && Request.UseCheckboxes) { Ret = new CswExtTree.TreeNodeWithCheckbox(); } else { Ret = new CswExtTree.TreeNode(); } CswNbtNodeKey ThisNodeKey = Tree.getNodeKeyForCurrentPosition(); string ThisNodeName = Tree.getNodeNameForCurrentPosition(); string ThisNodeIcon = ""; string ThisNodeKeyString = ThisNodeKey.ToString(); string ThisNodeId = ""; int ThisNodeTypeId = int.MinValue; int ThisObjectClassId = int.MinValue; bool ThisNodeLocked = false; bool ThisNodeDisabled = false; bool ThisNodeFavorite = false; CswNbtMetaDataNodeType ThisNodeType = _CswNbtResources.MetaData.getNodeType(ThisNodeKey.NodeTypeId); switch (ThisNodeKey.NodeSpecies) { case CswEnumNbtNodeSpecies.Plain: ThisNodeId = ThisNodeKey.NodeId.ToString(); ThisNodeName = Tree.getNodeNameForCurrentPosition(); ThisNodeTypeId = ThisNodeType.FirstVersionNodeTypeId; ThisObjectClassId = ThisNodeType.ObjectClassId; ThisNodeLocked = Tree.getNodeLockedForCurrentPosition(); ThisNodeDisabled = (false == Tree.getNodeIncludedForCurrentPosition()); ThisNodeFavorite = Tree.getNodeFavoritedForCurrentPosition(); if (ThisNodeFavorite) { ThisNodeIcon = CswNbtMetaDataObjectClass.IconPrefix16 + "starsolid.png"; } else { ThisNodeIcon = CswNbtMetaDataObjectClass.IconPrefix16 + Tree.getNodeIconForCurrentPosition(); } break; case CswEnumNbtNodeSpecies.Group: Ret.CssClass = "folder"; break; } CswNbtViewNode ThisNodeViewNode = _View.FindViewNodeByUniqueId(ThisNodeKey.ViewNodeUniqueId); string ThisNodeState = "closed"; if (ThisNodeKey.NodeSpecies == CswEnumNbtNodeSpecies.More || _View.ViewMode == CswEnumNbtViewRenderingMode.List || (Tree.IsFullyPopulated && Tree.getChildNodeCount() == 0) || (ThisNodeViewNode != null && ThisNodeViewNode.GetChildrenOfType(CswEnumNbtViewNodeType.CswNbtViewRelationship).Count == 0)) { ThisNodeState = "leaf"; } Ret.Name = ThisNodeName; Ret.Icon = ThisNodeIcon; Ret.Id = ThisNodeKeyString; switch (ThisNodeState) { case "closed": Ret.Expanded = false; break; case "leaf": Ret.IsLeaf = true; break; } if (null != Request) { Ret.Expanded = Request.ExpandAll; } if (int.MinValue != ThisNodeTypeId) { Ret.NodeTypeId = ThisNodeTypeId.ToString(); } if (int.MinValue != ThisObjectClassId) { Ret.ObjectClassId = ThisObjectClassId.ToString(); } Ret.NodeSpecies = ThisNodeKey.NodeSpecies.ToString(); Ret.NodeId = ThisNodeId; Ret.IsLocked = ThisNodeLocked; if (ThisNodeDisabled) { Ret.IsDisabled = true; Ret.CssClass = "disabled"; } Ret.IsFavorite = ThisNodeFavorite; if (null != Parent && false == string.IsNullOrEmpty(Parent.Path)) { Ret.Path = Parent.Path; } else { Ret.ParentId = "root"; Ret.Path = "|root"; } if (false == Tree.isCurrentPositionRoot()) { CswNbtNodeKey ParentKey = Tree.getNodeKeyForParentOfCurrentPosition(); if (ParentKey.NodeSpecies != CswEnumNbtNodeSpecies.Root) { Ret.ParentId = ParentKey.ToString(); } } Ret.Path += "|" + Ret.Id; if (Tree.getChildNodeCount() > 0) { Ret.Children = new Collection <CswExtTree.TreeNode>(); } else { Ret.Children = null; } Collection <CswNbtTreeNodeProp> ThisNodeProps = Tree.getChildNodePropsOfNode(); CswNbtViewRoot.forEachProperty EachNodeProp = (ViewProp) => { foreach (CswNbtTreeNodeProp NodeProp in ThisNodeProps) { if (NodeProp.PropName.ToLower().Trim() == ViewProp.Name.ToLower().Trim()) { Ret.data[new CswExtJsGridDataIndex(_View.ViewName, ViewProp.Name.ToLower().Trim())] = NodeProp.Gestalt; } } }; _View.Root.eachRelationship(relationshipCallBack: null, propertyCallBack: EachNodeProp); //ThisNodeObj["childcnt"] = Tree.getChildNodeCount().ToString(); return(Ret); } // _treeNodeJObject()
/// <summary> /// Recursively iterate the tree and add child nodes according to parent hierarchy /// </summary> private void _runTreeNodesRecursive(ICswNbtTree Tree, Collection <CswExtTree.TreeNode> TreeNodes, CswExtTree.TreeNode ParentNode, CswNbtSdTrees.Contract.Request Request, Int32 TotalNodeLimit, ref Int32 Count) { for (Int32 c = 0; c < Tree.getChildNodeCount(); c += 1) { Tree.goToNthChild(c); if (Count < TotalNodeLimit || TotalNodeLimit == Int32.MinValue) { CswExtTree.TreeNode TreeNode = _getTreeNode(Tree, ParentNode, Request); TreeNodes.Add(TreeNode); Count++; if (null != TreeNode.Children) { _runTreeNodesRecursive(Tree, TreeNode.Children, TreeNode, Request, TotalNodeLimit, ref Count); } } Tree.goToParentNode(); } if (Tree.getCurrentNodeChildrenTruncated()) { CswExtTree.TreeNode TruncatedTreeNode = _getTreeNode(Tree, ParentNode, null); TruncatedTreeNode.Name = "Results Truncated"; TruncatedTreeNode.IsLeaf = true; TruncatedTreeNode.Icon = "Images/icons/truncated.gif"; TruncatedTreeNode.Id = TruncatedTreeNode.Id + "_truncated"; TruncatedTreeNode.NodeId = ""; TreeNodes.Insert(0, TruncatedTreeNode); } } // _runTreeNodesRecursive()