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

            var originalObject = FindObjectFromDatasource(selectedItem);

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

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

            return(TraverseChildren(item, childrenList));
        }