예제 #1
0
        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);
        }
예제 #2
0
 protected static void DelinkTreeItemFromParent(EqTreeItem treeItem)
 {
     if (!treeItem.IsRootNode)
     {
         treeItem.Parent?.Children?.Remove(treeItem);
         treeItem.Parent = null;
     }
 }
예제 #3
0
        protected async Task ItemSelected(EqTreeItem selectedItem)
        {
            SetSelectedTreeItem(selectedItem);

            var originalObject = FindObjectFromDatasource(selectedItem);

            await OnItemSelected.InvokeAsync(originalObject);
        }
예제 #4
0
 public void AddChild(EqTreeItem child)
 {
     if (Children == null)
     {
         Children = new List <EqTreeItem>();
     }
     Children.Add(child);
     child.Level = this.Level + 1;
 }
예제 #5
0
        protected void ShowTreeItem(EqTreeItem eqTreeItem)
        {
            if (eqTreeItem == null)
            {
                return;
            }

            eqTreeItem.IsExpanded = true;
            eqTreeItem.IsVisible  = true;
            ShowTreeItem(eqTreeItem.Parent);
        }
예제 #6
0
 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;
     }
 }
예제 #7
0
        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);
        }
예제 #8
0
        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));
        }
예제 #9
0
        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);
            }
        }
예제 #10
0
 public void AddParent(EqTreeItem parent)
 {
     Parent = parent;
     Level++;
     IncrementChildrenLevel();
 }
예제 #11
0
        protected List <EqTreeItem> FindAllTreeItemChildren(EqTreeItem item)
        {
            var childrenList = new List <EqTreeItem>();

            return(TraverseChildren(item, childrenList));
        }