|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.zkoss.zul.AbstractTreeModel<TreeNode<E>> org.zkoss.zul.DefaultTreeModel<E>
public class DefaultTreeModel<E>
A simple tree data model that uses 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.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class org.zkoss.zul.AbstractTreeModel |
---|
AbstractTreeModel.Path |
Field Summary |
---|
Fields inherited from class org.zkoss.zul.AbstractTreeModel |
---|
_opens, _selection |
Constructor Summary | |
---|---|
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 | |
---|---|
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. |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public DefaultTreeModel(TreeNode<E> root)
root
- the root (cannot be null).public DefaultTreeModel(TreeNode<E> root, boolean emptyChildAsLeaf)
root
- the root (cannot be null).emptyChildAsLeaf
- whether to treat the zero size of children node as a leaf node.Method Detail |
---|
public boolean isLeaf(TreeNode<E> node)
TreeModel
isLeaf
in interface TreeModel<TreeNode<E>>
node
- a node in the tree, obtained from this data source
public TreeNode<E> getChild(TreeNode<E> parent, int index)
TreeModel
getChild
in interface TreeModel<TreeNode<E>>
parent
- a node in the tree, obtained from this data source
public int getChildCount(TreeNode<E> parent)
TreeModel
getChildCount
in interface TreeModel<TreeNode<E>>
parent
- a node in the tree, obtained from this data source
public 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 in
public int[] getPath(TreeNode<E> child)
getPath
in interface TreeModel<TreeNode<E>>
getPath
in class AbstractTreeModel<TreeNode<E>>
child
- the node we are interested inpublic 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.
sort
in interface Sortable<TreeNode<E>>
cmpr
- the comparator.ascending
- whether to sort in the ascending order.
It is ignored since this implementation uses cmprt to compare.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>>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |