com.vaadin.data.util.
Class HierarchicalContainer
java.lang.Object
com.vaadin.data.util.AbstractContainer
com.vaadin.data.util.AbstractInMemoryContainer<Object,Object,Item>
com.vaadin.data.util.IndexedContainer
com.vaadin.data.util.HierarchicalContainer
All Implemented Interfaces:
Container, Container.Filterable, Container.Hierarchical, Container.Indexed, Container.ItemSetChangeNotifier, Container.Ordered, Container.PropertySetChangeNotifier, Container.SimpleFilterable, Container.Sortable, Property.ValueChangeNotifier, Serializable, Cloneable
- extends IndexedContainer
- implements Container.Hierarchical
public class HierarchicalContainer
A specialized Container whose contents can be accessed like it was a tree-like structure.
Since:
3.0
Version:
6.8.18
Author:
Vaadin Ltd.
See Also:
Nested Class Summary |
---|
Nested classes/interfaces inherited from class com.vaadin.data.util.IndexedContainer |
---|
IndexedContainer.ItemSetChangeEvent |
Nested classes/interfaces inherited from class com.vaadin.data.util.AbstractContainer |
---|
AbstractContainer.BaseItemSetChangeEvent, AbstractContainer.BasePropertySetChangeEvent |
Nested classes/interfaces inherited from interface com.vaadin.data.Container |
---|
Container.Editor, Container.Filter, Container.Filterable, Container.Hierarchical, Container.Indexed, Container.ItemSetChangeEvent, Container.ItemSetChangeListener, Container.ItemSetChangeNotifier, Container.Ordered, Container.PropertySetChangeEvent, Container.PropertySetChangeListener, Container.PropertySetChangeNotifier, Container.SimpleFilterable, Container.Sortable, Container.Viewer |
Constructor Summary | |
---|---|
HierarchicalContainer()
|
Method Summary | |
---|---|
Object |
addItem()
Creates a new Item into the Container, and assign it an automatic ID. |
Item |
addItem(Object itemId)
Creates a new Item with the given ID in the Container. |
boolean |
areChildrenAllowed(Object itemId)
Tests if the Item with given ID can have children. |
protected boolean |
doFilterContainer(boolean hasFilters)
Filters the data in the container and updates internal data structures. |
protected void |
doSort()
Perform the sorting of the data structures in the container. |
protected void |
fireItemSetChange(Container.ItemSetChangeEvent event)
Sends an Item set change event to all registered interested listeners. |
Collection<?> |
getChildren(Object itemId)
Gets the IDs of all Items that are children of the specified Item. |
Object |
getParent(Object itemId)
Gets the ID of the parent Item of the specified Item. |
boolean |
hasChildren(Object itemId)
Tests if the Item specified with itemId has child Items
or if it is a leaf. |
boolean |
isIncludeParentsWhenFiltering()
Used to control how filtering works. |
boolean |
isRoot(Object itemId)
Tests if the Item specified with itemId is a root Item. |
void |
moveAfterSibling(Object itemId,
Object siblingId)
Moves a node (an Item) in the container immediately after a sibling node. |
protected boolean |
passesFilters(Object itemId)
Checks if the given itemId passes the filters set for the container. |
boolean |
removeAllItems()
Removes all Items from the Container. |
boolean |
removeItem(Object itemId)
Removes the Item identified by ItemId from the Container. |
static boolean |
removeItemRecursively(Container.Hierarchical container,
Object itemId)
Removes the Item identified by given itemId and all its children from the given Container. |
boolean |
removeItemRecursively(Object itemId)
Removes the Item identified by given itemId and all its children. |
Collection<?> |
rootItemIds()
Gets the IDs of all Items in the container that don't have a parent. |
boolean |
setChildrenAllowed(Object itemId,
boolean childrenAllowed)
Sets the given Item's capability to have children. |
void |
setIncludeParentsWhenFiltering(boolean includeParentsWhenFiltering)
Controls how the filtering of the container works. |
boolean |
setParent(Object itemId,
Object newParentId)
Sets the parent of an Item. |
Methods inherited from class com.vaadin.data.util.AbstractContainer |
---|
fireContainerPropertySetChange, fireContainerPropertySetChange, getItemSetChangeListeners, getPropertySetChangeListeners, setItemSetChangeListeners, setPropertySetChangeListeners |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface com.vaadin.data.Container |
---|
addContainerProperty, containsId, getContainerProperty, getContainerPropertyIds, getItem, getItemIds, getType, removeContainerProperty, size |
Methods inherited from interface com.vaadin.data.Container.Ordered |
---|
firstItemId, isFirstId, isLastId, lastItemId, nextItemId, prevItemId |
Constructor Detail |
---|
HierarchicalContainer
public HierarchicalContainer()
Method Detail |
---|
areChildrenAllowed
public boolean areChildrenAllowed(Object itemId)
- Specified by:
areChildrenAllowed
in interfaceContainer.Hierarchical
- Parameters:
itemId
- ID of the Item in the container whose child capability is to be tested- Returns:
true
if the specified Item exists in the Container and it can have children,false
if it's not found from the container or it can't have children.
Description copied from interface: Container.Hierarchical
Tests if the Item with given ID can have children.
getChildren
public Collection<?> getChildren(Object itemId)
- Specified by:
getChildren
in interfaceContainer.Hierarchical
- Parameters:
itemId
- ID of the Item whose children the caller is interested in- Returns:
- An unmodifiable
collection
containing the IDs of all other Items that are children in the container hierarchy
Description copied from interface: Container.Hierarchical
Gets the IDs of all Items that are children of the specified Item. The returned collection is unmodifiable.
getParent
public Object getParent(Object itemId)
- Specified by:
getParent
in interfaceContainer.Hierarchical
- Parameters:
itemId
- ID of the Item whose parent the caller wishes to find out.- Returns:
- the ID of the parent Item. Will be
null
if the specified Item is a root element.
Description copied from interface: Container.Hierarchical
Gets the ID of the parent Item of the specified Item.
hasChildren
public boolean hasChildren(Object itemId)
- Specified by:
hasChildren
in interfaceContainer.Hierarchical
- Parameters:
itemId
- ID of the Item to be tested- Returns:
true
if the specified Item has children,false
if not (is a leaf)
Description copied from interface: Container.Hierarchical
Tests if the Item specified with itemId
has child Items
or if it is a leaf. The Container.Hierarchical.getChildren(Object itemId)
method
always returns null
for leaf Items.
Note that being a leaf does not imply whether or not an Item is allowed to have children.
.
isRoot
public boolean isRoot(Object itemId)
- Specified by:
isRoot
in interfaceContainer.Hierarchical
- Parameters:
itemId
- ID of the Item whose root status is to be tested- Returns:
true
if the specified Item is a root,false
if not
Description copied from interface: Container.Hierarchical
Tests if the Item specified with itemId
is a root Item.
The hierarchical container can have more than one root and must have
at least one unless it is empty. The Container.Hierarchical.getParent(Object itemId)
method always returns null
for root Items.
rootItemIds
public Collection<?> rootItemIds()
- Specified by:
rootItemIds
in interfaceContainer.Hierarchical
- Returns:
- An unmodifiable
collection
containing IDs of all root elements of the container
Description copied from interface: Container.Hierarchical
Gets the IDs of all Items in the container that don't have a parent.
Such items are called root
Items. The returned
collection is unmodifiable.
setChildrenAllowed
public boolean setChildrenAllowed(Object itemId,
boolean childrenAllowed)
- Specified by:
setChildrenAllowed
in interfaceContainer.Hierarchical
- Parameters:
itemId
- the ID of the Item in the container whose child capability is to be set.childrenAllowed
- the boolean value specifying if the Item can have children or not.- Returns:
true
if the operation succeeded,false
if not
Sets the given Item's capability to have children. If the Item identified
with the itemId already has children and the areChildrenAllowed is false
this method fails and false
is returned; the children must
be first explicitly removed with
setParent(Object itemId, Object newParentId)
or
Container.removeItem(Object itemId)
.
setParent
public boolean setParent(Object itemId,
Object newParentId)
- Specified by:
setParent
in interfaceContainer.Hierarchical
- Parameters:
itemId
- the ID of the item to be set as the child of the Item identified with newParentId.newParentId
- the ID of the Item that's to be the new parent of the Item identified with itemId.- Returns:
true
if the operation succeeded,false
if not
Sets the parent of an Item. The new parent item must exist and be able to
have children. (canHaveChildren(newParentId) == true
). It is
also possible to detach a node from the hierarchy (and thus make it root)
by setting the parent null
.
moveAfterSibling
public void moveAfterSibling(Object itemId,
Object siblingId)
- Parameters:
itemId
- the identifier of the moved node (Item)siblingId
- the identifier of the reference node (Item), after which the other node will be located
Moves a node (an Item) in the container immediately after a sibling node. The two nodes must have the same parent in the container.
addItem
public Object addItem()
- Specified by:
addItem
in interfaceContainer
- Overrides:
addItem
in classIndexedContainer
- Returns:
- ID of the newly created Item, or
null
in case of a failure
Description copied from interface: Container
Creates a new Item into the Container, and assign it an automatic ID.
The new ID is returned, or null
if the operation fails.
After a successful call you can use the
method to fetch the Item.
getItem
This functionality is optional.
fireItemSetChange
protected void fireItemSetChange(Container.ItemSetChangeEvent event)
- Overrides:
fireItemSetChange
in classAbstractContainer
- Parameters:
event
- the item set change event to send, optionally with additional information
Description copied from class: AbstractContainer
Sends an Item set change event to all registered interested listeners.
addItem
public Item addItem(Object itemId)
- Specified by:
addItem
in interfaceContainer
- Overrides:
addItem
in classIndexedContainer
- Parameters:
itemId
- ID of the Item to be created- Returns:
- Created new Item, or
null
in case of a failure
Description copied from interface: Container
Creates a new Item with the given ID in the Container.
The new Item is returned, and it is ready to have its Properties
modified. Returns null
if the operation fails or the
Container already contains a Item with the given ID.
This functionality is optional.
removeAllItems
public boolean removeAllItems()
- Specified by:
removeAllItems
in interfaceContainer
- Overrides:
removeAllItems
in classIndexedContainer
- Returns:
true
if the operation succeeded,false
if not
Description copied from interface: Container
Removes all Items from the Container.
Note that Property ID and type information is preserved. This functionality is optional.
removeItem
public boolean removeItem(Object itemId)
- Specified by:
removeItem
in interfaceContainer
- Specified by:
removeItem
in interfaceContainer.Hierarchical
- Overrides:
removeItem
in classIndexedContainer
- Parameters:
itemId
- ID of the Item to remove- Returns:
true
if the operation succeeded,false
if not
Description copied from interface: Container
Removes the Item identified by ItemId
from the Container.
Containers that support filtering should also allow removing an item that is currently filtered out.
This functionality is optional.
removeItemRecursively
public boolean removeItemRecursively(Object itemId)
- Parameters:
itemId
- the identifier of the Item to be removed- Returns:
- true if the operation succeeded
- See Also:
removeItem(Object)
Removes the Item identified by given itemId and all its children.
removeItemRecursively
public static boolean removeItemRecursively(Container.Hierarchical container,
Object itemId)
- Parameters:
container
- the container where the item is to be removeditemId
- the identifier of the Item to be removed- Returns:
- true if the operation succeeded
Removes the Item identified by given itemId and all its children from the given Container.
doSort
protected void doSort()
- Overrides:
doSort
in classAbstractInMemoryContainer<Object,Object,Item>
Description copied from class: AbstractInMemoryContainer
Perform the sorting of the data structures in the container. This is
invoked when the itemSorter
has been prepared for the sort
operation. Typically this method calls
Collections.sort(aCollection, getItemSorter())
on all arrays
(containing item ids) that need to be sorted.
isIncludeParentsWhenFiltering
public boolean isIncludeParentsWhenFiltering()
- Returns:
- true if all parents for items that match the filter are included when filtering, false if only the matching items are included
Used to control how filtering works. @see
setIncludeParentsWhenFiltering(boolean)
for more information.
setIncludeParentsWhenFiltering
public void setIncludeParentsWhenFiltering(boolean includeParentsWhenFiltering)
- Parameters:
includeParentsWhenFiltering
- true to include all parents for items that match the filter, false to only include the matching items
Controls how the filtering of the container works. Set this to true to make filtering include parents for all matched items in addition to the items themselves. Setting this to false causes the filtering to only include the matching items and make items with excluded parents into root items.
doFilterContainer
protected boolean doFilterContainer(boolean hasFilters)
- Overrides:
doFilterContainer
in classAbstractInMemoryContainer<Object,Object,Item>
- Parameters:
hasFilters
- true if filters has been set for the container, false otherwise- Returns:
- true if the item set has changed as a result of the filtering
Description copied from class: AbstractInMemoryContainer
Filters the data in the container and updates internal data structures.
This method should reset any internal data structures and then repopulate
them so AbstractInMemoryContainer.getItemIds()
and other methods only return the filtered
items.
passesFilters
protected boolean passesFilters(Object itemId)
- Overrides:
passesFilters
in classAbstractInMemoryContainer<Object,Object,Item>
- Parameters:
itemId
- An itemId that exists in the container.- Returns:
- true if the itemId passes all filters or no filters are set, false otherwise.
Description copied from class: AbstractInMemoryContainer
Checks if the given itemId passes the filters set for the container. The caller should make sure the itemId exists in the container. For non-existing itemIds the behavior is undefined.