org.omnifaces.model.tree
Class ListTreeModel<T>

java.lang.Object
  extended by org.omnifaces.model.tree.ListTreeModel<T>
Type Parameters:
T - The type of the wrapped data of the tree node.
All Implemented Interfaces:
java.io.Serializable, java.lang.Iterable<TreeModel<T>>, TreeModel<T>

public class ListTreeModel<T>
extends java.lang.Object
implements TreeModel<T>

A concrete implementation of TreeModel which holds the tree children in a List.

Author:
Bauke Scholtz
See Also:
Serialized Form

Constructor Summary
ListTreeModel()
           
 
Method Summary
 TreeModel<T> addChild(T data)
          Creates and adds a child tree node with the given wrapped data to the current tree node.
 TreeModel<T> addChildNode(TreeModel<T> child)
          Adds the given child tree node to the current tree node.
 boolean equals(java.lang.Object object)
           
 int getChildCount()
          Returns the count of the children of the current tree node.
 java.util.List<TreeModel<T>> getChildren()
          Returns an unmodifiable list of all child tree nodes of the current tree node.
 T getData()
          Returns the wrapped data of the current tree node.
 java.lang.String getIndex()
          Returns the zero-based unique index of the current tree node.
 int getLevel()
          Returns the level of the current tree node.
 TreeModel<T> getNextSibling()
          Returns the next tree node sibling of the current tree node.
 TreeModel<T> getParent()
          Returns the parent tree node of the current tree node.
 TreeModel<T> getPreviousSibling()
          Returns the previous tree node sibling of the current tree node.
 int hashCode()
           
 boolean isFirst()
          Returns whether the current tree node is the first child of its parent, if any.
 boolean isLast()
          Returns whether the current tree node is the last child of its parent, if any.
 boolean isLeaf()
          Returns whether the current tree node is a leaf node.
 boolean isRoot()
          Returns whether the current tree node is the root node.
 java.util.Iterator<TreeModel<T>> iterator()
          Returns an unmodifiable iterator over the children of the current tree node.
 TreeModel<T> remove()
          Removes the current tree node from its parent, if any.
 void setData(T data)
          Sets the wrapped data of the current tree node.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ListTreeModel

public ListTreeModel()
Method Detail

setData

public void setData(T data)
Description copied from interface: TreeModel
Sets the wrapped data of the current tree node.

Specified by:
setData in interface TreeModel<T>
Parameters:
data - The wrapped data of current tree node.

addChild

public TreeModel<T> addChild(T data)
Description copied from interface: TreeModel
Creates and adds a child tree node with the given wrapped data to the current tree node. It returns the newly created and added child tree node to ease further building.

Specified by:
addChild in interface TreeModel<T>
Parameters:
data - The wrapped data of the child tree node to be created and added.
Returns:
The newly created and added child tree node of the current tree node.

addChildNode

public TreeModel<T> addChildNode(TreeModel<T> child)
Description copied from interface: TreeModel
Adds the given child tree node to the current tree node. It returns the added child tree node to ease further building.

Specified by:
addChildNode in interface TreeModel<T>
Parameters:
child - The child tree node to be added.
Returns:
The same child treenode.

remove

public TreeModel<T> remove()
Description copied from interface: TreeModel
Removes the current tree node from its parent, if any. It returns the parent to ease further building.

Specified by:
remove in interface TreeModel<T>
Returns:
The parent tree node of the current tree node.

getData

public T getData()
Description copied from interface: TreeModel
Returns the wrapped data of the current tree node.

Specified by:
getData in interface TreeModel<T>
Returns:
The wrapped data of the current tree node.

getParent

public TreeModel<T> getParent()
Description copied from interface: TreeModel
Returns the parent tree node of the current tree node. Returns null if there is none.

Specified by:
getParent in interface TreeModel<T>
Returns:
The parent tree node of the current tree node.

getNextSibling

public TreeModel<T> getNextSibling()
Description copied from interface: TreeModel
Returns the next tree node sibling of the current tree node. Returns null if there is none.

Specified by:
getNextSibling in interface TreeModel<T>
Returns:
The next tree node sibling of the current tree node.

getPreviousSibling

public TreeModel<T> getPreviousSibling()
Description copied from interface: TreeModel
Returns the previous tree node sibling of the current tree node. Returns null if there is none.

Specified by:
getPreviousSibling in interface TreeModel<T>
Returns:
The previous tree node sibling of the current tree node.

getChildCount

public int getChildCount()
Description copied from interface: TreeModel
Returns the count of the children of the current tree node.

Specified by:
getChildCount in interface TreeModel<T>
Returns:
The count of the children of the current tree node.

getChildren

public java.util.List<TreeModel<T>> getChildren()
Description copied from interface: TreeModel
Returns an unmodifiable list of all child tree nodes of the current tree node. Adding and removing elements is not supported on the list. Adding new children should be done by the TreeModel.addChild(Object) method on the tree node parent. Removing children should be done by the TreeModel.remove() method on the tree node itself.

Specified by:
getChildren in interface TreeModel<T>
Returns:
An unmodifiable list of all child tree nodes of the current tree node.

iterator

public java.util.Iterator<TreeModel<T>> iterator()
Description copied from interface: TreeModel
Returns an unmodifiable iterator over the children of the current tree node. Adding/inserting/removing elements is not supported on the iterator.

Specified by:
iterator in interface java.lang.Iterable<TreeModel<T>>
Specified by:
iterator in interface TreeModel<T>
Returns:
An unmodifiable iterator over the children of the current tree node.
See Also:
Iterable

getLevel

public int getLevel()
Description copied from interface: TreeModel
Returns the level of the current tree node. The root node has level 0.

Specified by:
getLevel in interface TreeModel<T>
Returns:
The level of the current tree node.

getIndex

public java.lang.String getIndex()
Description copied from interface: TreeModel
Returns the zero-based unique index of the current tree node. This is an underscore separated representation of the position of the node in the tree hierarchy. The root node has index of null. The first child has index 0. The second child of first child has index 0_1. The first child of second child of third child has index 2_1_0.

Specified by:
getIndex in interface TreeModel<T>
Returns:
The unique index of the current tree node.

isRoot

public boolean isRoot()
Description copied from interface: TreeModel
Returns whether the current tree node is the root node. That is, when it has no parent.

Specified by:
isRoot in interface TreeModel<T>
Returns:
true if the current tree node is the root node, otherwise false.

isLeaf

public boolean isLeaf()
Description copied from interface: TreeModel
Returns whether the current tree node is a leaf node. That is, when it has no children.

Specified by:
isLeaf in interface TreeModel<T>
Returns:
true if the current tree node is a leaf node, otherwise false.

isFirst

public boolean isFirst()
Description copied from interface: TreeModel
Returns whether the current tree node is the first child of its parent, if any.

Specified by:
isFirst in interface TreeModel<T>
Returns:
true if the current tree node is the first child of its parent, otherwise false.

isLast

public boolean isLast()
Description copied from interface: TreeModel
Returns whether the current tree node is the last child of its parent, if any.

Specified by:
isLast in interface TreeModel<T>
Returns:
true if the current tree node is the last child of its parent, otherwise false.

equals

public boolean equals(java.lang.Object object)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object