org.zkoss.zul
Class AbstractTreeModel<E>

java.lang.Object
  extended by org.zkoss.zul.AbstractTreeModel<E>
All Implemented Interfaces:
Serializable, Openable<E>, Selectable<E>, TreeModel<E>
Direct Known Subclasses:
DefaultTreeModel

public abstract class AbstractTreeModel<E>
extends Object
implements TreeModel<E>, Selectable<E>, Openable<E>, Serializable

A skeletal implementation for TreeModel.

For introduction, please refer to ZK Developer's Reference: Tree Model.

Since:
3.0.0
Author:
Jeff Liu
See Also:
Serialized Form

Constructor Summary
AbstractTreeModel(E root)
          Creates a AbstractTreeModel.
 
Method Summary
 void addSelection(E obj)
          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
 void clearOpen()
          Clear all open status.
 void clearSelection()
          Clear all selection.
 void fireEvent(E node, int indexFrom, int indexTo, int evtType)
          Fires a TreeDataEvent for all registered listener
 int getIndexOfChild(E parent, E child)
          Returns the index of child in parent.
 int[] getPath(Object parent, Object lastNode)
          Deprecated. As of release 5.0.6, it was replaced by getIndexOfChild(E, E). This method was implemented to provide backward compatibility.
 E getRoot()
          Return the root of tree
 Set<E> getSelection()
          Returns current selection.
 boolean isOpen(E obj)
          Returns whether the specified object be opened.
protected  void removeAllSelection(Collection<? extends E> c)
           
 void removeSelection(Object obj)
          Remove the specified object from selection.
 void removeTreeDataListener(TreeDataListener l)
          Remove a listener to the tree that's notified each time a change to the data model occurs
protected  void retainAllSelection(Collection<? extends E> c)
           
 void setOpen(E obj, boolean open)
          Sets the specified object into open.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.zkoss.zul.TreeModel
getChild, getChildCount, isLeaf
 

Constructor Detail

AbstractTreeModel

public AbstractTreeModel(E root)
Creates a AbstractTreeModel.

Parameters:
root - root of tree
Method Detail

getRoot

public E getRoot()
Return the root of tree

Specified by:
getRoot in interface TreeModel<E>
Returns:
the root of tree

fireEvent

public void fireEvent(E node,
                      int indexFrom,
                      int indexTo,
                      int evtType)
Fires a TreeDataEvent for all registered listener

Note: you can invoke this method only in an event listener.


getIndexOfChild

public int getIndexOfChild(E parent,
                           E child)
Returns the index of child in parent. If either parent or child is null, returns -1. If either parent or child don't belong to this tree model, returns -1.

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. TreeModel.getChild(E, int)

Specified by:
getIndexOfChild in interface TreeModel<E>
Parameters:
parent - a node in the tree, obtained from this data source
child - the node we are interested in
Returns:
the index of the child in the parent, or -1 if either child or parent are null or don't belong to this tree model
Since:
5.0.6

addTreeDataListener

public void addTreeDataListener(TreeDataListener l)
Description copied from interface: TreeModel
Add a listener to the tree that's notified each time a change to the data model occurs

Specified by:
addTreeDataListener in interface TreeModel<E>
Parameters:
l - the listener to add

removeTreeDataListener

public void removeTreeDataListener(TreeDataListener l)
Description copied from interface: TreeModel
Remove a listener to the tree that's notified each time a change to the data model occurs

Specified by:
removeTreeDataListener in interface TreeModel<E>
Parameters:
l - the listener to remove

getSelection

public Set<E> getSelection()
Description copied from interface: Selectable
Returns current selection.

Specified by:
getSelection in interface Selectable<E>
Returns:
current selection.

addSelection

public void addSelection(E obj)
Description copied from interface: Selectable
Add the specified object into selection.

Notice that this method is designed to be called by a component (such as Listbox). If it is called by an application, the component's selection status won't be changed.

Specified by:
addSelection in interface Selectable<E>
Parameters:
obj - the object to be as selection.

removeSelection

public void removeSelection(Object obj)
Description copied from interface: Selectable
Remove the specified object from selection.

Notice that this method is designed to be called by a component (such as Listbox). If it is called by an application, the component's selection status won't be changed.

Specified by:
removeSelection in interface Selectable<E>
Parameters:
obj - the object to be remove from selection.

clearSelection

public void clearSelection()
Description copied from interface: Selectable
Clear all selection.

Notice that this method is designed to be called by a component (such as Listbox). If it is called by an application, the component's selection status won't be changed.

Specified by:
clearSelection in interface Selectable<E>

removeAllSelection

protected void removeAllSelection(Collection<? extends E> c)

retainAllSelection

protected void retainAllSelection(Collection<? extends E> c)

setOpen

public void setOpen(E obj,
                    boolean open)
Description copied from interface: Openable
Sets the specified object into open.

Notice that this method is designed to be called by a component (such as Treeitem). If it is called by an application, the component's open status won't be changed.

Specified by:
setOpen in interface Openable<E>
Parameters:
obj - the object to be as open.
open - whether be opened

isOpen

public boolean isOpen(E obj)
Description copied from interface: Openable
Returns whether the specified object be opened.

Specified by:
isOpen in interface Openable<E>

clearOpen

public void clearOpen()
Description copied from interface: Openable
Clear all open status.

Notice that this method is designed to be called by a component (such as Tree). If it is called by an application, the component's open status won't be changed.

Specified by:
clearOpen in interface Openable<E>

getPath

public int[] getPath(Object parent,
                     Object lastNode)
Deprecated. As of release 5.0.6, it was replaced by getIndexOfChild(E, E). This method was implemented to provide backward compatibility.

Specified by:
getPath in interface TreeModel<E>


Copyright © 2011. All Rights Reserved.