protected void SetTreeItemParent(EqTreeItem treeItem, string newParentKey, string currentParentkey = null) { if (currentParentkey == newParentKey) { return; //Don't anything if the parent has not changed. } //Delink the existing parent DelinkTreeItemFromParent(treeItem); treeItem.ParentKey = newParentKey; if (newParentKey == null) { return; //The item is being moved to root. } var parent = FindTreeItem(newParentKey); if (parent == null) { throw new ApplicationException($"The {ParentKeyPropertyName} : {newParentKey} does not refer to a valid item and could not be set as a parent for item {treeItem.Label}"); } treeItem.AddParent(parent); treeItem.Parent.AddChild(treeItem); }
protected static void DelinkTreeItemFromParent(EqTreeItem treeItem) { if (!treeItem.IsRootNode) { treeItem.Parent?.Children?.Remove(treeItem); treeItem.Parent = null; } }
protected async Task ItemSelected(EqTreeItem selectedItem) { SetSelectedTreeItem(selectedItem); var originalObject = FindObjectFromDatasource(selectedItem); await OnItemSelected.InvokeAsync(originalObject); }
public void AddChild(EqTreeItem child) { if (Children == null) { Children = new List <EqTreeItem>(); } Children.Add(child); child.Level = this.Level + 1; }
protected void ShowTreeItem(EqTreeItem eqTreeItem) { if (eqTreeItem == null) { return; } eqTreeItem.IsExpanded = true; eqTreeItem.IsVisible = true; ShowTreeItem(eqTreeItem.Parent); }
protected void SetSelectedTreeItem(EqTreeItem newSelectedItem) { if (_selectedItem != null) { _selectedItem.IsSelected = false; //Notify the previously selected item that it has been deselected. } _selectedItem = newSelectedItem; if (_selectedItem != null) { _selectedItem.IsSelected = true; } }
protected List <EqTreeItem> TraverseChildren(EqTreeItem item, List <EqTreeItem> childrenList) { if (item.HasChildren) { foreach (var child in item.Children) { TraverseChildren(child, childrenList); } } childrenList.Add(item); return(childrenList); }
protected TValue FindObjectFromDatasource(EqTreeItem treeItem) { if (treeItem == null) { return(default(TValue)); } foreach (var item in Datasource) { if (treeItem.Key == item.GetPropValue(KeyPropertyName)?.ToString()) { return(item); } } return(default(TValue)); }
protected void AddChildren(EqTreeItem treeItem, IEnumerable <EqTreeItem> treeItems) { //Find all this nodes children var nodeChildren = treeItems.Where(c => c.ParentKey == treeItem.Key).ToList(); //If node exit if (nodeChildren.Count == 0) { return; } //Add the children. foreach (var child in nodeChildren) { child.Parent = treeItem; treeItem.AddChild(child); //Call each child to add their children AddChildren(child, treeItems); } }
public void AddParent(EqTreeItem parent) { Parent = parent; Level++; IncrementChildrenLevel(); }
protected List <EqTreeItem> FindAllTreeItemChildren(EqTreeItem item) { var childrenList = new List <EqTreeItem>(); return(TraverseChildren(item, childrenList)); }