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

            Reset();
            return(ret);
        }
コード例 #3
0
 internal void SendNodeChanged(DTreeNode <T> node, ENodeEvent change, int index)
 {
     if (OnNodeChanged != null)
     {
         OnNodeChanged(this, new DTreeEventArgs <T>(node, change, index));
     }
 }
コード例 #4
0
 internal DTreeNodeCollection(DTreeNode <T> owner)
 {
     if (owner == null)
     {
         throw new ArgumentNullException("owner");
     }
     mOwner = owner;
 }
コード例 #5
0
 internal void InternalSetParent(DTreeNode <T> parent)
 {
     mParent = parent;
     if (mParent != null)
     {
         SetRootLink(parent.Root);
     }
 }
コード例 #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);
        }
コード例 #7
0
        public DTreeNode <T> GetNodeAt(IEnumerable <int> index)
        {
            DTreeNode <T> node = this;

            foreach (int elementIndex in index)
            {
                node = node.Nodes[elementIndex];
            }
            return(node);
        }
コード例 #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);
        }
コード例 #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));
        }
コード例 #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");
            }
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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());
        }
コード例 #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);
        }
コード例 #17
0
 internal DTreeRoot(DTreeNode <T> root)
 {
     mRoot = root;
 }
コード例 #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);
 }
コード例 #19
0
 public bool IsChildOf(DTreeNode <T> node)
 {
     return(!IsAncestorOf(node));
 }
コード例 #20
0
 public bool Contains(DTreeNode <T> node)
 {
     return(List.Contains(node));
 }
コード例 #21
0
 public void Insert(int index, DTreeNode <T> node)
 {
     List.Insert(index, node);
 }
コード例 #22
0
 public int IndexOf(DTreeNode <T> node)
 {
     return(List.IndexOf(node));
 }
コード例 #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));
        }
コード例 #24
0
 public bool IsInLineWith(DTreeNode <T> node)
 {
     return(node == this ||
            node.IsAncestorOf(this) ||
            node.IsChildOf(node));
 }
コード例 #25
0
ファイル: Tree.cs プロジェクト: Rajeshbharathi/CGN.Paralegal
        public DTreeNode <T> GetNodeAt(IEnumerable <int> index)
        {
            DTreeNode <T> node = this;

            return(index.Aggregate(node, (current, elementIndex) => current.Nodes[elementIndex]));
        }
コード例 #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);
 }
コード例 #27
0
 public DTreeBuilder <T> Up()
 {
     current = current.Parent;
     return(this);
 }
コード例 #28
0
 public DTreeEventArgs(DTreeNode <T> node, ENodeEvent change, int index)
 {
     Node   = node;
     Change = change;
     Index  = index;
 }
コード例 #29
0
 internal void InternalDetach()
 {
     mParent = null;
     SetRootLink(new DTreeRoot <T>(this));
 }
コード例 #30
0
 public DTreeBuilder <T> Root()
 {
     current = root;
     return(this);
 }