com.vaadin.data.util
Class IndexedContainer

java.lang.Object
  extended by com.vaadin.data.util.IndexedContainer
All Implemented Interfaces:
Container, Container.Filterable, Container.Indexed, Container.ItemSetChangeNotifier, Container.Ordered, Container.PropertySetChangeNotifier, Container.Sortable, Property.ValueChangeNotifier, Serializable, Cloneable
Direct Known Subclasses:
HierarchicalContainer

public class IndexedContainer
extends Object
implements Container.Indexed, Container.ItemSetChangeNotifier, Container.PropertySetChangeNotifier, Property.ValueChangeNotifier, Container.Sortable, Cloneable, Container.Filterable

An implementation of the Container.Indexed interface with all important features.

Features:

Since:
3.0
Version:
6.3.3
Author:
IT Mill Ltd.
See Also:
Container, Serialized Form

Nested Class Summary
 class IndexedContainer.ItemSetChangeEvent
          An event object specifying the list whose Item set has changed.
 
Nested classes/interfaces inherited from interface com.vaadin.data.Container
Container.Editor, Container.Filterable, Container.Hierarchical, Container.Indexed, Container.ItemSetChangeListener, Container.ItemSetChangeNotifier, Container.Ordered, Container.PropertySetChangeListener, Container.PropertySetChangeNotifier, Container.Sortable, Container.Viewer
 
Nested classes/interfaces inherited from interface com.vaadin.data.Container
Container.Editor, Container.Filterable, Container.Hierarchical, Container.Indexed, Container.ItemSetChangeListener, Container.ItemSetChangeNotifier, Container.Ordered, Container.PropertySetChangeListener, Container.PropertySetChangeNotifier, Container.Sortable, Container.Viewer
 
Constructor Summary
IndexedContainer()
           
IndexedContainer(Collection itemIds)
           
 
Method Summary
 void addContainerFilter(Object propertyId, String filterString, boolean ignoreCase, boolean onlyMatchPrefix)
          Add a filter for given property.
 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, and assign it an automatic ID.
 Item addItem(Object itemId)
          Creates a new Item with the given ID into the Container.
 Object addItemAfter(Object previousItemId)
          Adds new item after the given item.
 Item addItemAfter(Object previousItemId, Object newItemId)
          Adds new item after the given item.
 Object addItemAt(int index)
          Adds new item at given index.
 Item addItemAt(int index, Object newItemId)
          Adds new item at given index.
 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.
 void addListener(Property.ValueChangeListener listener)
          Registers a new value change listener for this Property.
 Object clone()
          Supports cloning of the IndexedContainer cleanly.
 boolean containsId(Object itemId)
          Tests if the Container contains the specified Item
protected  boolean doFilterContainer(boolean hasFilters)
          Filters the data in the container and updates internal data structures.
protected  void doSort()
          Perform the sorting of the data structures in the container.
protected  void fireContentsChange(int addedItemIndex)
          Sends Item set change event to all registered interested listeners.
 Object firstItemId()
          Gets the ID of the first Item in the Container.
 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.
 Object getIdByIndex(int index)
          Gets the ID of an Item by an index number.
 Item getItem(Object itemId)
          Gets the Item with the given Item ID from the Container.
 Collection getItemIds()
          Gets the ID's of all Items stored in the Container.
 ItemSorter getItemSorter()
          Returns the ItemSorter used for comparing items in a sort.
 Collection<?> getSortableContainerPropertyIds()
          Gets the container property IDs, which can be used to sort the item.
 Class getType(Object propertyId)
          Gets the type of a Property stored in the list.
 int indexOfId(Object itemId)
          Gets the index of the Item corresponding to the itemId.
 boolean isFirstId(Object itemId)
          Tests if the Item corresponding to the given Item ID is the first Item in the Container.
 boolean isLastId(Object itemId)
          Tests if the Item corresponding to the given Item ID is the last Item in the Container.
 Object lastItemId()
          Gets the ID of the last Item in the Container..
 Object nextItemId(Object itemId)
          Gets the ID of the Item following the Item that corresponds to itemId.
protected  boolean passesFilters(Object itemId)
          Checks if the given itemId passes the filters set for the container.
 Object prevItemId(Object itemId)
          Gets the ID of the Item preceding the Item that corresponds to itemId.
 void removeAllContainerFilters()
          Remove all filters from all properties.
 boolean removeAllItems()
          Removes all Items from the Container.
 void removeContainerFilters(Object propertyId)
          Remove all filters from given property.
 boolean removeContainerProperty(Object propertyId)
          Removes a Property specified by the given Property ID from the Container.
 boolean removeItem(Object itemId)
          Removes the Item identified by ItemId from the Container.
 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.
 void removeListener(Property.ValueChangeListener listener)
          Removes a previously registered value change listener.
 void setItemSorter(ItemSorter itemSorter)
          Sets the ItemSorter used for comparing items in a sort.
 int size()
          Gets the number of Items in the Container.
 void sort(Object[] propertyId, boolean[] ascending)
          Sort method.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IndexedContainer

public IndexedContainer()

IndexedContainer

public IndexedContainer(Collection itemIds)
Method Detail

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.

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

getContainerPropertyIds

public 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 Class getType(Object propertyId)
Gets the type of a Property stored in the list.

Specified by:
getType in interface Container
Parameters:
id - the ID of the Property.
Returns:
Type of the requested Property

getContainerProperty

public Property getContainerProperty(Object itemId,
                                     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

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

containsId

public boolean containsId(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

addContainerProperty

public boolean addContainerProperty(Object propertyId,
                                    Class<?> type,
                                    Object defaultValue)
Description copied from interface: Container
Adds a new Property to all Items in the Container. The Property ID, data type and default value of the new Property are given as parameters. This functionality is optional.

Specified by:
addContainerProperty in interface Container
Parameters:
propertyId - ID of the 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

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
Returns:
true if the operation succeeded, false if not

addItem

public 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 getItemmethod to fetch the Item.

This functionality is optional.

Specified by:
addItem in interface Container
Returns:
ID of the newly created Item, or null in case of a failure

addItem

public Item addItem(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
Parameters:
itemId - ID of the Item to be created
Returns:
Created new Item, or null in case of a failure

removeItem

public boolean removeItem(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
Parameters:
itemId - ID of the Item to remove
Returns:
true if the operation succeeded, false if not

removeContainerProperty

public boolean removeContainerProperty(Object propertyId)
Description copied from interface: Container
Removes a Property specified by the given Property ID from the Container. Note that the Property will be removed from all Items in the Container. This functionality is optional.

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

firstItemId

public 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

lastItemId

public 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 Object nextItemId(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 Object prevItemId(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

isFirstId

public boolean isFirstId(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(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

addItemAfter

public Item addItemAfter(Object previousItemId,
                         Object newItemId)
Description copied from interface: Container.Ordered
Adds 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.

addItemAfter

public Object addItemAfter(Object previousItemId)
Description copied from interface: Container.Ordered
Adds 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.

getIdByIndex

public Object getIdByIndex(int index)
Description copied from interface: Container.Indexed
Gets the ID of an Item by an index number.

Specified by:
getIdByIndex in interface Container.Indexed
Parameters:
index - Index of the requested id in the Container
Returns:
ID of the Item in the given index

indexOfId

public int indexOfId(Object itemId)
Description copied from interface: Container.Indexed
Gets the index of the Item corresponding to the itemId. The following is true for the returned index: 0 <= index < size().

Specified by:
indexOfId in interface Container.Indexed
Parameters:
itemId - ID of an Item in the Container
Returns:
index of the Item, or -1 if the Container does not include the Item

addItemAt

public Item addItemAt(int index,
                      Object newItemId)
Description copied from interface: Container.Indexed
Adds new item at given index.

The indexes of the item currently in the given position and all the following items are incremented.

Specified by:
addItemAt in interface Container.Indexed
Parameters:
index - Index to add the new item.
newItemId - Id of the new item to be added.
Returns:
Returns new item or null if the operation fails.

addItemAt

public Object addItemAt(int index)
Description copied from interface: Container.Indexed
Adds new item at given index.

The indexes of the item currently in the given position and all the following items are incremented.

Specified by:
addItemAt in interface Container.Indexed
Parameters:
index - Index to add the new item.
Returns:
Returns item id the the created new item or null if the operation fails.

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

addListener

public void addListener(Container.ItemSetChangeListener listener)
Description copied from interface: Container.ItemSetChangeNotifier
Adds an 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 the Item set change listener from the object.

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

addListener

public void addListener(Property.ValueChangeListener listener)
Description copied from interface: Property.ValueChangeNotifier
Registers a new value change listener for this Property.

Specified by:
addListener in interface Property.ValueChangeNotifier
Parameters:
listener - the new Listener to be registered

removeListener

public void removeListener(Property.ValueChangeListener listener)
Description copied from interface: Property.ValueChangeNotifier
Removes a previously registered value change listener.

Specified by:
removeListener in interface Property.ValueChangeNotifier
Parameters:
listener - listener to be removed

fireContentsChange

protected void fireContentsChange(int addedItemIndex)
Sends Item set change event to all registered interested listeners.

Parameters:
addedItemIndex - index of new item if change event was an item addition

sort

public void sort(Object[] propertyId,
                 boolean[] ascending)
Description copied from interface: Container.Sortable
Sort method. Sorts the container items.

Specified by:
sort in interface Container.Sortable
Parameters:
propertyId - Array of container property IDs, which values are used to sort the items in container as primary, secondary, ... sorting criterion. All of the item IDs must be in the collection returned by getSortableContainerPropertyIds
ascending - Array of sorting order flags corresponding to each property ID used in sorting. If this array is shorter than propertyId array, ascending order is assumed for items where the order is not specified. Use true to sort in ascending order, false to use descending order.

doSort

protected void doSort()
Perform the sorting of the data structures in the container. This is invoked when the itemSorter has been prepared for the sort operation. Typically this method calls Collections.sort(aCollection, getItemSorter()) on all arrays (containing item ids) that need to be sorted.


getSortableContainerPropertyIds

public Collection<?> getSortableContainerPropertyIds()
Description copied from interface: Container.Sortable
Gets the container property IDs, which can be used to sort the item.

Specified by:
getSortableContainerPropertyIds in interface Container.Sortable
Returns:
The sortable field ids.

getItemSorter

public ItemSorter getItemSorter()
Returns the ItemSorter used for comparing items in a sort. See setItemSorter(ItemSorter) for more information.

Returns:
The ItemSorter used for comparing two items in a sort.

setItemSorter

public void setItemSorter(ItemSorter itemSorter)
Sets the ItemSorter used for comparing items in a sort. The ItemSorter is called for each collection that needs sorting. A default ItemSorter is used if this is not explicitly set.

Parameters:
itemSorter - The ItemSorter used for comparing two items in a sort.

clone

public Object clone()
             throws CloneNotSupportedException
Supports cloning of the IndexedContainer cleanly.

Overrides:
clone in class Object
Throws:
CloneNotSupportedException - if an object cannot be cloned. .

addContainerFilter

public void addContainerFilter(Object propertyId,
                               String filterString,
                               boolean ignoreCase,
                               boolean onlyMatchPrefix)
Description copied from interface: Container.Filterable
Add a filter for given property. Only items where given property for which toString() contains or starts with given filterString are visible in the container.

Specified by:
addContainerFilter in interface Container.Filterable
Parameters:
propertyId - Property for which the filter is applied to.
filterString - String that must match contents of the property
ignoreCase - Determine if the casing can be ignored when comparing strings.
onlyMatchPrefix - Only match prefixes; no other matches are included.

removeAllContainerFilters

public void removeAllContainerFilters()
Description copied from interface: Container.Filterable
Remove all filters from all properties.

Specified by:
removeAllContainerFilters in interface Container.Filterable

removeContainerFilters

public void removeContainerFilters(Object propertyId)
Description copied from interface: Container.Filterable
Remove all filters from given property.

Specified by:
removeContainerFilters in interface Container.Filterable

doFilterContainer

protected boolean doFilterContainer(boolean hasFilters)
Filters the data in the container and updates internal data structures. This method should reset any internal data structures and then repopulate them so getItemIds() and other methods only return the filtered items.

Parameters:
hasFilters - true if filters has been set for the container, false otherwise
Returns:
true if the item set has changed as a result of the filtering

passesFilters

protected boolean passesFilters(Object itemId)
Checks if the given itemId passes the filters set for the container. The caller should make sure the itemId exists in the container. For non-existing itemIds the behavior is undefined.

Parameters:
itemId - An itemId that exists in the container.
Returns:
true if the itemId passes all filters or no filters are set, false otherwise.


Copyright © 2000-2010 IT Mill Ltd. All Rights Reserved.