예제 #1
0
        public IEnumerable<SPTreeNode> LoadChildren(SPTreeNode parentNode)
        {
            var model = parentNode.Model;

            var index = model.Children.Count;

            model.LoadChildren();

            // Load new nodes
            var list = new List<SPTreeNode>();
            for (var count = index; count < parentNode.Model.Children.Count; count++)
            {
                var spNode = parentNode.Model.Children[count];

                var treeNode = SPTreeNode.Create(this, spNode);
                parentNode.Nodes.Insert(count, treeNode);
                list.Add(treeNode);
            }

            var modelCollection = model as ISPNodeCollection;
            if (modelCollection == null) return list;

            // Add more node
            if (modelCollection.LoadingChildren)
            {
                var moreNode = new MoreNode(modelCollection);
                moreNode.NodeProvider = modelCollection.NodeProvider;
                var spNode = SPMoreNode.Create(this, moreNode);
                list.Add(spNode);
                parentNode.Nodes.Add(spNode);
            }

            return list;
        }
예제 #2
0
        public IEnumerable<ISPNode> LoadCollectionChildren(ISPNodeCollection parentNode)
        {
            int batchCount = SPExplorerSettings.Current.BatchNodeLoad;

            var list = new List<ISPNode>();
            int count = 0;

            if (parentNode.Pointer == null)
            {
                parentNode.ClearChildren();
                parentNode.TotalCount = 0;
                var collection = (IEnumerable)parentNode.SPObject;
                parentNode.Pointer = collection.GetEnumerator();
                //_pointer.Reset();
                parentNode.MoveNext = parentNode.Pointer.MoveNext();
            }

            while (count <= batchCount && parentNode.MoveNext)
            {
                Type instanceType = parentNode.Pointer.Current.GetType();
                ISPNode node = null;

                if (parentNode.NodeTypes.ContainsKey(instanceType))
                {
                    node = parentNode.NodeTypes[instanceType];
                }
                else
                {
                    if (parentNode.DefaultNode != null)
                    {
                        node = parentNode.DefaultNode;
                    }
                }

                if (node != null)
                {
                    // Always create a new node, because the object has to be unique for each item in the treeview.
                    var instanceNode = (ISPNode) Activator.CreateInstance(node.GetType());
                    instanceNode.NodeProvider = parentNode.NodeProvider;
                    instanceNode.SPObject = parentNode.Pointer.Current;
                    instanceNode.Setup(parentNode.SPObject);
                    list.Add(instanceNode);
                }

                parentNode.MoveNext = parentNode.Pointer.MoveNext();
                count++;
                parentNode.TotalCount++;
            }
            // If there is more nodes in the collection, add a "More" item.
            if (count >= batchCount && parentNode.MoveNext)
            {
                var node = new MoreNode(parentNode);
                node.Setup(parentNode.SPObject);
                list.Add(node);
            }

            if (parentNode.TotalCount <= batchCount)
            {
                // There are a low number of nodes, therefore sort nodes by Text.
                return list.OrderBy(p => p.Text);
            }
            // Just add the elements without any sort, because of the high number of nodes.
            return list;
        }