Package org.zkoss.zul

Class DefaultTreeNode<E>

java.lang.Object
org.zkoss.zul.DefaultTreeNode<E>
All Implemented Interfaces:
Serializable, Cloneable, Comparable<DefaultTreeNode<E>>, TreeNode<E>

public class DefaultTreeNode<E> extends Object implements TreeNode<E>, Comparable<DefaultTreeNode<E>>, Cloneable, Serializable
A general-purpose node in a tree data structure.

Notice that if a node is added to another (i.e., become a child of another node), it will be removed from the previous parent automatically.

Since:
5.0.6
Author:
tomyeh
See Also:
  • Constructor Details

    • DefaultTreeNode

      public DefaultTreeNode(E data, Collection<? extends TreeNode<E>> children)
      Creates a branch (non-leaf) node.
      Parameters:
      children - a collection of children (they must be DefaultTreeNode too). If null or empty, it means no children at all. However, it still allows to add children. If it is not allowed, please use DefaultTreeNode(Object) instead.
    • DefaultTreeNode

      public DefaultTreeNode(E data, Collection<? extends TreeNode<E>> children, boolean nullAsMax)
      Creates a branch (non-leaf) node.
      Parameters:
      children - a collection of children (they must be DefaultTreeNode too). If null or empty, it means no children at all. However, it still allows to add children. If it is not allowed, please use DefaultTreeNode(Object) instead.
    • DefaultTreeNode

      public DefaultTreeNode(E data, TreeNode<E>[] children)
      Creates a branch (non-leaf) node.
      Parameters:
      children - a collection of children (they must be DefaultTreeNode too). If null or empty, it means no children at all. However, it still allows to add children. If it is not allowed, please use DefaultTreeNode(Object) instead.
    • DefaultTreeNode

      public DefaultTreeNode(E data)
      Creates a leaf node, i.e., it won't allow any children.
    • DefaultTreeNode

      public DefaultTreeNode(E data, boolean nullAsMax)
      Creates a leaf node, i.e., it won't allow any children.
      Parameters:
      nullAsMax - whether to consider null as the maximum value. If false, null is considered as the minimum value.
  • Method Details

    • removeFromParent

      public void removeFromParent()
      Removes the receiver from its parent.
    • getModel

      public DefaultTreeModel<E> getModel()
      Description copied from interface: TreeNode
      Returns the tree model it belongs to.
      Specified by:
      getModel in interface TreeNode<E>
    • setModel

      public void setModel(DefaultTreeModel<E> model)
      Description copied from interface: TreeNode
      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.

      Specified by:
      setModel in interface TreeNode<E>
    • getData

      public E getData()
      Description copied from interface: TreeNode
      Returns the application-specific data of this node.
      Specified by:
      getData in interface TreeNode<E>
    • setData

      public void setData(E data)
      Description copied from interface: TreeNode
      Sets the application-specific data associated with this node.
      Specified by:
      setData in interface TreeNode<E>
    • getChildren

      public List<TreeNode<E>> getChildren()
      Description copied from interface: TreeNode
      Return children of the receiver
      Specified by:
      getChildren in interface TreeNode<E>
      Returns:
      children of the receiver. If the node is a leaf, null is returned.
    • getChildAt

      public TreeNode<E> getChildAt(int childIndex)
      Description copied from interface: TreeNode
      Returns the child TreeNode at index childIndex.
      Specified by:
      getChildAt in interface TreeNode<E>
    • getChildCount

      public int getChildCount()
      Description copied from interface: TreeNode
      Returns the number of children TreeNodes this node contains.
      Specified by:
      getChildCount in interface TreeNode<E>
    • getParent

      public TreeNode<E> getParent()
      Description copied from interface: TreeNode
      Returns the parent TreeNode of this node.
      Specified by:
      getParent in interface TreeNode<E>
    • setParent

      protected void setParent(DefaultTreeNode<E> parent)
      Sets the parent. It is called automatically when insert(org.zkoss.zul.TreeNode<E>, int), add(org.zkoss.zul.TreeNode<E>) or remove(int) is called. The deriving class rarely needs to override it.
    • getIndex

      public int getIndex(TreeNode<E> node)
      Description copied from interface: TreeNode
      Returns the index of node in this node's children. If this node does not contain node, -1 will be returned.
      Specified by:
      getIndex in interface TreeNode<E>
    • isLeaf

      public boolean isLeaf()
      Description copied from interface: TreeNode
      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.
      Specified by:
      isLeaf in interface TreeNode<E>
    • insert

      public void insert(TreeNode<E> child, int index)
      Description copied from interface: TreeNode
      Adds child to this node at the given index.
      Specified by:
      insert in interface TreeNode<E>
    • add

      public void add(TreeNode<E> child)
      Description copied from interface: TreeNode
      Adds a child to this node at the end.
      Specified by:
      add in interface TreeNode<E>
    • remove

      public void remove(int index)
      Description copied from interface: TreeNode
      Removes the child at index from this node.
      Specified by:
      remove in interface TreeNode<E>
    • remove

      public void remove(TreeNode<E> child)
      Description copied from interface: TreeNode
      Removes the child from this node.
      Specified by:
      remove in interface TreeNode<E>
    • compareTo

      public int compareTo(DefaultTreeNode<E> node)
      Specified by:
      compareTo in interface Comparable<E>
    • clone

      public Object clone()
      Description copied from interface: TreeNode
      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.
      Specified by:
      clone in interface TreeNode<E>
      Overrides:
      clone in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object