public abstract class AbstractTreeModel<E> extends java.lang.Object implements TreeModel<E>, TreeSelectableModel, TreeOpenableModel, Selectable<E>, Openable<E>, java.io.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 java.util.Set<AbstractTreeModel.Path> |
_opens
The open information.
|
protected java.util.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(java.lang.Object ctx)
A utility that the deriving class can call to restore the states
saved by
beforeSort() |
protected java.lang.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.
|
java.lang.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.
|
java.util.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.
|
java.util.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(java.lang.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(java.lang.Object child)
Returns whether an object is selected.
|
boolean |
isSelectionEmpty()
Returns true if the selection is currently empty.
|
boolean |
removeFromSelection(java.lang.Object child)
Remove the specified object from selection.
|
boolean |
removeOpenObject(java.lang.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(java.util.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(java.util.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, wait
getChild, getChildCount, isLeaf
protected java.util.Set<AbstractTreeModel.Path> _selection
protected java.util.Set<AbstractTreeModel.Path> _opens
public AbstractTreeModel(E root)
AbstractTreeModel
.root
- root of treepublic void setSelectionControl(SelectionControl ctrl)
Selectable
setSelectionControl
in interface Selectable<E>
public SelectionControl getSelectionControl()
Selectable
getSelectionControl
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)
TreeModel
public int[] getPath(E child)
public void addTreeDataListener(TreeDataListener l)
TreeModel
addTreeDataListener
in interface TreeModel<E>
l
- the listener to addpublic void removeTreeDataListener(TreeDataListener l)
TreeModel
removeTreeDataListener
in interface TreeModel<E>
l
- the listener to removepublic void setMultiple(boolean multiple)
TreeSelectableModel
setMultiple
in interface Selectable<E>
setMultiple
in interface TreeSelectableModel
public boolean isMultiple()
TreeSelectableModel
isMultiple
in interface Selectable<E>
isMultiple
in interface TreeSelectableModel
TreeSelectableModel.setMultiple(boolean)
public boolean addSelectionPath(int[] path)
TreeSelectableModel
path
is null.addSelectionPath
in interface TreeSelectableModel
path
- the new path to add to the current selectionpublic boolean addSelectionPaths(int[][] paths)
TreeSelectableModel
paths
is null.addSelectionPaths
in interface TreeSelectableModel
paths
- the new paths to add to the current selectionpublic boolean removeSelectionPath(int[] path)
TreeSelectableModel
path
is null.removeSelectionPath
in interface TreeSelectableModel
path
- the path to remove from the selectionpublic boolean removeSelectionPaths(int[][] paths)
TreeSelectableModel
paths
are in the selection, the TreeDataListeners are
notified. This method has no effect if paths
is null.removeSelectionPaths
in interface TreeSelectableModel
paths
- the path to remove from the selectionpublic boolean isPathSelected(int[] path)
TreeSelectableModel
path
, is in the current selection.isPathSelected
in interface TreeSelectableModel
public int[] getSelectionPath()
TreeSelectableModel
getSelectionPath
in interface TreeSelectableModel
public int[][] getSelectionPaths()
TreeSelectableModel
getSelectionPaths
in interface TreeSelectableModel
public int getSelectionCount()
TreeSelectableModel
getSelectionCount
in interface TreeSelectableModel
public boolean isSelectionEmpty()
TreeSelectableModel
isSelectionEmpty
in interface Selectable<E>
isSelectionEmpty
in interface TreeSelectableModel
public void clearSelection()
TreeSelectableModel
clearSelection
in interface Selectable<E>
clearSelection
in interface TreeSelectableModel
public boolean addOpenPath(int[] path)
TreeOpenableModel
path
is null.addOpenPath
in interface TreeOpenableModel
path
- the new path to add to the current openpublic boolean addOpenPaths(int[][] paths)
TreeOpenableModel
paths
is null.addOpenPaths
in interface TreeOpenableModel
paths
- the new paths to add to the current Openpublic boolean removeOpenPath(int[] path)
TreeOpenableModel
path
is null.removeOpenPath
in interface TreeOpenableModel
path
- the path to remove from the openpublic boolean removeOpenPaths(int[][] paths)
TreeOpenableModel
paths
are in the open, the TreeDataListeners are notified. This method has no
effect if paths
is null.removeOpenPaths
in interface TreeOpenableModel
paths
- the path to remove from the openpublic boolean isPathOpened(int[] path)
TreeOpenableModel
path
, is in the current open.isPathOpened
in interface TreeOpenableModel
public int[] getOpenPath()
TreeOpenableModel
getOpenPath
in interface TreeOpenableModel
public int[][] getOpenPaths()
TreeOpenableModel
getOpenPaths
in interface TreeOpenableModel
public int getOpenCount()
TreeOpenableModel
getOpenCount
in interface TreeOpenableModel
public boolean isOpenEmpty()
TreeOpenableModel
isOpenEmpty
in interface Openable<E>
isOpenEmpty
in interface TreeOpenableModel
public void clearOpen()
TreeOpenableModel
TreeDataListener
listeners are notified.clearOpen
in interface Openable<E>
clearOpen
in interface TreeOpenableModel
protected java.lang.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(java.lang.Object ctx)
beforeSort()
public java.util.Set<E> getSelection()
Selectable
getSelection
in interface Selectable<E>
public void setSelection(java.util.Collection<? extends E> selection)
Selectable
If this represents a change to the current selection then notify each ListDataListener, including UI.
setSelection
in interface Selectable<E>
public boolean isSelected(java.lang.Object child)
Selectable
isSelected
in interface Selectable<E>
public boolean addToSelection(E child)
Selectable
If 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(java.lang.Object child)
Selectable
If 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 java.util.Set<E> getOpenObjects()
Openable
getOpenObjects
in interface Openable<E>
public void setOpenObjects(java.util.Collection<? extends E> opened)
Openable
setOpenObjects
in interface Openable<E>
public boolean isObjectOpened(java.lang.Object child)
Openable
isObjectOpened
in interface Openable<E>
public boolean addOpenObject(E child)
Openable
addOpenObject
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(java.lang.Object child)
Openable
removeOpenObject
in interface Openable<E>
child
- the object to be remove from selection.public java.lang.Object clone()
clone
in class java.lang.Object
public int getPageSize()
Pageable
Default: 20.
getPageSize
in interface Pageable
public void setPageSize(int size) throws WrongValueException
Pageable
setPageSize
in interface Pageable
WrongValueException
public int getPageCount()
getPageCount
in interface Pageable
public int getActivePage()
Pageable
getActivePage
in interface Pageable
public void setActivePage(int pg) throws WrongValueException
Pageable
setActivePage
in interface Pageable
WrongValueException
public void addPagingEventListener(PagingListener listener)
PagingEventPublisher
addPagingEventListener
in interface PagingEventPublisher
public void removePagingEventListener(PagingListener listener)
PagingEventPublisher
removePagingEventListener
in interface PagingEventPublisher
Copyright © 2005-2011 Potix Corporation. All Rights Reserved.