Exemplo n.º 1
0
        public void InsertChildBefore <T>(JsNode nextSibling, T child, JsTreeRole <T> role) where T : JsNode
        {
            if (role == null)
            {
                throw new ArgumentNullException("role");
            }
            if (nextSibling == null)
            {
                AddChild(child, role);
                return;
            }

            if (child == null)
            {
                return;
            }
            ThrowIfFrozen();
            if (child.parent != null)
            {
                throw new ArgumentException("Node is already used in another tree.", "child");
            }
            if (child.IsFrozen)
            {
                throw new ArgumentException("Cannot add a frozen node.", "child");
            }
            if (nextSibling.parent != this)
            {
                throw new ArgumentException("NextSibling is not a child of this node.", "nextSibling");
            }
            // No need to test for "Cannot add children to null nodes",
            // as there isn't any valid nextSibling in null nodes.
            InsertChildBeforeUnsafe(nextSibling, child, role);
        }
Exemplo n.º 2
0
 public void AddChild <T>(T child, JsTreeRole <T> role) where T : JsNode
 {
     if (role == null)
     {
         throw new ArgumentNullException("role");
     }
     if (child == null)
     {
         return;
     }
     ThrowIfFrozen();
     if (child == this)
     {
         throw new ArgumentException("Cannot add a node to itself as a child.", "child");
     }
     if (child.parent != null)
     {
         throw new ArgumentException("Node is already used in another tree.", "child");
     }
     if (child.IsFrozen)
     {
         throw new ArgumentException("Cannot add a frozen node.", "child");
     }
     AddChildUnsafe(child, role);
 }
Exemplo n.º 3
0
 protected void SetChildByRole <T>(JsTreeRole <T> role, T newChild) where T : JsNode
 {
     if (GetChildByRole(role) is T oldChild)
     {
         oldChild.ReplaceWith(newChild);
     }
     else
     {
         AddChild(newChild, role);
     }
 }
Exemplo n.º 4
0
 public JsNodeCollection(JsNode node, JsTreeRole <T> role)
 {
     if (node == null)
     {
         throw new ArgumentNullException("node");
     }
     if (role == null)
     {
         throw new ArgumentNullException("role");
     }
     this.node = node;
     this.role = role;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Adds a child without performing any safety checks.
 /// </summary>
 internal void AddChildUnsafe(JsNode child, JsTreeRole role)
 {
     child.parent = this;
     child.role   = role;
     if (firstChild == null)
     {
         lastChild = firstChild = child;
     }
     else
     {
         lastChild.nextSibling = child;
         child.prevSibling     = lastChild;
         lastChild             = child;
     }
 }
Exemplo n.º 6
0
 /// <summary>
 /// Gets the first child with the specified role.
 /// Returns the role's null object if the child is not found.
 /// </summary>
 public T GetChildByRole <T>(JsTreeRole <T> role) where T : JsNode
 {
     if (role == null)
     {
         throw new ArgumentNullException("role");
     }
     for (var cur = firstChild; cur != null; cur = cur.nextSibling)
     {
         if (cur.role == role)
         {
             return((T)cur);
         }
     }
     return(null);
 }
Exemplo n.º 7
0
        internal void InsertChildBeforeUnsafe(JsNode nextSibling, JsNode child, JsTreeRole role)
        {
            child.parent      = this;
            child.role        = role;
            child.nextSibling = nextSibling;
            child.prevSibling = nextSibling.prevSibling;

            if (nextSibling.prevSibling != null)
            {
                Debug.Assert(nextSibling.prevSibling.nextSibling == nextSibling);
                nextSibling.prevSibling.nextSibling = child;
            }
            else
            {
                Debug.Assert(firstChild == nextSibling);
                firstChild = child;
            }
            nextSibling.prevSibling = child;
        }
Exemplo n.º 8
0
 public void InsertChildAfter <T>(JsNode prevSibling, T child, JsTreeRole <T> role) where T : JsNode
 {
     InsertChildBefore(prevSibling == null ? firstChild : prevSibling.nextSibling, child, role);
 }
Exemplo n.º 9
0
 public JsNodeCollection <T> GetChildrenByRole <T>(JsTreeRole <T> role) where T : JsNode
 {
     return(new JsNodeCollection <T>(this, role));
 }