Beispiel #1
0
 public TFTreeNode <T> AddChild(TFTreeNode <T> child)
 {
     if (_Children == null)
     {
         _Children = new List <TFTreeNode <T> >();
     }
     Children.Add(child);
     return(child);
 }
Beispiel #2
0
 public bool RemoveChild(TFTreeNode <T> child)
 {
     if (Children.Contains(child))
     {
         Children.Remove(child);
         if (!Children.Any())
         {
             _Children = null;
         }
         return(true);
     }
     else
     {
         return(false);
     }
 }
Beispiel #3
0
        protected TFTreeNode <T> CreateCollapsedTreeRecursive(Func <TFTreeNode <T>, bool> isNodeTypeToCollapse, TFTreeNode <T> parentNode)
        {
            TFTreeNode <T> retNode = parentNode;

            if (!isNodeTypeToCollapse(this))
            {
                var copiedNode = new TFTreeNode <T>(this.Data);

                if (parentNode == null)
                {
                    retNode = copiedNode;
                }
                else
                {
                    parentNode.AddChild(copiedNode);
                }

                foreach (TFTreeNode <T> child in Children)
                {
                    child.CreateCollapsedTreeRecursive(isNodeTypeToCollapse, copiedNode);
                }
            }
            else
            {
                bool isFirst = true;
                foreach (TFTreeNode <T> child in Children)
                {
                    var tmp = child.CreateCollapsedTreeRecursive(isNodeTypeToCollapse, parentNode);
                    if (isFirst)
                    {
                        isFirst = false;
                        retNode = tmp;
                    }
                }
            }

            return(retNode);
        }
Beispiel #4
0
        // ToDo: Make this return a list of TFTreeNodes in case the collapsed tree has a node
        // at the top that we throw out but has more than one child!
        public TFTreeNode <T> CreateCollapsedTree(Func <TFTreeNode <T>, bool> isNodeTypeToCollapse)
        {
            TFTreeNode <T> root      = null;
            TFTreeNode <T> lowerRoot = null;

            if (!isNodeTypeToCollapse(this))
            {
                root = new TFTreeNode <T>(this.Data);
            }

            bool isFirst = true;

            foreach (TFTreeNode <T> child in Children)
            {
                var tmp = child.CreateCollapsedTreeRecursive(isNodeTypeToCollapse, root);
                if (isFirst)
                {
                    isFirst   = false;
                    lowerRoot = tmp;
                }
            }

            return(root ?? lowerRoot);
        }