Package org.zkoss.zul

## Interface TreeNode<E>

- All Known Implementing Classes:
    `DefaultTreeNode`

      public interface TreeNode<E>

  Defines the requirements for a tree node object that can change -- by adding or removing child nodes, or by changing the contents of an application-specific data (`setData(E)`) stored in the node. It is designed to be used with `DefaultTreeModel`.
  Since:
    5.0.6
  Author:
    tomyeh

- - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `add​(TreeNode<E> child)` | Adds a child to this node at the end.
    `java.lang.Object` | `clone()` | Clones the tree node.
    `TreeNode<E>` | `getChildAt​(int childIndex)` | Returns the child `TreeNode` at index `childIndex`.
    `int` | `getChildCount()` | Returns the number of children `TreeNode`s this node contains.
    `java.util.List<TreeNode<E>>` | `getChildren()` | Return children of the receiver
    `E` | `getData()` | Returns the application-specific data of this node.
    `int` | `getIndex​(TreeNode<E> node)` | Returns the index of `node` in this node's children.
    `DefaultTreeModel<E>` | `getModel()` | Returns the tree model it belongs to.
    `TreeNode<E>` | `getParent()` | Returns the parent `TreeNode` of this node.
    `void` | `insert​(TreeNode<E> child, int index)` | Adds child to this node at the given index.
    `boolean` | `isLeaf()` | Returns true if this node is a leaf.
    `void` | `remove​(int index)` | Removes the child at index from this node.
    `void` | `remove​(TreeNode<E> child)` | Removes the child from this node.
    `void` | `setData​(E data)` | Sets the application-specific data associated with this node.
    `void` | `setModel​(DefaultTreeModel<E> model)` | Sets the tree model it belongs to.

- - ### Method Detail

    - #### getModel

          DefaultTreeModel<E> getModel()

      Returns the tree model it belongs to.

    - #### setModel

          void setModel​(DefaultTreeModel<E> model)

      Sets the tree model it belongs to. It can be called only if this node is a root. If a node has a parent, its model shall be the same as its parent.

      This method is invoked automatically if `DefaultTreeModel`, so you don't have to invoke it.

      Throws:
        `java.lang.IllegalArgumentException` - if the model is null.
        `java.lang.IllegalStateException` - if the node is not a root.

    - #### getData

          E getData()

      Returns the application-specific data of this node.

    - #### setData

          void setData​(E data)

      Sets the application-specific data associated with this node.

    - #### getChildren

          java.util.List<TreeNode<E>> getChildren()

      Return children of the receiver
      Returns:
        children of the receiver. If the node is a leaf, null is returned.

    - #### getChildAt

          TreeNode<E> getChildAt​(int childIndex)

      Returns the child `TreeNode` at index `childIndex`.

    - #### getChildCount

          int getChildCount()

      Returns the number of children `TreeNode`s this node contains.

    - #### getParent

          TreeNode<E> getParent()

      Returns the parent `TreeNode` of this node.

    - #### getIndex

          int getIndex​(TreeNode<E> node)

      Returns the index of `node` in this node's children. If this node does not contain `node`, -1 will be returned.

    - #### isLeaf

          boolean isLeaf()

      Returns true if this node is a leaf. Notice that not all non-leaf nodes have children. In file-system terminology, a leaf node is a file, while a non-leaf node is a folder.

    - #### insert

          void insert​(TreeNode<E> child,
                      int index)

      Adds child to this node at the given index.
      Throws:
        `java.lang.UnsupportedOperationException` - if the tree structure is not mutable, or this node does not allow children
        `java.lang.IndexOutOfBoundsException` - if `index` is out of bounds
        `java.lang.IllegalArgumentException` - if `child` is an ancestor of this node
        `java.lang.NullPointerException` - if `child` is null

    - #### add

          void add​(TreeNode<E> child)

      Adds a child to this node at the end.
      Throws:
        `java.lang.UnsupportedOperationException` - if the tree structure is not mutable, or this node does not allow children
        `java.lang.IllegalArgumentException` - if `child` is an ancestor of this node
        `java.lang.NullPointerException` - if `child` is null

    - #### remove

          void remove​(int index)

      Removes the child at index from this node.
      Throws:
        `java.lang.UnsupportedOperationException` - if the tree structure is not mutable, or this node does not allow children
        `java.lang.IndexOutOfBoundsException` - if `index` is out of bounds

    - #### remove

          void remove​(TreeNode<E> child)

      Removes the child from this node.
      Throws:
        `java.lang.UnsupportedOperationException` - if the tree structure is not mutable or this node does not allow children
        `java.lang.IllegalArgumentException` - if `child` is not a child of this node

    - #### clone

          java.lang.Object clone()

      Clones the tree node.

      Notes:

      - It is a deep clone, i.e., all descendant are cloned.
      - If the implementation supports this method, it shall implement the Cloneable interface too.
      - If not supported, the implementation shall throw CloneNotSupportedException.