Package org.zkoss.zul
Class DefaultTreeNode<E>
- java.lang.Object
-
- 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
Nested Classes Modifier and Type Class Description protected class
DefaultTreeNode.TreeNodeChildrenList
-
Constructor Summary
Constructors Constructor Description 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
All Methods Instance Methods Concrete 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.int
compareTo(DefaultTreeNode<E> node)
TreeNode<E>
getChildAt(int childIndex)
Returns the childTreeNode
at indexchildIndex
.int
getChildCount()
Returns the number of childrenTreeNode
s this node contains.java.util.List<TreeNode<E>>
getChildren()
Return children of the receiverE
getData()
Returns the application-specific data of this node.int
getIndex(TreeNode<E> node)
Returns the index ofnode
in this node's children.DefaultTreeModel<E>
getModel()
Returns the tree model it belongs to.TreeNode<E>
getParent()
Returns the parentTreeNode
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()
-
-
-
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 beDefaultTreeNode
too). If null or empty, it means no children at all. However, it still allows to add children. If it is not allowed, please useDefaultTreeNode(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 beDefaultTreeNode
too). If null or empty, it means no children at all. However, it still allows to add children. If it is not allowed, please useDefaultTreeNode(Object)
instead.
-
DefaultTreeNode
public DefaultTreeNode(E data, TreeNode<E>[] children)
Creates a branch (non-leaf) node.- Parameters:
children
- a collection of children (they must beDefaultTreeNode
too). If null or empty, it means no children at all. However, it still allows to add children. If it is not allowed, please useDefaultTreeNode(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.
-
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.
-
getData
public E getData()
Description copied from interface:TreeNode
Returns the application-specific data of this node.
-
setData
public void setData(E data)
Description copied from interface:TreeNode
Sets the application-specific data associated with this node.
-
getChildren
public java.util.List<TreeNode<E>> getChildren()
Description copied from interface:TreeNode
Return children of the receiver- Specified by:
getChildren
in interfaceTreeNode<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 childTreeNode
at indexchildIndex
.- Specified by:
getChildAt
in interfaceTreeNode<E>
-
getChildCount
public int getChildCount()
Description copied from interface:TreeNode
Returns the number of childrenTreeNode
s this node contains.- Specified by:
getChildCount
in interfaceTreeNode<E>
-
getParent
public TreeNode<E> getParent()
Description copied from interface:TreeNode
Returns the parentTreeNode
of this node.
-
setParent
protected void setParent(DefaultTreeNode<E> parent)
Sets the parent. It is called automatically wheninsert(org.zkoss.zul.TreeNode<E>, int)
,add(org.zkoss.zul.TreeNode<E>)
orremove(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 ofnode
in this node's children. If this node does not containnode
, -1 will be returned.
-
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.
-
insert
public void insert(TreeNode<E> child, int index)
Description copied from interface:TreeNode
Adds child to this node at the given index.
-
add
public void add(TreeNode<E> child)
Description copied from interface:TreeNode
Adds a child to this node at the end.
-
remove
public void remove(int index)
Description copied from interface:TreeNode
Removes the child at index from this node.
-
remove
public void remove(TreeNode<E> child)
Description copied from interface:TreeNode
Removes the child from this node.
-
compareTo
public int compareTo(DefaultTreeNode<E> node)
- Specified by:
compareTo
in interfacejava.lang.Comparable<E>
-
clone
public java.lang.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.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-