Class DefaultTreeModel<E>
- java.lang.Object
-
- org.zkoss.zul.AbstractTreeModel<TreeNode<E>>
-
- org.zkoss.zul.DefaultTreeModel<E>
-
- All Implemented Interfaces:
java.io.Serializable,Openable<TreeNode<E>>,Pageable,Selectable<TreeNode<E>>,Sortable<TreeNode<E>>,TreeOpenableModel,TreeSelectableModel,PageableModel,TreeModel<TreeNode<E>>
public class DefaultTreeModel<E> extends AbstractTreeModel<TreeNode<E>> implements Sortable<TreeNode<E>>, java.io.Serializable
A simple tree data model that usesTreeNodeto represent a tree. Thus the whole tree of data must be loaded into memory, and each node must be represented byTreeNode.If you want to implement a huge tree that only a visible part shall be loaded, it is better to implement it by extending from
AbstractTreeModel.DefaultTreeModeldepends onTreeNodeonly. It does not depend onDefaultTreeNode. However,DefaultTreeNodedepends onDefaultTreeModel.For introduction, please refer to ZK Developer's Reference: Tree Model.
- Since:
- 5.0.6
- Author:
- tomyeh, jumperchen
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.zkoss.zul.AbstractTreeModel
AbstractTreeModel.DefaultSelectionControl<E>, AbstractTreeModel.Path
-
-
Field Summary
-
Fields inherited from class org.zkoss.zul.AbstractTreeModel
_opens, _selection
-
Fields inherited from interface org.zkoss.zul.PageableModel
INTERNAL_EVENT
-
-
Constructor Summary
Constructors Constructor Description DefaultTreeModel(TreeNode<E> root)Creates a tree with the specified note as the root.DefaultTreeModel(TreeNode<E> root, boolean emptyChildAsLeaf)Creates a tree with the specified note as the root.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Objectclone()TreeNode<E>getChild(TreeNode<E> parent, int index)Returns the child of the given parent at the given index where the index indicates in the parent's child array.intgetChildCount(TreeNode<E> parent)Returns the number of children of the given parent.intgetIndexOfChild(TreeNode<E> parent, TreeNode<E> child)Returns the index of child in parent.int[]getPath(TreeNode<E> child)Returns the path from the child, where the path indicates the child is placed in the whole tree.java.lang.StringgetSortDirection(java.util.Comparator<TreeNode<E>> cmpr)Returns the sort direction of this model for the given comparator.booleanisLeaf(TreeNode<E> node)Returns true if node is a leaf.booleanisObjectOpened(java.lang.Object child)Returns whether the specified object be opened.booleanisSelected(java.lang.Object child)Returns whether an object is selected.booleanremoveFromSelection(java.lang.Object child)Remove the specified object from selection.booleanremoveOpenObject(java.lang.Object child)Remove the specified object from selection.voidsort()Sort the data model by default or assigned comparator.voidsort(java.util.Comparator<TreeNode<E>> cmpr, boolean ascending)Sorts the data.-
Methods inherited from class org.zkoss.zul.AbstractTreeModel
addOpenObject, addOpenPath, addOpenPaths, addPagingEventListener, addSelectionPath, addSelectionPaths, addToSelection, addTreeDataListener, afterSort, beforeSort, clearOpen, clearSelection, fireEvent, fireEvent, fireEvent, fireOpenChanged, fireSelectionChanged, getActivePage, getChild, getOpenCount, getOpenObjects, getOpenPath, getOpenPaths, getPageCount, getPageSize, getRoot, getSelection, getSelectionControl, getSelectionCount, getSelectionPath, getSelectionPaths, getTotalSize, getTreeDataListeners, isMultiple, isOpenEmpty, isPathOpened, isPathSelected, isSelectionEmpty, removeOpenPath, removeOpenPaths, removePagingEventListener, removeSelectionPath, removeSelectionPaths, removeTreeDataListener, setActivePage, setMultiple, setOpenObjects, setPageSize, setSelection, setSelectionControl
-
-
-
-
Method Detail
-
isLeaf
public boolean isLeaf(TreeNode<E> node)
Description copied from interface:TreeModelReturns true if 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.
-
getChild
public TreeNode<E> getChild(TreeNode<E> parent, int index)
Description copied from interface:TreeModelReturns the child of the given parent at the given index where the index indicates in the parent's child array.
-
getChildCount
public int getChildCount(TreeNode<E> parent)
Description copied from interface:TreeModelReturns the number of children of the given parent.- Specified by:
getChildCountin interfaceTreeModel<E>- Parameters:
parent- a node in the tree, obtained from this data source- Returns:
- the number of children of the node parent
-
getIndexOfChild
public int getIndexOfChild(TreeNode<E> parent, TreeNode<E> child)
Description copied from class:AbstractTreeModelReturns the index of child in parent. If either parent or child is null, returns -1. If either parent or child don't belong to this tree model, returns -1.The default implementation iterates through all children of
parentby invoking, and check ifchildis part of them. You could override it if you have a better algorithm.AbstractTreeModel.getChild(int[])- Specified by:
getIndexOfChildin interfaceTreeModel<E>- Overrides:
getIndexOfChildin classAbstractTreeModel<TreeNode<E>>- Parameters:
parent- a node in the tree, obtained from this data sourcechild- the node we are interested in- Returns:
- the index of the child in the parent, or -1 if either child or parent are null or don't belong to this tree model
-
getPath
public int[] getPath(TreeNode<E> child)
Returns the path from the child, where the path indicates the child is placed in the whole tree.
-
isSelected
public boolean isSelected(java.lang.Object child)
Description copied from interface:SelectableReturns whether an object is selected.- Specified by:
isSelectedin interfaceSelectable<E>- Overrides:
isSelectedin classAbstractTreeModel<TreeNode<E>>
-
removeFromSelection
public boolean removeFromSelection(java.lang.Object child)
Description copied from interface:SelectableRemove the specified object from selection.If this represents a change to the current selection then notify each ListDataListener, including UI.
- Specified by:
removeFromSelectionin interfaceSelectable<E>- Overrides:
removeFromSelectionin classAbstractTreeModel<TreeNode<E>>- Parameters:
child- the object to be remove from selection.- Returns:
- whether it is removed successfully
-
isObjectOpened
public boolean isObjectOpened(java.lang.Object child)
Description copied from interface:OpenableReturns whether the specified object be opened.- Specified by:
isObjectOpenedin interfaceOpenable<E>- Overrides:
isObjectOpenedin classAbstractTreeModel<TreeNode<E>>
-
removeOpenObject
public boolean removeOpenObject(java.lang.Object child)
Description copied from interface:OpenableRemove the specified object from selection.- Specified by:
removeOpenObjectin interfaceOpenable<E>- Overrides:
removeOpenObjectin classAbstractTreeModel<TreeNode<E>>- Parameters:
child- the object to be remove from selection.- Returns:
- whether it is removed successfully
-
sort
public void sort(java.util.Comparator<TreeNode<E>> cmpr, boolean ascending)
Sorts the data.Notice: it invokes
AbstractTreeModel.beforeSort()andAbstractTreeModel.afterSort(java.lang.Object)to save and restore the selection and open states. If you prefer not to preserve objects and prefer to save the paths, you can overrideAbstractTreeModel.beforeSort()to do nothing but returning null. If you prefer to clear the selection, you can overrideAbstractTreeModel.beforeSort()to clearAbstractTreeModel._selectionand return null.
-
sort
public void sort()
Description copied from interface:SortableSort the data model by default or assigned comparator. Notice that the default implementation does nothing, the model which implements Sortable need to implement this method.- Specified by:
sortin interfaceSortable<E>- See Also:
Sortable.sort(Comparator, boolean)
-
getSortDirection
public java.lang.String getSortDirection(java.util.Comparator<TreeNode<E>> cmpr)
Description copied from interface:SortableReturns the sort direction of this model for the given comparator. It must be one of "ascending", "descending" and "natural".Default: "natural".
- Specified by:
getSortDirectionin interfaceSortable<E>
-
clone
public java.lang.Object clone()
- Overrides:
clonein classAbstractTreeModel<TreeNode<E>>
-
-