Class ContainerHierarchicalWrapper

A wrapper class for adding external hierarchy to containers not implementing the com.itmill.toolkit.data.Container.Hierarchical interface.

If the wrapped container is changed directly (that is, not through the wrapper), the hierarchy information must be updated with the updateHierarchicalWrapper() method.

Synopsis

Since

3.0

Inheritance Path.  java.lang.Object-> com.itmill.toolkit.data.util.ContainerHierarchicalWrapper

ContainerHierarchicalWrapper(Container)

Parameters

toBeWrapped

the container that needs to be accessed hierarchically

Constructs a new hierarchical wrapper for an existing Container. Works even if the to-be-wrapped container already implements the Container.Hierarchical interface.

addContainerProperty(Object, Class, Object)

Parameters

propertyId

ID of the new Property

type

Data type of the new Property

defaultValue

The value all created Properties are initialized to

return

true if the operation succeeded, false if not

Adds a new Property to all Items in the Container.

addItem()

Parameters

return

the autogenerated ID of the new Item or null if the operation failed

Creates a new Item into the Container, assigns it an automatic ID, and adds it to the hierarchy.

addItem(Object)

Parameters

return

the added Item or null if the operation failed

Adds a new Item by its ID to the underlying container and to the hierarchy.

addListener(Container.ItemSetChangeListener)

Parameters

listener

listener to be added

Description copied from interface: addListener

Adds a Item set change listener for the object.

addListener(Container.PropertySetChangeListener)

Parameters

listener

The new Listener to be registered

Description copied from interface: addListener

Registers a new Property set change listener for this Container.

areChildrenAllowed(Object)

Parameters

itemId

ID of the Item in the container whose child capability is to be tested

return

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: areChildrenAllowed

Tests if the Item with given ID can have any children. If the Container also implements the Managed interface, the items created with newItem can have children by default.

getChildren(Object)

Parameters

itemId

ID of the Item whose children the caller is interested in

return

An unmodifiable collection containing the IDs of all other Items that are children in the container hierarchy

Description copied from interface: getChildren

Gets the IDs of all Items that are children of the specified Item. The returned collection is unmodifiable.

getParent(Object)

Parameters

itemId

ID of the Item whose parent the caller wishes to find out.

return

the ID of the parent Item. Will be null if the specified Item is a root element.

Description copied from interface: getParent

Gets the ID of the parent Item of the specified Item.

hasChildren(Object)

Parameters

itemId

ID of the Item whose leaf status is to be tested

return

true if the specified Item is a leaf, false if not

Description copied from interface: hasChildren

Tests if the Item specified with itemId has any child Items, that is, is it a leaf Item. The getChildren(java.lang.Object) 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(Object)

Parameters

itemId

ID of the Item whose root status is to be tested

return

true if the specified Item is a root, false if not

Description copied from interface: isRoot

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 getParent(java.lang.Object) method always returns null for root Items.

removeAllItems()

Parameters

return

true if the operation succeeded, false if not

Removes all items from the underlying container and from the hierarcy.

removeContainerProperty(Object)

Parameters

propertyId

ID of the Property to remove

return

true if the operation succeeded, false if not

Removes the specified Property from the underlying container and from the hierarchy. Note that the Property will be removed from all Items in the Container.

removeItem(Object)

Parameters

return

true if the operation succeeded, false if not

Removes an Item specified by itemId from the underlying container and from the hierarcy.

removeListener(Container.ItemSetChangeListener)

Parameters

listener

listener to be removed

Description copied from interface: removeListener

Removes a Item set change listener from the object.

removeListener(Container.PropertySetChangeListener)

Parameters

listener

Listener to be removed

Description copied from interface: removeListener

Removes a previously registered Property set change listener.

rootItemIds()

Parameters

return

An unmodifiable collection containing IDs of all root elements of the container

Description copied from interface: rootItemIds

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(Object, boolean)

Parameters

itemId

ID of the Item in the container whose child capability is to be set

childrenAllowed

boolean value specifying if the Item can have children or not

return

true if the operation succeeded, false if not

Sets the given Item's capability to have children. If the Item identified with itemId already has children and areChildrenAllowed is false this method fails and false is returned; the children must be first explicitly removed with setParent(java.lang.Object, java.lang.Object) or removeItem(java.lang.Object) .

setParent(Object, Object)

Parameters

itemId

ID of the item to be set as the child of the Item identified with newParentId

newParentId

ID of the Item that's to be the new parent of the Item identified with itemId

return

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 .

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.