internal void SendValueChanged(DTreeNode <T> node) { if (OnValueChanged != null) { OnValueChanged(this, new DTreeEventArgs <T>(node, ENodeEvent.ValueChanged, -1)); } }
public DTreeNode <T> ToTree() { DTreeNode <T> ret = root; Reset(); return(ret); }
internal void SendNodeChanged(DTreeNode <T> node, ENodeEvent change, int index) { if (OnNodeChanged != null) { OnNodeChanged(this, new DTreeEventArgs <T>(node, change, index)); } }
internal DTreeNodeCollection(DTreeNode <T> owner) { if (owner == null) { throw new ArgumentNullException("owner"); } mOwner = owner; }
internal void InternalSetParent(DTreeNode <T> parent) { mParent = parent; if (mParent != null) { SetRootLink(parent.Root); } }
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); }
public DTreeNode <T> GetNodeAt(IEnumerable <int> index) { DTreeNode <T> node = this; foreach (int elementIndex in index) { node = node.Nodes[elementIndex]; } return(node); }
/// <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); }
/// <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)); }
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"); } }
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); }
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); }
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); }
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); }
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()); }
/// <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); }
internal DTreeRoot(DTreeNode <T> root) { mRoot = root; }
// required for XML Serializer, not to bad to have... public void Add(DTreeNode <T> node) { List.Add(node); SendOwnerNodeChanged(ENodeEvent.ChildAdded, List.Count - 1); }
public bool IsChildOf(DTreeNode <T> node) { return(!IsAncestorOf(node)); }
public bool Contains(DTreeNode <T> node) { return(List.Contains(node)); }
public void Insert(int index, DTreeNode <T> node) { List.Insert(index, node); }
public int IndexOf(DTreeNode <T> node) { return(List.IndexOf(node)); }
/// <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)); }
public bool IsInLineWith(DTreeNode <T> node) { return(node == this || node.IsAncestorOf(this) || node.IsChildOf(node)); }
public DTreeNode <T> GetNodeAt(IEnumerable <int> index) { DTreeNode <T> node = this; return(index.Aggregate(node, (current, elementIndex) => current.Nodes[elementIndex])); }
/// <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); }
public DTreeBuilder <T> Up() { current = current.Parent; return(this); }
public DTreeEventArgs(DTreeNode <T> node, ENodeEvent change, int index) { Node = node; Change = change; Index = index; }
internal void InternalDetach() { mParent = null; SetRootLink(new DTreeRoot <T>(this)); }
public DTreeBuilder <T> Root() { current = root; return(this); }