public class DefaultTreeModel<E> extends AbstractTreeModel<TreeNode<E>> implements Sortable<TreeNode<E>>, Serializable
TreeNode to represent a tree.
Thus the whole tree of data must be loaded into memory, and each node
must be represented by TreeNode.
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.
DefaultTreeModel depends on TreeNode only.
It does not depend on DefaultTreeNode. However, DefaultTreeNode
depends on DefaultTreeModel.
For introduction, please refer to ZK Developer's Reference: Tree Model.
AbstractTreeModel.DefaultSelectionControl<E>, AbstractTreeModel.Path_opens, _selectionINTERNAL_EVENT| Constructor and 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.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addSelection(Object obj)
Deprecated.
As of release 6.0.0, replaced with
AbstractTreeModel.addToSelection(E). |
Object |
clone() |
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.
|
int |
getChildCount(TreeNode<E> parent)
Returns the number of children of the given parent.
|
int |
getIndexOfChild(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.
|
String |
getSortDirection(Comparator<TreeNode<E>> cmpr)
Returns the sort direction of this model for the given comparator.
|
boolean |
isLeaf(TreeNode<E> node)
Returns true if node is a leaf.
|
boolean |
isObjectOpened(Object child)
Returns whether the specified object be opened.
|
boolean |
isOpen(Object child)
Deprecated.
As of release 6.0.0, replaced with
isObjectOpened(java.lang.Object). |
boolean |
isSelected(Object child)
Returns whether an object is selected.
|
boolean |
removeFromSelection(Object child)
Remove the specified object from selection.
|
boolean |
removeOpenObject(Object child)
Remove the specified object from selection.
|
void |
removeSelection(Object obj)
Deprecated.
As of release 6.0.0, replaced with
removeFromSelection(java.lang.Object). |
void |
setOpen(TreeNode<E> child,
boolean open)
Deprecated.
As of release 6.0.0, replaced with
AbstractTreeModel.addOpenObject(E)
and removeOpenObject(java.lang.Object). |
void |
sort(Comparator<TreeNode<E>> cmpr,
boolean ascending)
Sorts the data.
|
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, isMultiple, isOpenEmpty, isPathOpened, isPathSelected, isSelectionEmpty, removeOpenPath, removeOpenPaths, removePagingEventListener, removeSelectionPath, removeSelectionPaths, removeTreeDataListener, setActivePage, setMultiple, setOpenObjects, setPageSize, setSelection, setSelectionControlpublic DefaultTreeModel(TreeNode<E> root)
root - the root (cannot be null).public boolean isLeaf(TreeNode<E> node)
TreeModelpublic TreeNode<E> getChild(TreeNode<E> parent, int index)
TreeModelpublic int getChildCount(TreeNode<E> parent)
TreeModelgetChildCount in interface TreeModel<TreeNode<E>>parent - a node in the tree, obtained from this data sourcepublic int getIndexOfChild(TreeNode<E> parent, TreeNode<E> child)
AbstractTreeModel
The default implementation iterates through all children of
parent by invoking, and check if child is part
of them. You could override it if you have a better algorithm.
AbstractTreeModel.getChild(int[])
getIndexOfChild in interface TreeModel<TreeNode<E>>getIndexOfChild in class AbstractTreeModel<TreeNode<E>>parent - a node in the tree, obtained from this data sourcechild - the node we are interested inpublic int[] getPath(TreeNode<E> child)
public boolean isSelected(Object child)
SelectableisSelected in interface Selectable<TreeNode<E>>isSelected in class AbstractTreeModel<TreeNode<E>>public boolean removeFromSelection(Object child)
SelectableIf this represents a change to the current selection then notify each ListDataListener, including UI.
removeFromSelection in interface Selectable<TreeNode<E>>removeFromSelection in class AbstractTreeModel<TreeNode<E>>child - the object to be remove from selection.public boolean isObjectOpened(Object child)
OpenableisObjectOpened in interface Openable<TreeNode<E>>isObjectOpened in class AbstractTreeModel<TreeNode<E>>public boolean removeOpenObject(Object child)
OpenableremoveOpenObject in interface Openable<TreeNode<E>>removeOpenObject in class AbstractTreeModel<TreeNode<E>>child - the object to be remove from selection.public void sort(Comparator<TreeNode<E>> cmpr, boolean ascending)
Notice: it invokes AbstractTreeModel.beforeSort() and AbstractTreeModel.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 override AbstractTreeModel.beforeSort() to do nothing but returning null.
If you prefer to clear the selection, you can override AbstractTreeModel.beforeSort()
to clear AbstractTreeModel._selection and return null.
public void addSelection(Object obj)
AbstractTreeModel.addToSelection(E).public void removeSelection(Object obj)
removeFromSelection(java.lang.Object).public void setOpen(TreeNode<E> child, boolean open)
AbstractTreeModel.addOpenObject(E)
and removeOpenObject(java.lang.Object).public boolean isOpen(Object child)
isObjectOpened(java.lang.Object).public String getSortDirection(Comparator<TreeNode<E>> cmpr)
SortableDefault: "natural".
getSortDirection in interface Sortable<TreeNode<E>>public Object clone()
clone in class AbstractTreeModel<TreeNode<E>>Copyright © 2015. All rights reserved.