org.millstone.base.data.util
Class ContainerOrderedWrapper

java.lang.Object
  |
  +--org.millstone.base.data.util.ContainerOrderedWrapper
All Implemented Interfaces:
Container, Container.ItemSetChangeNotifier, Container.Ordered, Container.PropertySetChangeNotifier

public class ContainerOrderedWrapper
extends java.lang.Object
implements Container.Ordered, Container.ItemSetChangeNotifier, Container.PropertySetChangeNotifier

A wrapper class for adding external ordering to containers not implementing the Container.Ordered interface.

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

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
ContainerOrderedWrapper(Container toBeWrapped)
          Constructs a new ordered wrapper for an existing Container.
 
Method Summary
 boolean addContainerProperty(java.lang.Object propertyId, java.lang.Class type, java.lang.Object defaultValue)
          Adds a new Property to all Items in the Container.
 java.lang.Object addItem()
          Creates a new Item into the Container, assigns it an automatic ID, and adds it to the ordering.
 Item addItem(java.lang.Object itemId)
          Adds a new Item by its ID to the underlying container and to the ordering.
 java.lang.Object addItemAfter(java.lang.Object previousItemId)
          Add new item after the given item.
 Item addItemAfter(java.lang.Object previousItemId, java.lang.Object newItemId)
          Add new item after the given item.
 void addListener(Container.ItemSetChangeListener listener)
          Adds a Item set change listener for the object.
 void addListener(Container.PropertySetChangeListener listener)
          Registers a new Property set change listener for this Container.
 boolean containsId(java.lang.Object itemId)
          Tests if the Container contains the specified Item
 java.lang.Object firstItemId()
          Gets the ID of the first Item in the Container.
 Property getContainerProperty(java.lang.Object itemId, java.lang.Object propertyId)
          Gets the Property identified by the given itemId and propertyId from the Container.
 java.util.Collection getContainerPropertyIds()
          Gets the ID's of all Properties stored in the Container.
 Item getItem(java.lang.Object itemId)
          Gets the Item with the given Item ID from the Container.
 java.util.Collection getItemIds()
          Gets the ID's of all Items stored in the Container.
 java.lang.Class getType(java.lang.Object propertyId)
          Gets the data type of all Properties identified by the given Property ID.
 boolean isFirstId(java.lang.Object itemId)
          Tests if the Item corresponding to the given Item ID is the first Item in the Container.
 boolean isLastId(java.lang.Object itemId)
          Tests if the Item corresponding to the given Item ID is the last Item in the Container.
 java.lang.Object lastItemId()
          Gets the ID of the last Item in the Container..
 java.lang.Object nextItemId(java.lang.Object itemId)
          Gets the ID of the Item following the Item that corresponds to itemId.
 java.lang.Object prevItemId(java.lang.Object itemId)
          Gets the ID of the Item preceding the Item that corresponds to itemId.
 boolean removeAllItems()
          Removes all items from the underlying container and from the ordering.
 boolean removeContainerProperty(java.lang.Object propertyId)
          Removes the specified Property from the underlying container and from the ordering.
 boolean removeItem(java.lang.Object itemId)
          Removes an Item specified by itemId from the underlying container and from the ordering.
 void removeListener(Container.ItemSetChangeListener listener)
          Removes a Item set change listener from the object.
 void removeListener(Container.PropertySetChangeListener listener)
          Removes a previously registered Property set change listener.
 int size()
          Gets the number of Items in the Container.
 void updateOrderWrapper()
          Updates the wrapper's internal ordering information 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

ContainerOrderedWrapper

public ContainerOrderedWrapper(Container toBeWrapped)
Constructs a new ordered wrapper for an existing Container. Works even if the to-be-wrapped container already implements the Container.Ordered interface.

Parameters:
toBeWrapped - the container whose contents need to be ordered
Method Detail

updateOrderWrapper

public void updateOrderWrapper()
Updates the wrapper's internal ordering information 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 ordering information of the Items.


firstItemId

public java.lang.Object firstItemId()
Description copied from interface: Container.Ordered
Gets the ID of the first Item in the Container.

Specified by:
firstItemId in interface Container.Ordered
Returns:
ID of the first Item in the Container

isFirstId

public boolean isFirstId(java.lang.Object itemId)
Description copied from interface: Container.Ordered
Tests if the Item corresponding to the given Item ID is the first Item in the Container.

Specified by:
isFirstId in interface Container.Ordered
Parameters:
itemId - ID of an Item in the Container
Returns:
true if the Item is first in the Container, false if not

isLastId

public boolean isLastId(java.lang.Object itemId)
Description copied from interface: Container.Ordered
Tests if the Item corresponding to the given Item ID is the last Item in the Container.

Specified by:
isLastId in interface Container.Ordered
Returns:
true if the Item is last in the Container, false if not

lastItemId

public java.lang.Object lastItemId()
Description copied from interface: Container.Ordered
Gets the ID of the last Item in the Container..

Specified by:
lastItemId in interface Container.Ordered
Returns:
ID of the last Item in the Container

nextItemId

public java.lang.Object nextItemId(java.lang.Object itemId)
Description copied from interface: Container.Ordered
Gets the ID of the Item following the Item that corresponds to itemId. If the given Item is the last or not found in the Container, null is returned.

Specified by:
nextItemId in interface Container.Ordered
Parameters:
itemId - ID of an Item in the Container
Returns:
ID of the next Item or null

prevItemId

public java.lang.Object prevItemId(java.lang.Object itemId)
Description copied from interface: Container.Ordered
Gets the ID of the Item preceding the Item that corresponds to itemId. If the given Item is the first or not found in the Container, null is returned.

Specified by:
prevItemId in interface Container.Ordered
Parameters:
itemId - ID of an Item in the Container
Returns:
ID of the previous Item or null

addContainerProperty

public boolean addContainerProperty(java.lang.Object propertyId,
                                    java.lang.Class type,
                                    java.lang.Object defaultValue)
                             throws java.lang.UnsupportedOperationException
Adds a new Property to all Items in the Container.

Specified by:
addContainerProperty in interface Container
Parameters:
propertyId - ID of the new Property
type - Data type of the new Property
defaultValue - The value all created Properties are initialized to
Returns:
true if the operation succeeded, false if not
java.lang.UnsupportedOperationException

addItem

public java.lang.Object addItem()
                         throws java.lang.UnsupportedOperationException
Creates a new Item into the Container, assigns it an automatic ID, and adds it to the ordering.

Specified by:
addItem in interface Container
Returns:
the autogenerated ID of the new Item or null if the operation failed
java.lang.UnsupportedOperationException

addItem

public Item addItem(java.lang.Object itemId)
             throws java.lang.UnsupportedOperationException
Adds a new Item by its ID to the underlying container and to the ordering.

Specified by:
addItem in interface Container
Parameters:
itemId - ID of the Item to be created
Returns:
the added Item or null if the operation failed
java.lang.UnsupportedOperationException

removeAllItems

public boolean removeAllItems()
                       throws java.lang.UnsupportedOperationException
Removes all items from the underlying container and from the ordering.

Specified by:
removeAllItems in interface Container
Returns:
true if the operation succeeded, false if not
java.lang.UnsupportedOperationException

removeItem

public boolean removeItem(java.lang.Object itemId)
                   throws java.lang.UnsupportedOperationException
Removes an Item specified by itemId from the underlying container and from the ordering.

Specified by:
removeItem in interface Container
Parameters:
itemId - ID of the Item to remove
Returns:
true if the operation succeeded, false if not
java.lang.UnsupportedOperationException

removeContainerProperty

public boolean removeContainerProperty(java.lang.Object propertyId)
                                throws java.lang.UnsupportedOperationException
Removes the specified Property from the underlying container and from the ordering. Note that the Property will be removed from all Items in the Container.

Specified by:
removeContainerProperty in interface Container
Parameters:
propertyId - ID of the Property to remove
Returns:
true if the operation succeeded, false if not
java.lang.UnsupportedOperationException

containsId

public boolean containsId(java.lang.Object itemId)
Description copied from interface: Container
Tests if the Container contains the specified Item

Specified by:
containsId in interface Container
Parameters:
itemId - ID the of Item to be tested
Returns:
boolean indicating if the Container holds the specified Item

getItem

public Item getItem(java.lang.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.

Specified by:
getItem in interface Container
Parameters:
itemId - ID of the Item to retrieve
Returns:
the Item with the given ID or null if the Item is not found in the Container

getItemIds

public java.util.Collection getItemIds()
Description copied from interface: Container
Gets the ID's of all Items stored in the Container. The ID's are returned as a unmodifiable collection.

Specified by:
getItemIds in interface Container
Returns:
unmodifiable collection of Item IDs

getContainerProperty

public Property getContainerProperty(java.lang.Object itemId,
                                     java.lang.Object propertyId)
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 Property, null is returned.

Specified by:
getContainerProperty in interface Container
Parameters:
itemId - ID of the Item which contains the Property
propertyId - ID of the Property to retrieve
Returns:
Property with the given ID or null

getContainerPropertyIds

public java.util.Collection getContainerPropertyIds()
Description copied from interface: Container
Gets the ID's of all Properties stored in the Container. The ID's are returned as a unmodifiable collection.

Specified by:
getContainerPropertyIds in interface Container
Returns:
unmodifiable collection of Property IDs

getType

public java.lang.Class getType(java.lang.Object propertyId)
Description copied from interface: Container
Gets the data type of all Properties identified by the given Property ID.

Specified by:
getType in interface Container
Parameters:
propertyId - ID identifying the Properties
Returns:
data type of the Properties

size

public int size()
Description copied from interface: Container
Gets the number of Items in the Container.

Specified by:
size in interface Container
Returns:
number of Items in the Container

addListener

public void addListener(Container.ItemSetChangeListener listener)
Description copied from interface: Container.ItemSetChangeNotifier
Adds a Item set change listener for the object.

Specified by:
addListener in interface Container.ItemSetChangeNotifier
Parameters:
listener - listener to be added

removeListener

public void removeListener(Container.ItemSetChangeListener listener)
Description copied from interface: Container.ItemSetChangeNotifier
Removes a Item set change listener from the object.

Specified by:
removeListener in interface Container.ItemSetChangeNotifier
Parameters:
listener - listener to be removed

addListener

public void addListener(Container.PropertySetChangeListener listener)
Description copied from interface: Container.PropertySetChangeNotifier
Registers a new Property set change listener for this Container.

Specified by:
addListener in interface Container.PropertySetChangeNotifier
Parameters:
listener - The new Listener to be registered

removeListener

public void removeListener(Container.PropertySetChangeListener listener)
Description copied from interface: Container.PropertySetChangeNotifier
Removes a previously registered Property set change listener.

Specified by:
removeListener in interface Container.PropertySetChangeNotifier
Parameters:
listener - Listener to be removed

addItemAfter

public Item addItemAfter(java.lang.Object previousItemId,
                         java.lang.Object newItemId)
                  throws java.lang.UnsupportedOperationException
Description copied from interface: Container.Ordered
Add new item after the given item.

Adding an item after null item adds the item as first item of the ordered container.

Specified by:
addItemAfter in interface Container.Ordered
Parameters:
previousItemId - Id of the previous item in ordered container.
newItemId - Id of the new item to be added.
Returns:
Returns new item or null if the operation fails.
java.lang.UnsupportedOperationException
See Also:
Container.Ordered.addItemAfter(Object, Object)

addItemAfter

public java.lang.Object addItemAfter(java.lang.Object previousItemId)
                              throws java.lang.UnsupportedOperationException
Description copied from interface: Container.Ordered
Add new item after the given item.

Adding an item after null item adds the item as first item of the ordered container.

Specified by:
addItemAfter in interface Container.Ordered
Parameters:
previousItemId - Id of the previous item in ordered container.
Returns:
Returns item id the the created new item or null if the operation fails.
java.lang.UnsupportedOperationException
See Also:
Container.Ordered.addItemAfter(Object)


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