/// <summary> /// Gets the full path of this hirarchical entity, seperated by a specified seperation string. /// </summary> public static string GetFullPath(this IHierarchy hierarchy, string seperator) { if (hierarchy == null) { return(null); } if (hierarchy.GetParent() == null || hierarchy.GetParent() == hierarchy) { return(hierarchy.Name); } else { return(hierarchy.GetParent().GetFullPath(seperator) + seperator + hierarchy.Name); } }
/// <summary> /// Gets all parents hierarchy of this node. /// </summary> public static IEnumerable <IHierarchy> GetAllParents(this IHierarchy child) { var parent = child.GetParent(); if (parent == null || parent == child) { return(new IHierarchy[0]); } else { return(parent.WithAllParents().OrderBy(i => i.GetFullPath()).ToArray()); } }
/// <summary> /// Gets the hierarchical path of the node in the hierarchical structure. /// </summary> /// <param name="pathResolver">The function delegate path resolver.</param> /// <returns>A <see cref="string" /> that identifies the hierarchical path relative to the current node.</returns> public string GetPath(Func <IHierarchy <T>, string> pathResolver) { StringBuilder path = new StringBuilder(); IHierarchy <T> current = this; while (current != null && current.Depth >= 0) { path.Insert(0, "."); path.Insert(0, pathResolver(current)); current = current.GetParent(); } return(path.ToString(0, path.Length - 1)); }
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); }
/// <summary> /// Gets whether this node is a root hierarchy node. /// </summary> public static bool IsRootNode(this IHierarchy node) => node.GetParent() == null;
internal static IHierarchy<TSource> AncestorsAndSelf<TSource>(IHierarchy<TSource> source) { return source.GetParent(); }
/// <summary> /// Gets whether this node is a root hierarchy node. /// </summary> public static bool IsRootNode(this IHierarchy node) { return(node.GetParent() == null); }