public void CanBuild_HierarchyBranch()
 {
     HierarchyNode<ContentItem> node = new BranchHierarchyBuilder(a_a_a, null).Build();
     ItemHierarchyNavigator ih = new ItemHierarchyNavigator(node);
     Assert.AreEqual(a, ih.Current);
     Assert.IsNull(ih.Parent);
     EnumerableAssert.Count(5, ih.EnumerateAllItems());
 }
        public void Parent_IsSet()
        {
            HierarchyNode<ContentItem> node = new BranchHierarchyBuilder(a_a_a, null).Build();

            Assert.That(node.Parent, Is.Null);
            Assert.That(node.Children[0].Parent, Is.EqualTo(node));
            Assert.That(node.Children[0].Children[0].Parent, Is.EqualTo(node.Children[0]));
        }
Exemple #3
0
 internal static HierarchyNode<ContentItem> BuildBranchStructure(ItemFilter filter, IContentAdapterProvider adapters, ContentItem selectedItem, ContentItem root)
 {
     var structure = new BranchHierarchyBuilder(selectedItem, root, true) { UseMasterVersion = false }
         .Children((item) =>
         {
             var q = new N2.Persistence.Sources.Query { Parent = item, OnlyPages = true, Interface = Interfaces.Managing, Filter = filter };
             return adapters.ResolveAdapter<NodeAdapter>(item).GetChildren(q);
         })
         .Build();
     return structure;
 }
Exemple #4
0
		protected override void Render(HtmlTextWriter writer)
		{
			IContentAdapterProvider adapters = Engine.Resolve<IContentAdapterProvider>();

			if (Nodes == null)
				Nodes = new BranchHierarchyBuilder(SelectedItem, RootNode, true) { UseMasterVersion = false }
					.Children((item) => adapters.ResolveAdapter<NodeAdapter>(item).GetChildren(item, Interfaces.Managing).Where(Filter))
					.Build();

			TreeUtility.Write(Nodes, SelectedItem, adapters, Filter, SelectableTypes, SelectableExtensions, excludeRoot: false, target: Target, writer: writer);
		}
Exemple #5
0
        private void BuildControlHierarchy(ContentItem currentItem, ContentItem startPage)
        {
            if (currentItem == null)
                currentItem = startPage;

            ItemList children = currentItem.GetChildren();
            if (children.Count > 0)
                currentItem = children[0];
            IEnumerable<ContentItem> ancestors = GetAncestors(currentItem, startPage);
            ContentItem startingPoint = GetStartingPoint();
            if (startingPoint != null)
            {
                HierarchyBuilder builder = null;

                if (BranchMode)
                {
                    builder = new BranchHierarchyBuilder(currentItem, startingPoint);
                }
                else
                {
                    builder = new TreeHierarchyBuilder(startingPoint, MaxLevels);
                }

                HierarchyNode<ContentItem> node = builder.Children(Filters).Build();
                if (node.Current != null)
                {
                    AddControlsRecursive(this, node, CurrentItem, ancestors);
                }
            }
        }
 public void CanBuild_HierarchyBranch_AndAddInitialsChildren_WithDifferent_InitialAsLast()
 {
     HierarchyNode<ContentItem> node = new BranchHierarchyBuilder(a_a, a, true).Build();
     ItemHierarchyNavigator ih = new ItemHierarchyNavigator(node);
     EnumerableAssert.Count(5, ih.EnumerateAllItems());
 }
 public void BuildHierarchyBranch_SameInitialAndLast()
 {
     HierarchyNode<ContentItem> node = new BranchHierarchyBuilder(a, a).Build();
     ItemHierarchyNavigator ih = new ItemHierarchyNavigator(node);
     EnumerableAssert.Count(1, ih.EnumerateAllItems());
 }
Exemple #8
0
        protected override void CreateChildControls()
        {
            IContentAdapterProvider adapters = Engine.Resolve<IContentAdapterProvider>();

            if (Nodes == null)
                Nodes = new BranchHierarchyBuilder(SelectedItem, RootNode, true)
                    .Children((item) => adapters.ResolveAdapter<NodeAdapter>(item).GetChildren(item, Interfaces.Managing))
                    .Build();

            var tree = new N2.Web.Tree(Nodes)
                .OpenTo(SelectedItem)
                .Filters(Filter)
                .LinkProvider(item => BuildLink(adapters.ResolveAdapter<NodeAdapter>(item), item, item.Path == SelectedItem.Path, Target))
                .ToControl();

            AppendExpanderNodeRecursive(tree, Filter, Target, adapters);

            Controls.Add(tree);

            base.CreateChildControls();
        }