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 classDefaultTreeNode.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 voidadd(TreeNode<E> child)Adds a child to this node at the end.java.lang.Objectclone()Clones the tree node.intcompareTo(DefaultTreeNode<E> node)TreeNode<E>getChildAt(int childIndex)Returns the childTreeNodeat indexchildIndex.intgetChildCount()Returns the number of childrenTreeNodes this node contains.java.util.List<TreeNode<E>>getChildren()Return children of the receiverEgetData()Returns the application-specific data of this node.intgetIndex(TreeNode<E> node)Returns the index ofnodein this node's children.DefaultTreeModel<E>getModel()Returns the tree model it belongs to.TreeNode<E>getParent()Returns the parentTreeNodeof this node.voidinsert(TreeNode<E> child, int index)Adds child to this node at the given index.booleanisLeaf()Returns true if this node is a leaf.voidremove(int index)Removes the child at index from this node.voidremove(TreeNode<E> child)Removes the child from this node.voidremoveFromParent()Removes the receiver from its parent.voidsetData(E data)Sets the application-specific data associated with this node.voidsetModel(DefaultTreeModel<E> model)Sets the tree model it belongs to.protected voidsetParent(DefaultTreeNode<E> parent)Sets the parent.java.lang.StringtoString()
-
-
-
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 beDefaultTreeNodetoo). 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 beDefaultTreeNodetoo). 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 beDefaultTreeNodetoo). 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:TreeNodeReturns the tree model it belongs to.
-
setModel
public void setModel(DefaultTreeModel<E> model)
Description copied from interface:TreeNodeSets 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:TreeNodeReturns the application-specific data of this node.
-
setData
public void setData(E data)
Description copied from interface:TreeNodeSets the application-specific data associated with this node.
-
getChildren
public java.util.List<TreeNode<E>> getChildren()
Description copied from interface:TreeNodeReturn children of the receiver- Specified by:
getChildrenin 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:TreeNodeReturns the childTreeNodeat indexchildIndex.- Specified by:
getChildAtin interfaceTreeNode<E>
-
getChildCount
public int getChildCount()
Description copied from interface:TreeNodeReturns the number of childrenTreeNodes this node contains.- Specified by:
getChildCountin interfaceTreeNode<E>
-
getParent
public TreeNode<E> getParent()
Description copied from interface:TreeNodeReturns the parentTreeNodeof 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:TreeNodeReturns the index ofnodein this node's children. If this node does not containnode, -1 will be returned.
-
isLeaf
public boolean isLeaf()
Description copied from interface:TreeNodeReturns 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:TreeNodeAdds child to this node at the given index.
-
add
public void add(TreeNode<E> child)
Description copied from interface:TreeNodeAdds a child to this node at the end.
-
remove
public void remove(int index)
Description copied from interface:TreeNodeRemoves the child at index from this node.
-
remove
public void remove(TreeNode<E> child)
Description copied from interface:TreeNodeRemoves the child from this node.
-
compareTo
public int compareTo(DefaultTreeNode<E> node)
- Specified by:
compareToin interfacejava.lang.Comparable<E>
-
clone
public java.lang.Object clone()
Description copied from interface:TreeNodeClones 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:
toStringin classjava.lang.Object
-
-