org.zkoss.zul
Interface TreeModel<E>

All Known Implementing Classes:
AbstractTreeModel, DefaultTreeModel

public interface TreeModel<E>

This interface defines the methods that component like Tree use to get the content of items.

Note: changing a render will not cause the tree to re-render. If you want it to re-render, you could assign the same model again (i.e., setModel(getModel())), or fire an TreeDataEvent event.

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

Since:
3.0.0
Author:
Jeff Liu

Method Summary
 void addTreeDataListener(TreeDataListener l)
          Add a listener to the tree that's notified each time a change to the data model occurs
 E getChild(E parent, int index)
          Returns the child of parent at index index in the parent's child array.
 int getChildCount(E parent)
          Returns the number of children of parent.
 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). You don't have to implement this method if you extends from AbstractTreeModel. If you implement TreeModel from scratch, you could implement this method by just returning null, since none of ZK's code depends on it.
 E getRoot()
          Returns the root of the tree.
 boolean isLeaf(E node)
          Returns true if node is a leaf.
 void removeTreeDataListener(TreeDataListener l)
          Remove a listener to the tree that's notified each time a change to the data model occurs
 

Method Detail

isLeaf

boolean isLeaf(E node)
Returns true if node is a leaf. Notice that not all non-leaf nodes have children. In file-system terminology, a leaf node is a file, while a non-leaf node is a folder.

Parameters:
node - a node in the tree, obtained from this data source
Returns:
true if node is a leaf.

getChild

E getChild(E parent,
           int index)
Returns the child of parent at index index in the parent's child array.

Parameters:
parent - a node in the tree, obtained from this data source
Returns:
the child of parent at index index

getChildCount

int getChildCount(E parent)
Returns the number of children of parent.

Parameters:
parent - a node in the tree, obtained from this data source
Returns:
the number of children of the node parent

getIndexOfChild

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.

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

getRoot

E getRoot()
Returns the root of the tree.

Returns:
the root of Tree.

addTreeDataListener

void addTreeDataListener(TreeDataListener l)
Add a listener to the tree that's notified each time a change to the data model occurs

Parameters:
l - the listener to add

removeTreeDataListener

void removeTreeDataListener(TreeDataListener l)
Remove a listener to the tree that's notified each time a change to the data model occurs

Parameters:
l - the listener to remove

getPath

int[] getPath(Object parent,
              Object lastNode)
Deprecated. As of release 5.0.6, it was replaced by getIndexOfChild(E, E). You don't have to implement this method if you extends from AbstractTreeModel. If you implement TreeModel from scratch, you could implement this method by just returning null, since none of ZK's code depends on it.



Copyright © 2011. All Rights Reserved.