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 underlyingCollectionis 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)Collectioninstance which should hold the tree's children.booleanequals(Object object)intgetChildCount()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.TgetData()Returns the wrapped data of the current tree node.StringgetIndex()Returns the zero-based unique index of the current tree node.intgetLevel()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.inthashCode()booleanisFirst()Returns whether the current tree node is the first child of its parent, if any.booleanisLast()Returns whether the current tree node is the last child of its parent, if any.booleanisLeaf()Returns whether the current tree node is a leaf node.booleanisRoot()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.voidsetData(T data)Sets the wrapped data of the current tree node.StringtoString()-
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)Collectioninstance which should hold the tree's children.- Returns:
- A concrete (and usually empty)
Collectioninstance which should hold the tree's children.
-
setData
public void setData(T data)
Description copied from interface:TreeModelSets the wrapped data of the current tree node.
-
addChild
public TreeModel<T> addChild(T data)
Description copied from interface:TreeModelCreates 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:TreeModelAdds the given child tree node to the current tree node. It returns the added child tree node to ease further building.- Specified by:
addChildNodein 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:TreeModelRemoves 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:TreeModelReturns the wrapped data of the current tree node.
-
getParent
public TreeModel<T> getParent()
Description copied from interface:TreeModelReturns the parent tree node of the current tree node. Returnsnullif there is none.
-
getNextSibling
public TreeModel<T> getNextSibling()
Description copied from interface:TreeModelReturns the next tree node sibling of the current tree node. Returnsnullif there is none.- Specified by:
getNextSiblingin interfaceTreeModel<T>- Returns:
- The next tree node sibling of the current tree node.
-
getPreviousSibling
public TreeModel<T> getPreviousSibling()
Description copied from interface:TreeModelReturns the previous tree node sibling of the current tree node. Returnsnullif there is none.- Specified by:
getPreviousSiblingin interfaceTreeModel<T>- Returns:
- The previous tree node sibling of the current tree node.
-
getChildCount
public int getChildCount()
Description copied from interface:TreeModelReturns the count of the children of the current tree node.- Specified by:
getChildCountin interfaceTreeModel<T>- Returns:
- The count of the children of the current tree node.
-
getChildren
public List<TreeModel<T>> getChildren()
Description copied from interface:TreeModelReturns 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:
getChildrenin 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:TreeModelReturns 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:TreeModelReturns the level of the current tree node. The root node has level 0.
-
getIndex
public String getIndex()
Description copied from interface:TreeModelReturns 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:TreeModelReturns whether the current tree node is the root node. That is, when it has no parent.
-
isLeaf
public boolean isLeaf()
Description copied from interface:TreeModelReturns whether the current tree node is a leaf node. That is, when it has no children.
-
isFirst
public boolean isFirst()
Description copied from interface:TreeModelReturns whether the current tree node is the first child of its parent, if any.
-
isLast
public boolean isLast()
Description copied from interface:TreeModelReturns whether the current tree node is the last child of its parent, if any.
-
-