Class ContainerHierarchicalWrapper
- java.lang.Object
-
- com.vaadin.data.util.ContainerHierarchicalWrapper
-
- All Implemented Interfaces:
Container,Container.Hierarchical,Container.ItemSetChangeNotifier,Container.PropertySetChangeNotifier,Serializable
public class ContainerHierarchicalWrapper extends Object implements Container.Hierarchical, Container.ItemSetChangeNotifier, Container.PropertySetChangeNotifier
A wrapper class for adding external hierarchy to containers not implementing the
Container.Hierarchicalinterface.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
- Author:
- Vaadin Ltd.
- See Also:
- Serialized Form
-
-
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
Constructors Constructor Description ContainerHierarchicalWrapper(Container toBeWrapped)Constructs a new hierarchical wrapper for an existing Container.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleanaddContainerProperty(Object propertyId, Class<?> type, Object defaultValue)Adds a new Property to all Items in the Container.ObjectaddItem()Creates a new Item into the Container, assigns it an automatic ID, and adds it to the hierarchy.ItemaddItem(Object itemId)Adds a new Item by its ID to the underlying container and to the hierarchy.voidaddItemSetChangeListener(Container.ItemSetChangeListener listener)Adds an Item set change listener for the object.voidaddListener(Container.ItemSetChangeListener listener)Deprecated.As of 7.0, replaced byaddItemSetChangeListener(Container.ItemSetChangeListener)voidaddListener(Container.PropertySetChangeListener listener)Deprecated.As of 7.0, replaced byaddPropertySetChangeListener(Container.PropertySetChangeListener)voidaddPropertySetChangeListener(Container.PropertySetChangeListener listener)Registers a new Property set change listener for this Container.booleanareChildrenAllowed(Object itemId)Tests if the Item with given ID can have children.booleancontainsId(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.PropertygetContainerProperty(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.ItemgetItem(Object itemId)Gets theItemwith 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.ObjectgetParent(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.booleanhasChildren(Object itemId)Tests if the Item specified withitemIdhas child Items or if it is a leaf.booleanisRoot(Object itemId)Tests if the Item specified withitemIdis a root Item.booleanremoveAllItems()Removes all items from the underlying container and from the hierarcy.booleanremoveContainerProperty(Object propertyId)Removes the specified Property from the underlying container and from the hierarchy.booleanremoveItem(Object itemId)Removes an Item specified by the itemId from the underlying container and from the hierarchy.booleanremoveItemRecursively(Object itemId)Removes the Item identified by given itemId and all its children.voidremoveItemSetChangeListener(Container.ItemSetChangeListener listener)Removes the Item set change listener from the object.voidremoveListener(Container.ItemSetChangeListener listener)Deprecated.As of 7.0, replaced byremoveItemSetChangeListener(Container.ItemSetChangeListener)voidremoveListener(Container.PropertySetChangeListener listener)Deprecated.As of 7.0, replaced byremovePropertySetChangeListener(Container.PropertySetChangeListener)voidremovePropertySetChangeListener(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.booleansetChildrenAllowed(Object itemId, boolean childrenAllowed)Sets the given Item's capability to have children.booleansetParent(Object itemId, Object newParentId)Sets the parent of an Item.intsize()Gets the number of visible Items in the Container.voidupdateHierarchicalWrapper()Updates the wrapper's internal hierarchy data to include all Items in the underlying container.
-
-
-
Constructor Detail
-
ContainerHierarchicalWrapper
public ContainerHierarchicalWrapper(Container toBeWrapped)
Constructs a new hierarchical wrapper for an existing Container. Works even if the to-be-wrapped container already implements theContainer.Hierarchicalinterface.- Parameters:
toBeWrapped- the container that needs to be accessed hierarchically- See Also:
updateHierarchicalWrapper()
-
-
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)
Description copied from interface:Container.HierarchicalTests if the Item with given ID can have children.- Specified by:
areChildrenAllowedin interfaceContainer.Hierarchical- Parameters:
itemId- ID of the Item in the container whose child capability is to be tested- Returns:
trueif the specified Item exists in the Container and it can have children,falseif it's not found from the container or it can't have children.
-
getChildren
public Collection<?> getChildren(Object itemId)
Description copied from interface:Container.HierarchicalGets the IDs of all Items that are children of the specified Item. The returned collection is unmodifiable.- Specified by:
getChildrenin interfaceContainer.Hierarchical- Parameters:
itemId- ID of the Item whose children the caller is interested in- Returns:
- An unmodifiable
collectioncontaining the IDs of all other Items that are children in the container hierarchy;nullif item does not have any children.
-
getParent
public Object getParent(Object itemId)
Description copied from interface:Container.HierarchicalGets the ID of the parent Item of the specified Item.- Specified by:
getParentin 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
nullif the specified Item is a root element.
-
hasChildren
public boolean hasChildren(Object itemId)
Description copied from interface:Container.HierarchicalTests if the Item specified with
itemIdhas child Items or if it is a leaf. TheContainer.Hierarchical.getChildren(Object itemId)method always returnsnullfor leaf Items.Note that being a leaf does not imply whether or not an Item is allowed to have children.
- Specified by:
hasChildrenin interfaceContainer.Hierarchical- Parameters:
itemId- ID of the Item to be tested- Returns:
trueif the specified Item has children,falseif not (is a leaf)
-
isRoot
public boolean isRoot(Object itemId)
Description copied from interface:Container.HierarchicalTests if the Item specified withitemIdis a root Item. The hierarchical container can have more than one root and must have at least one unless it is empty. TheContainer.Hierarchical.getParent(Object itemId)method always returnsnullfor root Items.- Specified by:
isRootin interfaceContainer.Hierarchical- Parameters:
itemId- ID of the Item whose root status is to be tested- Returns:
trueif the specified Item is a root,falseif not
-
rootItemIds
public Collection<?> rootItemIds()
Description copied from interface:Container.HierarchicalGets the IDs of all Items in the container that don't have a parent. Such items are calledrootItems. The returned collection is unmodifiable.- Specified by:
rootItemIdsin interfaceContainer.Hierarchical- Returns:
- An unmodifiable
collectioncontaining IDs of all root elements of the container
-
setChildrenAllowed
public boolean setChildrenAllowed(Object itemId, boolean childrenAllowed)
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
falseis returned; the children must be first explicitly removed withsetParent(Object itemId, Object newParentId)orContainer.removeItem(Object itemId).- Specified by:
setChildrenAllowedin 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:
trueif the operation succeeded,falseif not
-
setParent
public boolean setParent(Object itemId, Object newParentId)
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 parentnull.- Specified by:
setParentin 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:
trueif the operation succeeded,falseif not
-
addItem
public Object addItem() throws UnsupportedOperationException
Creates a new Item into the Container, assigns it an automatic ID, and adds it to the hierarchy.- Specified by:
addItemin interfaceContainer- Returns:
- the autogenerated ID of the new Item or
nullif the operation failed - Throws:
UnsupportedOperationException- if the addItem is not supported.
-
addItem
public Item addItem(Object itemId) throws UnsupportedOperationException
Adds a new Item by its ID to the underlying container and to the hierarchy.- Specified by:
addItemin interfaceContainer- Parameters:
itemId- the ID of the Item to be created.- Returns:
- the added Item or
nullif the operation failed. - Throws:
UnsupportedOperationException- if the addItem is not supported.
-
removeAllItems
public boolean removeAllItems() throws UnsupportedOperationExceptionRemoves all items from the underlying container and from the hierarcy.- Specified by:
removeAllItemsin interfaceContainer- Returns:
trueif the operation succeeded,falseif not- Throws:
UnsupportedOperationException- if the removeAllItems is not supported.
-
removeItem
public boolean removeItem(Object itemId) throws UnsupportedOperationException
Removes an Item specified by the itemId from the underlying container and from the hierarchy.- Specified by:
removeItemin interfaceContainer- Specified by:
removeItemin interfaceContainer.Hierarchical- Parameters:
itemId- the ID of the Item to be removed.- Returns:
trueif the operation succeeded,falseif not- Throws:
UnsupportedOperationException- if the removeItem is not supported.
-
removeItemRecursively
public boolean removeItemRecursively(Object itemId)
Removes the Item identified by given itemId and all its children.- Parameters:
itemId- the identifier of the Item to be removed- Returns:
- true if the operation succeeded
- See Also:
removeItem(Object)
-
addContainerProperty
public boolean addContainerProperty(Object propertyId, Class<?> type, Object defaultValue) throws UnsupportedOperationException
Adds a new Property to all Items in the Container.- Specified by:
addContainerPropertyin 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:
trueif the operation succeeded,falseif not- Throws:
UnsupportedOperationException- if the addContainerProperty is not supported.
-
removeContainerProperty
public boolean removeContainerProperty(Object propertyId) throws UnsupportedOperationException
Removes the specified Property from the underlying container and from the hierarchy.Note : The Property will be removed from all Items in the Container.
- Specified by:
removeContainerPropertyin interfaceContainer- Parameters:
propertyId- the ID of the Property to remove.- Returns:
trueif the operation succeeded,falseif not- Throws:
UnsupportedOperationException- if the removeContainerProperty is not supported.
-
containsId
public boolean containsId(Object itemId)
Description copied from interface:ContainerTests 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.
- Specified by:
containsIdin interfaceContainer- Parameters:
itemId- ID the of Item to be tested- Returns:
- boolean indicating if the Container holds the specified Item
-
getItem
public Item getItem(Object itemId)
Description copied from interface:ContainerGets theItemwith the given Item ID from the Container. If the Container does not contain the requested Item,nullis returned.Containers should not return Items that are filtered out.
-
getItemIds
public Collection<?> getItemIds()
Description copied from interface:ContainerGets 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 isContainer.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.
- Specified by:
getItemIdsin interfaceContainer- Returns:
- unmodifiable collection of Item IDs
-
getContainerProperty
public Property getContainerProperty(Object itemId, Object propertyId)
Description copied from interface:ContainerGets 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,nullis returned.- Specified by:
getContainerPropertyin 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
-
getContainerPropertyIds
public Collection<?> getContainerPropertyIds()
Description copied from interface:ContainerGets the ID's of all Properties stored in the Container. The ID's cannot be modified through the returned collection.- Specified by:
getContainerPropertyIdsin interfaceContainer- Returns:
- unmodifiable collection of Property IDs
-
getType
public Class<?> getType(Object propertyId)
Description copied from interface:ContainerGets the data type of all Properties identified by the given Property ID.
-
size
public int size()
Description copied from interface:ContainerGets the number of visible Items in the Container.Filtering can hide items so that they will not be visible through the container API.
-
addItemSetChangeListener
public void addItemSetChangeListener(Container.ItemSetChangeListener listener)
Description copied from interface:Container.ItemSetChangeNotifierAdds an Item set change listener for the object.- Specified by:
addItemSetChangeListenerin interfaceContainer.ItemSetChangeNotifier- Parameters:
listener- listener to be added
-
addListener
@Deprecated public void addListener(Container.ItemSetChangeListener listener)
Deprecated.As of 7.0, replaced byaddItemSetChangeListener(Container.ItemSetChangeListener)- Specified by:
addListenerin interfaceContainer.ItemSetChangeNotifier
-
removeItemSetChangeListener
public void removeItemSetChangeListener(Container.ItemSetChangeListener listener)
Description copied from interface:Container.ItemSetChangeNotifierRemoves the Item set change listener from the object.- Specified by:
removeItemSetChangeListenerin interfaceContainer.ItemSetChangeNotifier- Parameters:
listener- listener to be removed
-
removeListener
@Deprecated public void removeListener(Container.ItemSetChangeListener listener)
Deprecated.As of 7.0, replaced byremoveItemSetChangeListener(Container.ItemSetChangeListener)- Specified by:
removeListenerin interfaceContainer.ItemSetChangeNotifier
-
addPropertySetChangeListener
public void addPropertySetChangeListener(Container.PropertySetChangeListener listener)
Description copied from interface:Container.PropertySetChangeNotifierRegisters a new Property set change listener for this Container.- Specified by:
addPropertySetChangeListenerin interfaceContainer.PropertySetChangeNotifier- Parameters:
listener- The new Listener to be registered
-
addListener
@Deprecated public void addListener(Container.PropertySetChangeListener listener)
Deprecated.As of 7.0, replaced byaddPropertySetChangeListener(Container.PropertySetChangeListener)- Specified by:
addListenerin interfaceContainer.PropertySetChangeNotifier
-
removePropertySetChangeListener
public void removePropertySetChangeListener(Container.PropertySetChangeListener listener)
Description copied from interface:Container.PropertySetChangeNotifierRemoves a previously registered Property set change listener.- Specified by:
removePropertySetChangeListenerin interfaceContainer.PropertySetChangeNotifier- Parameters:
listener- Listener to be removed
-
removeListener
@Deprecated public void removeListener(Container.PropertySetChangeListener listener)
Deprecated.As of 7.0, replaced byremovePropertySetChangeListener(Container.PropertySetChangeListener)- Specified by:
removeListenerin interfaceContainer.PropertySetChangeNotifier
-
-