org.millstone.base.data.util
Class HierarchicalContainer

java.lang.Object
  |
  +--org.millstone.base.data.util.IndexedContainer
        |
        +--org.millstone.base.data.util.HierarchicalContainer
All Implemented Interfaces:
Container, Container.Hierarchical, Container.Indexed, Container.ItemSetChangeNotifier, Container.Ordered, Container.PropertySetChangeNotifier, Property.ValueChangeNotifier

public class HierarchicalContainer
extends IndexedContainer
implements Container.Hierarchical

A specialized Container whose contents can be accessed like it was a tree-like structure.

Since:
3.0
Version:
3.0.3
Author:
IT Mill Ltd.

Nested Class Summary
 
Nested classes inherited from class org.millstone.base.data.Container
Container.Editor, Container.Hierarchical, Container.Indexed, Container.ItemSetChangeEvent, Container.ItemSetChangeListener, Container.ItemSetChangeNotifier, Container.Ordered, Container.PropertySetChangeEvent, Container.PropertySetChangeListener, Container.PropertySetChangeNotifier, Container.Viewer
 
Field Summary
 
Fields inherited from interface org.millstone.base.data.Container
NULL_ITEM_ID
 
Constructor Summary
HierarchicalContainer()
           
 
Method Summary
 java.lang.Object addItem()
          Creates a new Item into the Container, and assign it an automatic ID.
 Item addItem(java.lang.Object itemId)
          Creates a new Item with the given ID into the Container.
 boolean areChildrenAllowed(java.lang.Object itemId)
          Tests if the Item with given ID can have any children.
 java.util.Collection getChildren(java.lang.Object itemId)
          Gets the IDs of all Items that are children of the specified Item.
 java.lang.Object getParent(java.lang.Object itemId)
          Gets the ID of the parent Item of the specified Item.
 boolean hasChildren(java.lang.Object itemId)
          Tests if the Item specified with itemId has any child Items, that is, is it a leaf Item.
 boolean isRoot(java.lang.Object itemId)
          Tests if the Item specified with itemId is a root Item.
 boolean removeAllItems()
          Removes all Items from the Container.
 boolean removeItem(java.lang.Object itemId)
          Removes the Item identified by ItemId from the Container.
 java.util.Collection rootItemIds()
          Gets the IDs of all Items in the container that don't have a parent.
 boolean setChildrenAllowed(java.lang.Object itemId, boolean childrenAllowed)
          Sets the given Item's capability to have children.
 boolean setParent(java.lang.Object itemId, java.lang.Object newParentId)
          Sets the parent of an Item.
 
Methods inherited from class org.millstone.base.data.util.IndexedContainer
addContainerProperty, addItemAfter, addItemAfter, addItemAt, addItemAt, addListener, addListener, addListener, containsId, firstItemId, getContainerProperty, getContainerPropertyIds, getIdByIndex, getItem, getItemIds, getType, indexOfId, isFirstId, isLastId, lastItemId, nextItemId, prevItemId, removeContainerProperty, removeListener, removeListener, removeListener, size
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.millstone.base.data.Container
addContainerProperty, containsId, getContainerProperty, getContainerPropertyIds, getItem, getItemIds, getType, removeContainerProperty, size
 

Constructor Detail

HierarchicalContainer

public HierarchicalContainer()
Method Detail

areChildrenAllowed

public boolean areChildrenAllowed(java.lang.Object itemId)
Description copied from interface: Container.Hierarchical
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.

Specified by:
areChildrenAllowed in interface Container.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.

getChildren

public java.util.Collection getChildren(java.lang.Object itemId)
Description copied from interface: Container.Hierarchical
Gets the IDs of all Items that are children of the specified Item. The returned collection is unmodifiable.

Specified by:
getChildren in interface Container.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

getParent

public java.lang.Object getParent(java.lang.Object itemId)
Description copied from interface: Container.Hierarchical
Gets the ID of the parent Item of the specified Item.

Specified by:
getParent in interface Container.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.

hasChildren

public boolean hasChildren(java.lang.Object itemId)
Description copied from interface: Container.Hierarchical

Tests if the Item specified with itemId has any child Items, that is, is it a leaf Item. 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.

.

Specified by:
hasChildren in interface Container.Hierarchical
Parameters:
itemId - ID of the Item whose leaf status is to be tested
Returns:
true if the specified Item is a leaf, false if not

isRoot

public boolean isRoot(java.lang.Object itemId)
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.

Specified by:
isRoot in interface Container.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

rootItemIds

public java.util.Collection rootItemIds()
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.

Specified by:
rootItemIds in interface Container.Hierarchical
Returns:
An unmodifiable collection containing IDs of all root elements of the container

setChildrenAllowed

public boolean setChildrenAllowed(java.lang.Object itemId,
                                  boolean childrenAllowed)

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(Object itemId, Object newParentId) or Container.removeItem(Object itemId).

Specified by:
setChildrenAllowed in interface Container.Hierarchical
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
Returns:
true if the operation succeeded, false if not

setParent

public boolean setParent(java.lang.Object itemId,
                         java.lang.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 parent null.

Specified by:
setParent in interface Container.Hierarchical
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
Returns:
true if the operation succeeded, false if not

addItem

public java.lang.Object addItem()
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 getItem method to fetch the Item.

This functionality is optional.

Specified by:
addItem in interface Container
Overrides:
addItem in class IndexedContainer
Returns:
ID of the newly created Item, or null in case of a failure
See Also:
Container.addItem()

addItem

public Item addItem(java.lang.Object itemId)
Description copied from interface: Container
Creates a new Item with the given ID into 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.

Specified by:
addItem in interface Container
Overrides:
addItem in class IndexedContainer
Parameters:
itemId - ID of the Item to be created
Returns:
Created new Item, or null in case of a failure
See Also:
Container.addItem(Object)

removeAllItems

public boolean removeAllItems()
Description copied from interface: Container
Removes all Items from the Container.

Note that Property ID and type information is preserved. This functionality is optional.

Specified by:
removeAllItems in interface Container
Overrides:
removeAllItems in class IndexedContainer
Returns:
true if the operation succeeded, false if not
See Also:
Container.removeAllItems()

removeItem

public boolean removeItem(java.lang.Object itemId)
Description copied from interface: Container
Removes the Item identified by ItemId from the Container. This functionality is optional.

Specified by:
removeItem in interface Container
Overrides:
removeItem in class IndexedContainer
Parameters:
itemId - ID of the Item to remove
Returns:
true if the operation succeeded, false if not
See Also:
Container.removeItem(Object)


Copyright © 2000,2001,2002 IT Mill Ltd. All Rights Reserved.