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:
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionDefaultTreeNode(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, Collection<? extends TreeNode<E>> children) Creates a branch (non-leaf) node.DefaultTreeNode(E data, 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
Modifier and TypeMethodDescriptionvoidAdds a child to this node at the end.clone()Clones the tree node.intcompareTo(DefaultTreeNode<E> node) getChildAt(int childIndex) Returns the childTreeNodeat indexchildIndex.intReturns the number of childrenTreeNodes this node contains.Return children of the receivergetData()Returns the application-specific data of this node.intReturns the index ofnodein this node's children.getModel()Returns the tree model it belongs to.Returns the parentTreeNodeof this node.voidAdds 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.voidRemoves the child from this node.voidRemoves the receiver from its parent.voidSets 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.toString()
-
Constructor Details
-
DefaultTreeNode
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
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
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
Creates a leaf node, i.e., it won't allow any children. -
DefaultTreeNode
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
Description copied from interface:TreeNodeReturns the tree model it belongs to. -
setModel
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
Description copied from interface:TreeNodeReturns the application-specific data of this node. -
setData
Description copied from interface:TreeNodeSets the application-specific data associated with this node. -
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
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
Description copied from interface:TreeNodeReturns the parentTreeNodeof this node. -
setParent
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
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
Description copied from interface:TreeNodeAdds child to this node at the given index. -
add
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
Description copied from interface:TreeNodeRemoves the child from this node. -
compareTo
- Specified by:
compareToin interfaceComparable<E>
-
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
-