com.vaadin.data.util.
Class ContainerHierarchicalWrapper
java.lang.Object
com.vaadin.data.util.ContainerHierarchicalWrapper
All Implemented Interfaces:
Container, Container.Hierarchical, Container.ItemSetChangeNotifier, Container.PropertySetChangeNotifier, Serializable
- extends Object
- implements Container.Hierarchical, Container.ItemSetChangeNotifier, Container.PropertySetChangeNotifier
public class ContainerHierarchicalWrapper
A wrapper class for adding external hierarchy to containers not implementing
the Container.Hierarchical
interface.
If the wrapped container is changed directly (that is, not through the
wrapper), and does not implement Container.ItemSetChangeNotifier and/or
Container.PropertySetChangeNotifier the hierarchy information must be updated
with the updateHierarchicalWrapper()
method.
Since:
3.0
Version:
6.8.18
Author:
Vaadin Ltd.
See Also:
Nested Class Summary |
---|
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 | |
---|---|
ContainerHierarchicalWrapper(Container toBeWrapped)
Constructs a new hierarchical wrapper for an existing Container. |
Method Summary | |
---|---|
boolean |
addContainerProperty(Object propertyId,
Class<?> type,
Object defaultValue)
Adds a new Property to all Items in the Container. |
Object |
addItem()
Creates a new Item into the Container, assigns it an automatic ID, and adds it to the hierarchy. |
Item |
addItem(Object itemId)
Adds a new Item by its ID to the underlying container and to the hierarchy. |
void |
addListener(Container.ItemSetChangeListener listener)
Adds an Item set change listener for the object. |
void |
addListener(Container.PropertySetChangeListener listener)
Registers a new Property set change listener for this Container. |
boolean |
areChildrenAllowed(Object itemId)
Tests if the Item with given ID can have children. |
boolean |
containsId(Object itemId)
Tests if the Container contains the specified Item. |
Collection<?> |
getChildren(Object itemId)
Gets the IDs of all Items that are children of the specified Item. |
Property |
getContainerProperty(Object itemId,
Object propertyId)
Gets the Property identified by the given itemId and propertyId from the Container. |
Collection<?> |
getContainerPropertyIds()
Gets the ID's of all Properties stored in the Container. |
Item |
getItem(Object itemId)
Gets the Item with the given Item ID from the Container. |
Collection<?> |
getItemIds()
Gets the ID's of all visible (after filtering and sorting) Items stored in the Container. |
Object |
getParent(Object itemId)
Gets the ID of the parent Item of the specified Item. |
Class<?> |
getType(Object propertyId)
Gets the data type of all Properties identified by the given Property ID. |
boolean |
hasChildren(Object itemId)
Tests if the Item specified with itemId has child Items
or if it is a leaf. |
boolean |
isRoot(Object itemId)
Tests if the Item specified with itemId is a root Item. |
boolean |
removeAllItems()
Removes all items from the underlying container and from the hierarcy. |
boolean |
removeContainerProperty(Object propertyId)
Removes the specified Property from the underlying container and from the hierarchy. |
boolean |
removeItem(Object itemId)
Removes an Item specified by the itemId from the underlying container and from the hierarchy. |
boolean |
removeItemRecursively(Object itemId)
Removes the Item identified by given itemId and all its children. |
void |
removeListener(Container.ItemSetChangeListener listener)
Removes the Item set change listener from the object. |
void |
removeListener(Container.PropertySetChangeListener listener)
Removes a previously registered Property set change listener. |
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. |
boolean |
setParent(Object itemId,
Object newParentId)
Sets the parent of an Item. |
int |
size()
Gets the number of visible Items in the Container. |
void |
updateHierarchicalWrapper()
Updates the wrapper's internal hierarchy data to include all Items in the underlying container. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
ContainerHierarchicalWrapper
public ContainerHierarchicalWrapper(Container toBeWrapped)
- Parameters:
toBeWrapped
- the container that needs to be accessed hierarchically- See Also:
updateHierarchicalWrapper()
Constructs a new hierarchical wrapper for an existing Container. Works
even if the to-be-wrapped container already implements the
Container.Hierarchical
interface.
Method Detail |
---|
updateHierarchicalWrapper
public void updateHierarchicalWrapper()
Updates the wrapper's internal hierarchy data to include all Items in the underlying container. If the contents of the wrapped container change without the wrapper's knowledge, this method needs to be called to update the hierarchy information of the Items.
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
.
addItem
public Object addItem()
throws UnsupportedOperationException
- Returns:
- the autogenerated ID of the new Item or
null
if the operation failed - Throws:
UnsupportedOperationException
- if the addItem is not supported.
Creates a new Item into the Container, assigns it an automatic ID, and adds it to the hierarchy.
addItem
public Item addItem(Object itemId)
throws UnsupportedOperationException
- Parameters:
itemId
- the ID of the Item to be created.- Returns:
- the added Item or
null
if the operation failed. - Throws:
UnsupportedOperationException
- if the addItem is not supported.
Adds a new Item by its ID to the underlying container and to the hierarchy.
removeAllItems
public boolean removeAllItems()
throws UnsupportedOperationException
- Specified by:
removeAllItems
in interfaceContainer
- Returns:
true
if the operation succeeded,false
if not- Throws:
UnsupportedOperationException
- if the removeAllItems is not supported.
Removes all items from the underlying container and from the hierarcy.
removeItem
public boolean removeItem(Object itemId)
throws UnsupportedOperationException
- Specified by:
removeItem
in interfaceContainer
- Specified by:
removeItem
in interfaceContainer.Hierarchical
- Parameters:
itemId
- the ID of the Item to be removed.- Returns:
true
if the operation succeeded,false
if not- Throws:
UnsupportedOperationException
- if the removeItem is not supported.
Removes an Item specified by the itemId from the underlying container and from the hierarchy.
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.
addContainerProperty
public boolean addContainerProperty(Object propertyId,
Class<?> type,
Object defaultValue)
throws UnsupportedOperationException
- Specified by:
addContainerProperty
in interfaceContainer
- Parameters:
propertyId
- the ID of the new Property.type
- the Data type of the new Property.defaultValue
- the value all created Properties are initialized to.- Returns:
true
if the operation succeeded,false
if not- Throws:
UnsupportedOperationException
- if the addContainerProperty is not supported.
Adds a new Property to all Items in the Container.
removeContainerProperty
public boolean removeContainerProperty(Object propertyId)
throws UnsupportedOperationException
- Specified by:
removeContainerProperty
in interfaceContainer
- Parameters:
propertyId
- the ID of the Property to remove.- Returns:
true
if the operation succeeded,false
if not- Throws:
UnsupportedOperationException
- if the removeContainerProperty is not supported.
Removes the specified Property from the underlying container and from the hierarchy.
Note : The Property will be removed from all Items in the Container.
containsId
public boolean containsId(Object itemId)
- Specified by:
containsId
in interfaceContainer
- Parameters:
itemId
- ID the of Item to be tested- Returns:
- boolean indicating if the Container holds the specified Item
Description copied from interface: Container
Tests if the Container contains the specified Item. Filtering can hide items so that they will not be visible through the container API, and this method should respect visibility of items (i.e. only indicate visible items as being in the container) if feasible for the container.
getItem
public Item getItem(Object itemId)
Description copied from interface: Container
Gets the Item
with the given Item ID from the Container. If the
Container does not contain the requested Item, null
is
returned.
Containers should not return Items that are filtered out.
getItemIds
public Collection<?> getItemIds()
- Specified by:
getItemIds
in interfaceContainer
- Returns:
- unmodifiable collection of Item IDs
Description copied from interface: Container
Gets the ID's of all visible (after filtering and sorting) Items stored
in the Container. The ID's cannot be modified through the returned
collection.
If the container is Container.Ordered
, the collection returned by this
method should follow that order. If the container is Container.Sortable
,
the items should be in the sorted order.
Calling this method for large lazy containers can be an expensive
operation and should be avoided when practical.
getContainerProperty
public Property getContainerProperty(Object itemId,
Object propertyId)
- Specified by:
getContainerProperty
in interfaceContainer
- Parameters:
itemId
- ID of the visible Item which contains the PropertypropertyId
- ID of the Property to retrieve- Returns:
- Property with the given ID or
null
Description copied from interface: Container
Gets the Property identified by the given itemId and propertyId from the
Container. If the Container does not contain the item or it is filtered
out, or the Container does not have the Property, null
is
returned.
getContainerPropertyIds
public Collection<?> getContainerPropertyIds()
- Specified by:
getContainerPropertyIds
in interfaceContainer
- Returns:
- unmodifiable collection of Property IDs
Description copied from interface: Container
Gets the ID's of all Properties stored in the Container. The ID's cannot be modified through the returned collection.
getType
public Class<?> getType(Object propertyId)
- Parameters:
propertyId
- ID identifying the Properties- Returns:
- data type of the Properties
Description copied from interface: Container
Gets the data type of all Properties identified by the given Property ID.
size
public int size()
- Returns:
- number of Items in the Container
Description copied from interface: Container
Gets the number of visible Items in the Container. Filtering can hide items so that they will not be visible through the container API.
addListener
public void addListener(Container.ItemSetChangeListener listener)
- Specified by:
addListener
in interfaceContainer.ItemSetChangeNotifier
- Parameters:
listener
- listener to be added
Description copied from interface: Container.ItemSetChangeNotifier
Adds an Item set change listener for the object.
removeListener
public void removeListener(Container.ItemSetChangeListener listener)
- Specified by:
removeListener
in interfaceContainer.ItemSetChangeNotifier
- Parameters:
listener
- listener to be removed
Description copied from interface: Container.ItemSetChangeNotifier
Removes the Item set change listener from the object.
addListener
public void addListener(Container.PropertySetChangeListener listener)
- Specified by:
addListener
in interfaceContainer.PropertySetChangeNotifier
- Parameters:
listener
- The new Listener to be registered
Description copied from interface: Container.PropertySetChangeNotifier
Registers a new Property set change listener for this Container.
removeListener
public void removeListener(Container.PropertySetChangeListener listener)
- Specified by:
removeListener
in interfaceContainer.PropertySetChangeNotifier
- Parameters:
listener
- Listener to be removed
Description copied from interface: Container.PropertySetChangeNotifier
Removes a previously registered Property set change listener.