public class DefaultTreeModel<E> extends AbstractTreeModel<TreeNode<E>> implements Sortable<TreeNode<E>>, java.io.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, _selection
INTERNAL_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(java.lang.Object obj)
Deprecated.
As of release 6.0.0, replaced with
AbstractTreeModel.addToSelection(E) . |
java.lang.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.
|
java.lang.String |
getSortDirection(java.util.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(java.lang.Object child)
Returns whether the specified object be opened.
|
boolean |
isOpen(java.lang.Object child)
Deprecated.
As of release 6.0.0, replaced with
isObjectOpened(java.lang.Object) . |
boolean |
isSelected(java.lang.Object child)
Returns whether an object is selected.
|
boolean |
removeFromSelection(java.lang.Object child)
Remove the specified object from selection.
|
boolean |
removeOpenObject(java.lang.Object child)
Remove the specified object from selection.
|
void |
removeSelection(java.lang.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(java.util.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, setSelectionControl
public DefaultTreeModel(TreeNode<E> root)
root
- the root (cannot be null).public boolean isLeaf(TreeNode<E> node)
TreeModel
public TreeNode<E> getChild(TreeNode<E> parent, int index)
TreeModel
public int getChildCount(TreeNode<E> parent)
TreeModel
getChildCount
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(java.lang.Object child)
Selectable
isSelected
in interface Selectable<TreeNode<E>>
isSelected
in class AbstractTreeModel<TreeNode<E>>
public boolean removeFromSelection(java.lang.Object child)
Selectable
If 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(java.lang.Object child)
Openable
isObjectOpened
in interface Openable<TreeNode<E>>
isObjectOpened
in class AbstractTreeModel<TreeNode<E>>
public boolean removeOpenObject(java.lang.Object child)
Openable
removeOpenObject
in interface Openable<TreeNode<E>>
removeOpenObject
in class AbstractTreeModel<TreeNode<E>>
child
- the object to be remove from selection.public void sort(java.util.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(java.lang.Object obj)
AbstractTreeModel.addToSelection(E)
.public void removeSelection(java.lang.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(java.lang.Object child)
isObjectOpened(java.lang.Object)
.public java.lang.String getSortDirection(java.util.Comparator<TreeNode<E>> cmpr)
Sortable
Default: "natural".
getSortDirection
in interface Sortable<TreeNode<E>>
public java.lang.Object clone()
clone
in class AbstractTreeModel<TreeNode<E>>
Copyright © 2005-2011 Potix Corporation. All Rights Reserved.