public abstract class AbstractTreeModel<E> extends Object implements TreeModel<E>, TreeSelectableModel, TreeOpenableModel, Selectable<E>, Openable<E>, Serializable, Pageable, PagingEventPublisher
TreeModel.
AbstractTreeModel implements both TreeSelectableModel
and TreeOpenableModel. In other words, it stores the selection
and open states, such that Tree and other UI can interact with.
In additions, AbstractTreeModel also implements
Selectable and Openable to simplify the access
(and provides backward compatibility to ZK 5 and earlier).
However, these two interfaces are optional and designed for application.
Tree and all ZK core don't access it at all.
For introduction, please refer to ZK Developer's Reference: Tree Model.
| Modifier and Type | Class and Description |
|---|---|
static class |
AbstractTreeModel.DefaultSelectionControl<E>
A default selection control implementation for
AbstractTreeModel,
by default it assumes all elements are selectable. |
protected static class |
AbstractTreeModel.Path
Represents a tree path.
|
| Modifier and Type | Field and Description |
|---|---|
protected Set<AbstractTreeModel.Path> |
_opens
The open information.
|
protected Set<AbstractTreeModel.Path> |
_selection
The selection.
|
INTERNAL_EVENT| Constructor and Description |
|---|
AbstractTreeModel(E root)
Creates a
AbstractTreeModel. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
addOpenObject(E child)
Add the specified object into the collection of opened objects.
|
boolean |
addOpenPath(int[] path)
Adds path to the current open.
|
boolean |
addOpenPaths(int[][] paths)
Adds paths to the current Open.
|
void |
addPagingEventListener(PagingListener listener)
Adds a listener to the list of listeners to be notified when a PagingEvent
happens outside of standard Paging component
|
boolean |
addSelectionPath(int[] path)
Adds path to the current selection.
|
boolean |
addSelectionPaths(int[][] paths)
Adds paths to the current selection.
|
boolean |
addToSelection(E child)
Add the specified object into selection.
|
void |
addTreeDataListener(TreeDataListener l)
Add a listener to the tree that's notified each time a change to the data model occurs
|
protected void |
afterSort(Object ctx)
A utility that the deriving class can call to restore the states
saved by
beforeSort() |
protected Object |
beforeSort()
A utility that the deriving class can call to save the states
before sorting the model.
|
void |
clearOpen()
Empties the current open path.
|
void |
clearSelection()
Empties the current selection.
|
Object |
clone() |
void |
fireEvent(E node,
int indexFrom,
int indexTo,
int evtType)
Deprecated.
As of release 6.0.0, replaced with
fireEvent(int, int[], int, int). |
void |
fireEvent(int evtType,
int[] path,
int indexFrom,
int indexTo)
Fires a
TreeDataEvent for all registered listener
Note: you can invoke this method only in an event listener. |
void |
fireEvent(int evtType,
int[] path,
int indexFrom,
int indexTo,
int[] affectedPath)
Has the same functionality with
fireEvent(int, int[], int, int),
while this is used for node removal only |
protected void |
fireOpenChanged(int[] path)
Fires a
TreeDataEvent for all registered listener when open
status has changed. |
protected void |
fireSelectionChanged(int[] path)
Fires a
TreeDataEvent for all registered listener when selection
status has changed. |
int |
getActivePage()
Returns the active page (starting from 0).
|
E |
getChild(int[] path)
Returns the child at the given path where the path indicates the child is
placed in the whole tree.
|
int |
getIndexOfChild(E parent,
E child)
Returns the index of child in parent.
|
int |
getOpenCount()
Returns the number of paths that are opened.
|
Set<E> |
getOpenObjects()
Returns the objects that are opened.
|
int[] |
getOpenPath()
Returns the first path in the open.
|
int[][] |
getOpenPaths()
Returns the paths in the open.
|
int |
getPageCount()
Returns the number of pages.
|
int |
getPageSize()
Returns the number of items per page.
|
int[] |
getPath(E child)
Returns the path from the specified child.
|
E |
getRoot()
Return the root of the tree model.
|
Set<E> |
getSelection()
Returns the current selection.
|
SelectionControl |
getSelectionControl()
Returns the selection control for the selection model, if any.
|
int |
getSelectionCount()
Returns the number of paths that are selected.
|
int[] |
getSelectionPath()
Returns the first path in the selection.
|
int[][] |
getSelectionPaths()
Returns the paths in the selection.
|
boolean |
isMultiple()
Returns whether the current selection mode is multiple.
|
boolean |
isObjectOpened(Object child)
Returns whether the specified object be opened.
|
boolean |
isOpenEmpty()
Returns true if the open is currently empty.
|
boolean |
isPathOpened(int[] path)
Returns true if the path,
path, is in the current open. |
boolean |
isPathSelected(int[] path)
Returns true if the path,
path, is in the current selection. |
boolean |
isSelected(Object child)
Returns whether an object is selected.
|
boolean |
isSelectionEmpty()
Returns true if the selection is currently empty.
|
boolean |
removeFromSelection(Object child)
Remove the specified object from selection.
|
boolean |
removeOpenObject(Object child)
Remove the specified object from selection.
|
boolean |
removeOpenPath(int[] path)
Removes path from the open.
|
boolean |
removeOpenPaths(int[][] paths)
Removes paths from the open.
|
void |
removePagingEventListener(PagingListener listener)
Removes a listener from the list of listeners to be notified when a PagingEvent
happens outside of standard Paging component
|
boolean |
removeSelectionPath(int[] path)
Removes path from the selection.
|
boolean |
removeSelectionPaths(int[][] paths)
Removes paths from the selection.
|
void |
removeTreeDataListener(TreeDataListener l)
Remove a listener to the tree that's notified each time a change to the data model occurs
|
void |
setActivePage(int pg)
Sets the active page (starting from 0).
|
void |
setMultiple(boolean multiple)
Sets the selection mode to be multiple.
|
void |
setOpenObjects(Collection<? extends E> opened)
Replace the current set of opened objects with the given set.
|
void |
setPageSize(int size)
Sets the number of items per page.
|
void |
setSelection(Collection<? extends E> selection)
Replace the current selection with the given set.
|
void |
setSelectionControl(SelectionControl ctrl)
Sets the selection control for the selection model
|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetChild, getChildCount, isLeafprotected Set<AbstractTreeModel.Path> _selection
protected Set<AbstractTreeModel.Path> _opens
public AbstractTreeModel(E root)
AbstractTreeModel.root - root of treepublic void setSelectionControl(SelectionControl ctrl)
SelectablesetSelectionControl in interface Selectable<E>public SelectionControl getSelectionControl()
SelectablegetSelectionControl in interface Selectable<E>public E getRoot()
public void fireEvent(E node, int indexFrom, int indexTo, int evtType)
fireEvent(int, int[], int, int).public void fireEvent(int evtType,
int[] path,
int indexFrom,
int indexTo)
TreeDataEvent for all registered listener
Note: you can invoke this method only in an event listener.
public void fireEvent(int evtType,
int[] path,
int indexFrom,
int indexTo,
int[] affectedPath)
fireEvent(int, int[], int, int),
while this is used for node removal onlyprotected void fireSelectionChanged(int[] path)
TreeDataEvent for all registered listener when selection
status has changed.protected void fireOpenChanged(int[] path)
TreeDataEvent for all registered listener when open
status has changed.public int getIndexOfChild(E parent, E child)
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.
getChild(int[])
getIndexOfChild in interface TreeModel<E>parent - a node in the tree, obtained from this data sourcechild - the node we are interested inpublic E getChild(int[] path)
TreeModelpublic int[] getPath(E child)
public void addTreeDataListener(TreeDataListener l)
TreeModeladdTreeDataListener in interface TreeModel<E>l - the listener to addpublic void removeTreeDataListener(TreeDataListener l)
TreeModelremoveTreeDataListener in interface TreeModel<E>l - the listener to removepublic void setMultiple(boolean multiple)
TreeSelectableModelsetMultiple in interface Selectable<E>setMultiple in interface TreeSelectableModelpublic boolean isMultiple()
TreeSelectableModelisMultiple in interface Selectable<E>isMultiple in interface TreeSelectableModelTreeSelectableModel.setMultiple(boolean)public boolean addSelectionPath(int[] path)
TreeSelectableModelpath is null.addSelectionPath in interface TreeSelectableModelpath - the new path to add to the current selectionpublic boolean addSelectionPaths(int[][] paths)
TreeSelectableModelpaths is null.addSelectionPaths in interface TreeSelectableModelpaths - the new paths to add to the current selectionpublic boolean removeSelectionPath(int[] path)
TreeSelectableModelpath
is null.removeSelectionPath in interface TreeSelectableModelpath - the path to remove from the selectionpublic boolean removeSelectionPaths(int[][] paths)
TreeSelectableModelpaths are in the selection, the TreeDataListeners are
notified. This method has no effect if paths is null.removeSelectionPaths in interface TreeSelectableModelpaths - the path to remove from the selectionpublic boolean isPathSelected(int[] path)
TreeSelectableModelpath, is in the current selection.isPathSelected in interface TreeSelectableModelpublic int[] getSelectionPath()
TreeSelectableModelgetSelectionPath in interface TreeSelectableModelpublic int[][] getSelectionPaths()
TreeSelectableModelgetSelectionPaths in interface TreeSelectableModelpublic int getSelectionCount()
TreeSelectableModelgetSelectionCount in interface TreeSelectableModelpublic boolean isSelectionEmpty()
TreeSelectableModelisSelectionEmpty in interface Selectable<E>isSelectionEmpty in interface TreeSelectableModelpublic void clearSelection()
TreeSelectableModelclearSelection in interface Selectable<E>clearSelection in interface TreeSelectableModelpublic boolean addOpenPath(int[] path)
TreeOpenableModelpath is null.addOpenPath in interface TreeOpenableModelpath - the new path to add to the current openpublic boolean addOpenPaths(int[][] paths)
TreeOpenableModelpaths is null.addOpenPaths in interface TreeOpenableModelpaths - the new paths to add to the current Openpublic boolean removeOpenPath(int[] path)
TreeOpenableModelpath is null.removeOpenPath in interface TreeOpenableModelpath - the path to remove from the openpublic boolean removeOpenPaths(int[][] paths)
TreeOpenableModelpaths
are in the open, the TreeDataListeners are notified. This method has no
effect if paths is null.removeOpenPaths in interface TreeOpenableModelpaths - the path to remove from the openpublic boolean isPathOpened(int[] path)
TreeOpenableModelpath, is in the current open.isPathOpened in interface TreeOpenableModelpublic int[] getOpenPath()
TreeOpenableModelgetOpenPath in interface TreeOpenableModelpublic int[][] getOpenPaths()
TreeOpenableModelgetOpenPaths in interface TreeOpenableModelpublic int getOpenCount()
TreeOpenableModelgetOpenCount in interface TreeOpenableModelpublic boolean isOpenEmpty()
TreeOpenableModelisOpenEmpty in interface Openable<E>isOpenEmpty in interface TreeOpenableModelpublic void clearOpen()
TreeOpenableModelTreeDataListener listeners are notified.clearOpen in interface Openable<E>clearOpen in interface TreeOpenableModelprotected Object beforeSort()
Default: saves the selection and open states.
For example, DefaultTreeModel.sort(java.util.Comparator<org.zkoss.zul.TreeNode<E>>, boolean) invokes it to preserve
the selection to the same objects (rather than the same paths).
protected void afterSort(Object ctx)
beforeSort()public Set<E> getSelection()
SelectablegetSelection in interface Selectable<E>public void setSelection(Collection<? extends E> selection)
SelectableIf this represents a change to the current selection then notify each ListDataListener, including UI.
setSelection in interface Selectable<E>public boolean isSelected(Object child)
SelectableisSelected in interface Selectable<E>public boolean addToSelection(E child)
SelectableIf this represents a change to the current selection then notify each ListDataListener, including UI.
addToSelection in interface Selectable<E>child - the object to be as selection.obj
is not part of the data, or was already selected.public boolean removeFromSelection(Object child)
SelectableIf this represents a change to the current selection then notify each ListDataListener, including UI.
removeFromSelection in interface Selectable<E>child - the object to be remove from selection.public Set<E> getOpenObjects()
OpenablegetOpenObjects in interface Openable<E>public void setOpenObjects(Collection<? extends E> opened)
OpenablesetOpenObjects in interface Openable<E>public boolean isObjectOpened(Object child)
OpenableisObjectOpened in interface Openable<E>public boolean addOpenObject(E child)
OpenableaddOpenObject in interface Openable<E>child - the object to be as selection.obj
is not part of the data, or was already opened.public boolean removeOpenObject(Object child)
OpenableremoveOpenObject in interface Openable<E>child - the object to be remove from selection.public int getPageSize()
PageableDefault: 20.
getPageSize in interface Pageablepublic void setPageSize(int size)
throws org.zkoss.zk.ui.WrongValueException
PageablesetPageSize in interface Pageableorg.zkoss.zk.ui.WrongValueExceptionpublic int getPageCount()
getPageCount in interface Pageablepublic int getActivePage()
PageablegetActivePage in interface Pageablepublic void setActivePage(int pg)
throws org.zkoss.zk.ui.WrongValueException
PageablesetActivePage in interface Pageableorg.zkoss.zk.ui.WrongValueExceptionpublic void addPagingEventListener(PagingListener listener)
PagingEventPublisheraddPagingEventListener in interface PagingEventPublisherpublic void removePagingEventListener(PagingListener listener)
PagingEventPublisherremovePagingEventListener in interface PagingEventPublisherCopyright © 2015. All rights reserved.