org.zkoss.zul
Class DefaultTreeNode<E>

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

public class DefaultTreeNode<E>
extends java.lang.Object
implements TreeNode<E>, java.lang.Comparable<DefaultTreeNode<E>>, java.lang.Cloneable, java.io.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:
Serialized Form

Nested Class Summary
protected  class DefaultTreeNode.TreeNodeChildrenList
           
 
Constructor Summary
DefaultTreeNode(E data)
          Creates a leaf node, i.e., it won't allow any children.
DefaultTreeNode(E data, boolean nullAsMax)
          Creates a leaf node, i.e., it won't allow any children.
DefaultTreeNode(E data, java.util.Collection<? extends TreeNode<E>> children)
          Creates a branch (non-leaf) node.
DefaultTreeNode(E data, java.util.Collection<? extends TreeNode<E>> children, boolean nullAsMax)
          Creates a branch (non-leaf) node.
DefaultTreeNode(E data, TreeNode<E>[] children)
          Creates a branch (non-leaf) node.
 
Method Summary
 void add(TreeNode<E> child)
          Adds a child to this node at the end.
 java.lang.Object clone()
          Clones the tree node.
 int compareTo(DefaultTreeNode<E> node)
           
 TreeNode<E> getChildAt(int childIndex)
          Returns the child TreeNode at index childIndex.
 int getChildCount()
          Returns the number of children TreeNodes this node contains.
 java.util.List<? extends 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 removeFromParent()
          Removes the receiver from its parent.
 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.
protected  void setParent(DefaultTreeNode<E> parent)
          Sets the parent.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultTreeNode

public DefaultTreeNode(E data,
                       java.util.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,
                       java.util.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 Detail

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 java.util.List<? extends 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, int), add(org.zkoss.zul.TreeNode) 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 java.lang.Comparable<DefaultTreeNode<E>>

clone

public java.lang.Object clone()
Description copied from interface: TreeNode
Clones the tree node.

Notes:

Specified by:
clone in interface TreeNode<E>
Overrides:
clone in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2005-2011 Potix Corporation. All Rights Reserved. SourceForge.net Logo