Beispiel #1
0
 internal void SendValueChanged(DTreeNode <T> node)
 {
     if (OnValueChanged != null)
     {
         OnValueChanged(this, new DTreeEventArgs <T>(node, ENodeEvent.ValueChanged, -1));
     }
 }
Beispiel #2
0
        public DTreeNode <T> ToTree()
        {
            DTreeNode <T> ret = root;

            Reset();
            return(ret);
        }
Beispiel #3
0
 internal void SendNodeChanged(DTreeNode <T> node, ENodeEvent change, int index)
 {
     if (OnNodeChanged != null)
     {
         OnNodeChanged(this, new DTreeEventArgs <T>(node, change, index));
     }
 }
Beispiel #4
0
 internal DTreeNodeCollection(DTreeNode <T> owner)
 {
     if (owner == null)
     {
         throw new ArgumentNullException("owner");
     }
     mOwner = owner;
 }
Beispiel #5
0
 internal void InternalSetParent(DTreeNode <T> parent)
 {
     mParent = parent;
     if (mParent != null)
     {
         SetRootLink(parent.Root);
     }
 }
Beispiel #6
0
        public void Remove(DTreeNode <T> node)
        {
            int index = IndexOf(node);

            if (index < 0)
            {
                throw new ArgumentException("the node to remove is not a in this collection");
            }
            RemoveAt(index);
        }
Beispiel #7
0
        public DTreeNode <T> GetNodeAt(IEnumerable <int> index)
        {
            DTreeNode <T> node = this;

            foreach (int elementIndex in index)
            {
                node = node.Nodes[elementIndex];
            }
            return(node);
        }
Beispiel #8
0
        /// <summary>
        /// Appends a new node with the specified value
        /// </summary>
        /// <param name="value">value for the new node</param>
        /// <returns>the node that was created</returns>
        public DTreeNode <T> Add(T value)
        {
            DTreeNode <T> n = new DTreeNode <T>(value);

            List.Add(n);

            SendOwnerNodeChanged(ENodeEvent.ChildAdded, List.Count - 1);

            return(n);
        }
Beispiel #9
0
        /// <summary>
        /// Inserts a new node after the specified node
        /// </summary>
        /// <param name="insertPos">Existing node after which the new node is inserted</param>
        /// <param name="value">value for the new node</param>
        /// <returns>The newly created node</returns>
        public DTreeNode <T> InsertAfter(DTreeNode <T> insertPos, T value)
        {
            int index = IndexOf(insertPos) + 1;

            if (index == 0)
            {
                index = Count;
            }
            return(InsertAt(index, value));
        }
Beispiel #10
0
        protected override void OnValidate(object value)
        {
            // Verify: value.Parent must be null or this.mOwner)
            base.OnValidate(value);
            DTreeNode <T> parent = ((DTreeNode <T>)value).Parent;

            if (parent != null && parent != mOwner)
            {
                throw new ArgumentException("Cannot add a node referenced in another node collection");
            }
        }
Beispiel #11
0
        public bool IsAncestorOf(DTreeNode <T> node)
        {
            if (node.Root != Root)
            {
                return(false);                // different trees
            }
            DTreeNode <T> parent = node.Parent;

            while (parent != null && parent != this)
            {
                parent = parent.Parent;
            }
            return(parent != null);
        }
Beispiel #12
0
        public IList <T> GetElementPath()
        {
            List <T>      list = new List <T>();
            DTreeNode <T> node = mParent;

            while (node != null)
            {
                list.Add(node.Value);
                node = node.Parent;
            }
            list.Reverse();
            list.Add(this.mValue);

            return(list);
        }
Beispiel #13
0
        public System.Collections.IList GetNodePath()
        {
            List <DTreeNode <T> > list = new List <DTreeNode <T> >();
            DTreeNode <T>         node = mParent;

            while (node != null)
            {
                list.Add(node);
                node = node.Parent;
            }
            list.Reverse();
            list.Add(this);

            return(list);
        }
Beispiel #14
0
        public string GetNodePathAsString(char separator, NodeToString <T> toString)
        {
            string        s    = "";
            DTreeNode <T> node = this;

            while (node != null)
            {
                if (s.Length != 0)
                {
                    s = toString(node) + separator + s;
                }
                else
                {
                    s = toString(node);
                }
                node = node.Parent;
            }

            return(s);
        }
Beispiel #15
0
        public int[] GetIndexPathTo(DTreeNode <T> node)
        {
            if (Root != node.Root)
            {
                throw new ArgumentException("parameter node must belong to the same tree");
            }
            List <int> index = new List <int>();

            while (node != this && node.mParent != null)
            {
                index.Add(node.mParent.Nodes.IndexOf(node));
                node = node.mParent;
            }

            if (node != this)
            {
                throw new ArgumentException("node is not a child of this");
            }

            index.Reverse();
            return(index.ToArray());
        }
Beispiel #16
0
        /// <summary>
        /// Adds a new node with the given value at the specified index.
        /// </summary>
        /// <param name="index">Position where to insert the item.
        /// All values are accepted, if index is out of range, the new item is inserted as first or
        /// last item</param>
        /// <param name="value">value for the new node</param>
        /// <returns></returns>
        public DTreeNode <T> InsertAt(int index, T value)
        {
            DTreeNode <T> n = new DTreeNode <T>(value, mOwner);

            // "tolerant insert"
            if (index < 0)
            {
                index = 0;
            }

            if (index >= Count)
            {
                index = Count;
                List.Add(n);
            }
            else
            {
                List.Insert(index, n);
            }

            SendOwnerNodeChanged(ENodeEvent.ChildAdded, index);

            return(n);
        }
Beispiel #17
0
 internal DTreeRoot(DTreeNode <T> root)
 {
     mRoot = root;
 }
Beispiel #18
0
 // required for XML Serializer, not to bad to have...
 public void Add(DTreeNode <T> node)
 {
     List.Add(node);
     SendOwnerNodeChanged(ENodeEvent.ChildAdded, List.Count - 1);
 }
Beispiel #19
0
 public bool IsChildOf(DTreeNode <T> node)
 {
     return(!IsAncestorOf(node));
 }
Beispiel #20
0
 public bool Contains(DTreeNode <T> node)
 {
     return(List.Contains(node));
 }
Beispiel #21
0
 public void Insert(int index, DTreeNode <T> node)
 {
     List.Insert(index, node);
 }
Beispiel #22
0
 public int IndexOf(DTreeNode <T> node)
 {
     return(List.IndexOf(node));
 }
Beispiel #23
0
        /// <summary>
        /// Inserts a new node before the specified node.
        /// </summary>
        /// <param name="insertPos">Existing node in front of which the new node is inserted</param>
        /// <param name="value">value for the new node</param>
        /// <returns>The newly created node</returns>
        public DTreeNode <T> InsertBefore(DTreeNode <T> insertPos, T value)
        {
            int index = IndexOf(insertPos);

            return(InsertAt(index, value));
        }
Beispiel #24
0
 public bool IsInLineWith(DTreeNode <T> node)
 {
     return(node == this ||
            node.IsAncestorOf(this) ||
            node.IsChildOf(node));
 }
Beispiel #25
0
        public DTreeNode <T> GetNodeAt(IEnumerable <int> index)
        {
            DTreeNode <T> node = this;

            return(index.Aggregate(node, (current, elementIndex) => current.Nodes[elementIndex]));
        }
Beispiel #26
0
 /// <summary>
 /// Creates a new node as child of parent, and sets Value to value
 /// </summary>
 /// <param name="value"></param>
 /// <param name="parent"></param>
 internal DTreeNode(T value, DTreeNode <T> parent)
 {
     mValue = value;
     InternalSetParent(parent);
 }
Beispiel #27
0
 public DTreeBuilder <T> Up()
 {
     current = current.Parent;
     return(this);
 }
Beispiel #28
0
 public DTreeEventArgs(DTreeNode <T> node, ENodeEvent change, int index)
 {
     Node   = node;
     Change = change;
     Index  = index;
 }
Beispiel #29
0
 internal void InternalDetach()
 {
     mParent = null;
     SetRootLink(new DTreeRoot <T>(this));
 }
Beispiel #30
0
 public DTreeBuilder <T> Root()
 {
     current = root;
     return(this);
 }