Package org.omnifaces.model.tree
Class AbstractTreeModel<T>
- java.lang.Object
-
- org.omnifaces.model.tree.AbstractTreeModel<T>
-
- Type Parameters:
T
- The type of the wrapped data of the tree node.
- All Implemented Interfaces:
Serializable
,Iterable<TreeModel<T>>
,TreeModel<T>
- Direct Known Subclasses:
ListTreeModel
,SortedTreeModel
public abstract class AbstractTreeModel<T> extends Object implements TreeModel<T>
A base implementation ofTreeModel
. Implementors basically only need to implementcreateChildren()
wherein a concrete instance of the desired underlyingCollection
is returned.- Since:
- 1.7
- Author:
- Bauke Scholtz
- See Also:
ListTreeModel
,SortedTreeModel
, Serialized Form
-
-
Constructor Summary
Constructors Constructor Description AbstractTreeModel()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description 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.protected abstract Collection<TreeModel<T>>
createChildren()
Returns a concrete (and usually empty)Collection
instance which should hold the tree's children.boolean
equals(Object object)
int
getChildCount()
Returns the count of the children of the current tree node.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.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.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.String
toString()
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Method Detail
-
createChildren
protected abstract Collection<TreeModel<T>> createChildren()
Returns a concrete (and usually empty)Collection
instance which should hold the tree's children.- Returns:
- A concrete (and usually empty)
Collection
instance which should hold the tree's children.
-
setData
public void setData(T data)
Description copied from interface:TreeModel
Sets the wrapped data of the 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.
-
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 interfaceTreeModel<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.
-
getData
public T getData()
Description copied from interface:TreeModel
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. Returnsnull
if there is none.
-
getNextSibling
public TreeModel<T> getNextSibling()
Description copied from interface:TreeModel
Returns the next tree node sibling of the current tree node. Returnsnull
if there is none.- Specified by:
getNextSibling
in interfaceTreeModel<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. Returnsnull
if there is none.- Specified by:
getPreviousSibling
in interfaceTreeModel<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 interfaceTreeModel<T>
- Returns:
- The count of the children of the current tree node.
-
getChildren
public 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 theTreeModel.addChild(Object)
method on the tree node parent. Removing children should be done by theTreeModel.remove()
method on the tree node itself.- Specified by:
getChildren
in interfaceTreeModel<T>
- Returns:
- An unmodifiable list of all child tree nodes of the current tree node.
-
iterator
public 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.
-
getLevel
public int getLevel()
Description copied from interface:TreeModel
Returns the level of the current tree node. The root node has level 0.
-
getIndex
public 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 ofnull
. The first child has index0
. The second child of first child has index0_1
. The first child of second child of third child has index2_1_0
.
-
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.
-
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.
-
isFirst
public boolean isFirst()
Description copied from interface:TreeModel
Returns whether the current tree node is the first child of its parent, if any.
-
isLast
public boolean isLast()
Description copied from interface:TreeModel
Returns whether the current tree node is the last child of its parent, if any.
-
-