Exemplo n.º 1
0
        static void ConfigureTreeViewNode(this GridViewRow row, IHierarchy item, Func <IHierarchy, bool> isItemCollapsed)
        {
            var parent = item.GetParent();

            var isVisible = true;

            if (parent != null)
            {
                isVisible = !isItemCollapsed(parent);
            }

            var isCollapsed = isItemCollapsed(item);
            var isRoot      = parent == null;
            var isLeaf      = item.GetChildren().None();

            // setting up grid view row attributes
            row.Attributes["itemid"] = item.GetId().ToString();
            row.CssClass            += " {0}{1}{2}{3}".FormatWith(
                item.GetAllParents().Select(a => a.GetId()).ToString(" "),
                " treeview-leaf-node".OnlyWhen(isLeaf),
                " treeview-root-node".OnlyWhen(isRoot),
                " collapsed".OnlyWhen(isCollapsed && !isLeaf));

            if (!isVisible)
            {
                row.Style["display"]           = "none";
                row.Attributes["collapsedfor"] = parent.GetId().ToString();
            }

            // Creating additional controls
            var spacerSpan   = CreateSpacer(item.GetAllParents().Count());
            var collapseIcon = CreateLink(item.GetId().ToString());

            // putting additional controls in the right place
            var anchorControl = FindAnchorControl(row);

            var parentToAdd  = anchorControl?.Parent ?? row.Cells[0];
            var controlIndex = anchorControl == null ? 0 : parentToAdd.Controls.IndexOf(anchorControl);

            parentToAdd.Controls.AddAt(controlIndex, collapseIcon);
            parentToAdd.Controls.AddAt(controlIndex, spacerSpan);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Gets all parents hierarchy of this node.
 /// </summary>
 public static IEnumerable <T> GetAllParents <T>(this IHierarchy child) where T : IHierarchy =>
 child.GetAllParents().Cast <T>().ToArray();
Exemplo n.º 3
0
 /// <summary>
 /// Gets this node as well as all its parents hierarchy.
 /// </summary>
 public static IEnumerable <IHierarchy> WithAllParents(this IHierarchy child) =>
 child.GetAllParents().Concat(child).OrderBy(i => i.GetFullPath()).ToArray();