com.vaadin.data.util
Class IndexedContainer

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

public class IndexedContainer
extends AbstractInMemoryContainer<java.lang.Object,java.lang.Object,Item>
implements Container.PropertySetChangeNotifier, Property.ValueChangeNotifier, Container.Sortable, java.lang.Cloneable, Container.Filterable, Container.SimpleFilterable

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

Features:

Since:
3.0
Author:
Vaadin Ltd.
See Also:
Container, Serialized Form

Nested Class Summary
static class IndexedContainer.ItemSetChangeEvent
          An event object specifying the list whose Item set has changed.
 
Nested classes/interfaces inherited from class com.vaadin.data.util.AbstractContainer
AbstractContainer.BaseItemSetChangeEvent, AbstractContainer.BasePropertySetChangeEvent
 
Nested classes/interfaces inherited from interface com.vaadin.data.Container
Container.Editor, Container.Filter, Container.Filterable, Container.Hierarchical, Container.Indexed, Container.ItemSetChangeListener, Container.ItemSetChangeNotifier, Container.Ordered, Container.PropertySetChangeEvent, Container.PropertySetChangeListener, Container.PropertySetChangeNotifier, Container.SimpleFilterable, Container.Sortable, Container.Viewer
 
Constructor Summary
IndexedContainer()
           
IndexedContainer(java.util.Collection<?> itemIds)
           
 
Method Summary
 void addContainerFilter(Container.Filter filter)
          Adds a filter for the container.
 void addContainerFilter(java.lang.Object propertyId, java.lang.String filterString, boolean ignoreCase, boolean onlyMatchPrefix)
          Add a filter for given property.
 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, and assign it an automatic ID.
 Item addItem(java.lang.Object itemId)
          Creates a new Item with the given ID in the Container.
 java.lang.Object addItemAfter(java.lang.Object previousItemId)
          Adds a new item after the given item.
 Item addItemAfter(java.lang.Object previousItemId, java.lang.Object newItemId)
          Adds a new item after the given item.
 java.lang.Object addItemAt(int index)
          Adds a new item at given index (in the filtered view).
 Item addItemAt(int index, java.lang.Object newItemId)
          Adds a new item at given index (in the filtered view).
 void addListener(Container.PropertySetChangeListener listener)
          Deprecated. As of 7.0, replaced by addPropertySetChangeListener(com.vaadin.data.Container.PropertySetChangeListener)
 void addListener(Property.ValueChangeListener listener)
          Deprecated. As of 7.0, replaced by addValueChangeListener(com.vaadin.data.Property.ValueChangeListener)
 void addPropertySetChangeListener(Container.PropertySetChangeListener listener)
          Implementation of the corresponding method in PropertySetChangeNotifier, override with the corresponding public method and implement the interface to use this.
 void addValueChangeListener(Property.ValueChangeListener listener)
          Registers a new value change listener for this Property.
 java.lang.Object clone()
          Deprecated. As of 6.6. Cloning support might be removed from IndexedContainer in the future
protected  void fireItemAdded(int position, java.lang.Object itemId, Item item)
          Notify item set change listeners that an item has been added to the container.
protected  void fireItemSetChange()
          Sends a simple Item set change event to all interested listeners, indicating that anything in the contents may have changed (items added, removed etc.).
 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.
 ItemSorter getItemSorter()
          Returns the ItemSorter used for comparing items in a sort.
 java.util.Collection<?> getListeners(java.lang.Class<?> eventType)
           
 java.util.Collection<?> getSortableContainerPropertyIds()
          Gets the container property IDs which can be used to sort the items.
 java.lang.Class<?> getType(java.lang.Object propertyId)
          Gets the type of a Property stored in the list.
protected  Item getUnfilteredItem(java.lang.Object itemId)
          Get an item even if filtered out.
protected  void registerNewItem(int index, java.lang.Object newItemId, Item item)
          Registers a new item as having been added to the container.
 void removeAllContainerFilters()
          Remove all active filters from the container.
 boolean removeAllItems()
          Removes all Items from the Container.
 void removeContainerFilter(Container.Filter filter)
          Removes a filter from the container.
 void removeContainerFilters(java.lang.Object propertyId)
          Remove all filters from the given property.
 boolean removeContainerProperty(java.lang.Object propertyId)
          Removes a Property specified by the given Property ID from the Container.
 boolean removeItem(java.lang.Object itemId)
          Removes the Item identified by ItemId from the Container.
 void removeListener(Container.PropertySetChangeListener listener)
          Deprecated. As of 7.0, replaced by removePropertySetChangeListener(com.vaadin.data.Container.PropertySetChangeListener)
 void removeListener(Property.ValueChangeListener listener)
          Deprecated. As of 7.0, replaced by removeValueChangeListener(com.vaadin.data.Property.ValueChangeListener)
 void removePropertySetChangeListener(Container.PropertySetChangeListener listener)
          Implementation of the corresponding method in PropertySetChangeNotifier, override with the corresponding public method and implement the interface to use this.
 void removeValueChangeListener(Property.ValueChangeListener listener)
          Removes a previously registered value change listener.
 void setItemSorter(ItemSorter itemSorter)
          Sets the ItemSorter used for comparing items in a sort.
 void sort(java.lang.Object[] propertyId, boolean[] ascending)
          Sort method.
 
Methods inherited from class com.vaadin.data.util.AbstractInMemoryContainer
addFilter, addItemSetChangeListener, addListener, containsId, doFilterContainer, doSort, filterAll, fireItemRemoved, firstItemId, getAllItemIds, getFilteredItemIds, getFilters, getIdByIndex, getItem, getItemIds, getItemIds, getSortablePropertyIds, getVisibleItemIds, indexOfId, internalAddItemAfter, internalAddItemAt, internalAddItemAtEnd, internalRemoveAllItems, internalRemoveItem, isFiltered, isFirstId, isLastId, isPropertyFiltered, lastItemId, nextItemId, passesFilters, prevItemId, removeAllFilters, removeFilter, removeFilters, removeItemSetChangeListener, removeListener, setAllItemIds, setFilteredItemIds, setFilters, size, sortContainer
 
Methods inherited from class com.vaadin.data.util.AbstractContainer
fireContainerPropertySetChange, fireContainerPropertySetChange, fireItemSetChange, getItemSetChangeListeners, getPropertySetChangeListeners, setItemSetChangeListeners, setPropertySetChangeListeners
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, toString
 
Methods inherited from interface com.vaadin.data.Container.Ordered
firstItemId, isFirstId, isLastId, lastItemId, nextItemId, prevItemId
 
Methods inherited from interface com.vaadin.data.Container
containsId, getItem, getItemIds, size
 

Constructor Detail

IndexedContainer

public IndexedContainer()

IndexedContainer

public IndexedContainer(java.util.Collection<?> itemIds)
Method Detail

getUnfilteredItem

protected Item getUnfilteredItem(java.lang.Object itemId)
Description copied from class: AbstractInMemoryContainer
Get an item even if filtered out. For internal use only.

Specified by:
getUnfilteredItem in class AbstractInMemoryContainer<java.lang.Object,java.lang.Object,Item>
Returns:

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 cannot be modified through the returned collection.

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

getType

public java.lang.Class<?> getType(java.lang.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(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 item or it is filtered out, or the Container does not have the Property, null is returned.

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

addContainerProperty

public boolean addContainerProperty(java.lang.Object propertyId,
                                    java.lang.Class<?> type,
                                    java.lang.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
Overrides:
addContainerProperty in class AbstractInMemoryContainer<java.lang.Object,java.lang.Object,Item>
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
Overrides:
removeAllItems in class AbstractInMemoryContainer<java.lang.Object,java.lang.Object,Item>
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 getItemmethod to fetch the Item.

This functionality is optional.

Specified by:
addItem in interface Container
Overrides:
addItem in class AbstractInMemoryContainer<java.lang.Object,java.lang.Object,Item>
Returns:
ID of the newly created Item, or null in case of a failure

addItem

public Item addItem(java.lang.Object itemId)
Description copied from interface: Container
Creates a new Item with the given ID in 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 AbstractInMemoryContainer<java.lang.Object,java.lang.Object,Item>
Parameters:
itemId - ID of the Item to be created
Returns:
Created new Item, or null in case of a failure

removeItem

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

Containers that support filtering should also allow removing an item that is currently filtered out.

This functionality is optional.

Specified by:
removeItem in interface Container
Overrides:
removeItem in class AbstractInMemoryContainer<java.lang.Object,java.lang.Object,Item>
Parameters:
itemId - ID of the Item to remove
Returns:
true if the operation succeeded, false if not

removeContainerProperty

public boolean removeContainerProperty(java.lang.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
Overrides:
removeContainerProperty in class AbstractInMemoryContainer<java.lang.Object,java.lang.Object,Item>
Parameters:
propertyId - ID of the Property to remove
Returns:
true if the operation succeeded, false if not

addItemAfter

public Item addItemAfter(java.lang.Object previousItemId,
                         java.lang.Object newItemId)
Description copied from interface: Container.Ordered
Adds a 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
Overrides:
addItemAfter in class AbstractInMemoryContainer<java.lang.Object,java.lang.Object,Item>
Parameters:
previousItemId - Id of the visible item in ordered container after which to insert the new item.
newItemId - Id of the new item to be added.
Returns:
new item or null if the operation fails.
See Also:
Ordered: adding items in filtered or sorted containers

addItemAfter

public java.lang.Object addItemAfter(java.lang.Object previousItemId)
Description copied from interface: Container.Ordered
Adds a 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
Overrides:
addItemAfter in class AbstractInMemoryContainer<java.lang.Object,java.lang.Object,Item>
Parameters:
previousItemId - Id of the visible item in ordered container after which to insert the new item.
Returns:
item id the the created new item or null if the operation fails.
See Also:
Ordered: adding items in filtered or sorted containers

addItemAt

public Item addItemAt(int index,
                      java.lang.Object newItemId)
Description copied from interface: Container.Indexed
Adds a new item at given index (in the filtered view).

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

This method should apply filters to the added item after inserting it, possibly hiding it immediately. If the container is being sorted, the item may be added at the correct sorted position instead of the given position. See Container.Indexed, Container.SimpleFilterable and Container.Sortable for more information.

Specified by:
addItemAt in interface Container.Indexed
Overrides:
addItemAt in class AbstractInMemoryContainer<java.lang.Object,java.lang.Object,Item>
Parameters:
index - Index (in the filtered and sorted view) at which to add the new item.
newItemId - Id of the new item to be added.
Returns:
new Item or null if the operation fails.

addItemAt

public java.lang.Object addItemAt(int index)
Description copied from interface: Container.Indexed
Adds a new item at given index (in the filtered view).

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

This method should apply filters to the added item after inserting it, possibly hiding it immediately. If the container is being sorted, the item may be added at the correct sorted position instead of the given position. See Container.Indexed, Container.Ordered, Container.SimpleFilterable and Container.Sortable for more information.

Specified by:
addItemAt in interface Container.Indexed
Overrides:
addItemAt in class AbstractInMemoryContainer<java.lang.Object,java.lang.Object,Item>
Parameters:
index - Index (in the filtered and sorted view) to add the new item.
Returns:
item id of the created item or null if the operation fails.

registerNewItem

protected void registerNewItem(int index,
                               java.lang.Object newItemId,
                               Item item)
Description copied from class: AbstractInMemoryContainer
Registers a new item as having been added to the container. This can involve storing the item or any relevant information about it in internal container-specific collections if necessary, as well as registering listeners etc. The full identifier list in AbstractInMemoryContainer has already been updated to reflect the new item when this method is called.

Overrides:
registerNewItem in class AbstractInMemoryContainer<java.lang.Object,java.lang.Object,Item>

addPropertySetChangeListener

public void addPropertySetChangeListener(Container.PropertySetChangeListener listener)
Description copied from class: AbstractContainer
Implementation of the corresponding method in PropertySetChangeNotifier, override with the corresponding public method and implement the interface to use this.

Specified by:
addPropertySetChangeListener in interface Container.PropertySetChangeNotifier
Overrides:
addPropertySetChangeListener in class AbstractContainer
Parameters:
listener - The new Listener to be registered
See Also:
PropertySetChangeNotifier#addListener(com.vaadin.data.Container.PropertySetChangeListener)

addListener

@Deprecated
public void addListener(Container.PropertySetChangeListener listener)
Deprecated. As of 7.0, replaced by addPropertySetChangeListener(com.vaadin.data.Container.PropertySetChangeListener)

Specified by:
addListener in interface Container.PropertySetChangeNotifier
Overrides:
addListener in class AbstractContainer

removePropertySetChangeListener

public void removePropertySetChangeListener(Container.PropertySetChangeListener listener)
Description copied from class: AbstractContainer
Implementation of the corresponding method in PropertySetChangeNotifier, override with the corresponding public method and implement the interface to use this.

Specified by:
removePropertySetChangeListener in interface Container.PropertySetChangeNotifier
Overrides:
removePropertySetChangeListener in class AbstractContainer
Parameters:
listener - Listener to be removed
See Also:
PropertySetChangeNotifier#removeListener(com.vaadin.data.Container. PropertySetChangeListener)

removeListener

@Deprecated
public void removeListener(Container.PropertySetChangeListener listener)
Deprecated. As of 7.0, replaced by removePropertySetChangeListener(com.vaadin.data.Container.PropertySetChangeListener)

Specified by:
removeListener in interface Container.PropertySetChangeNotifier
Overrides:
removeListener in class AbstractContainer

addValueChangeListener

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

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

addListener

@Deprecated
public void addListener(Property.ValueChangeListener listener)
Deprecated. As of 7.0, replaced by addValueChangeListener(com.vaadin.data.Property.ValueChangeListener)

Specified by:
addListener in interface Property.ValueChangeNotifier

removeValueChangeListener

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

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

removeListener

@Deprecated
public void removeListener(Property.ValueChangeListener listener)
Deprecated. As of 7.0, replaced by removeValueChangeListener(com.vaadin.data.Property.ValueChangeListener)

Specified by:
removeListener in interface Property.ValueChangeNotifier

getListeners

public java.util.Collection<?> getListeners(java.lang.Class<?> eventType)
Overrides:
getListeners in class AbstractContainer

fireItemAdded

protected void fireItemAdded(int position,
                             java.lang.Object itemId,
                             Item item)
Description copied from class: AbstractInMemoryContainer
Notify item set change listeners that an item has been added to the container. Unless subclasses specify otherwise, the default notification indicates a full refresh.

Overrides:
fireItemAdded in class AbstractInMemoryContainer<java.lang.Object,java.lang.Object,Item>
itemId - id of the added item
item - the added item

fireItemSetChange

protected void fireItemSetChange()
Description copied from class: AbstractContainer
Sends a simple Item set change event to all interested listeners, indicating that anything in the contents may have changed (items added, removed etc.).

Overrides:
fireItemSetChange in class AbstractContainer

sort

public void sort(java.lang.Object[] propertyId,
                 boolean[] ascending)
Description copied from interface: Container.Sortable
Sort method. Sorts the container items. Sorting a container can irreversibly change the order of its items or only change the order temporarily, depending on the container.

Specified by:
sort in interface Container.Sortable
Parameters:
propertyId - Array of container property IDs, whose 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 Container.Sortable.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.

getSortableContainerPropertyIds

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

Specified by:
getSortableContainerPropertyIds in interface Container.Sortable
Returns:
the IDs of the properties that can be used for sorting the container

getItemSorter

public ItemSorter getItemSorter()
Description copied from class: AbstractInMemoryContainer
Returns the ItemSorter used for comparing items in a sort. See AbstractInMemoryContainer.setItemSorter(ItemSorter) for more information.

Overrides:
getItemSorter in class AbstractInMemoryContainer<java.lang.Object,java.lang.Object,Item>
Returns:
The ItemSorter used for comparing two items in a sort.

setItemSorter

public void setItemSorter(ItemSorter itemSorter)
Description copied from class: AbstractInMemoryContainer
Sets the ItemSorter used for comparing items in a sort. The ItemSorter.compare(Object, Object) method is called with item ids to perform the sorting. A default ItemSorter is used if this is not explicitly set.

Overrides:
setItemSorter in class AbstractInMemoryContainer<java.lang.Object,java.lang.Object,Item>
Parameters:
itemSorter - The ItemSorter used for comparing two items in a sort (not null).

clone

@Deprecated
public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Deprecated. As of 6.6. Cloning support might be removed from IndexedContainer in the future

Supports cloning of the IndexedContainer cleanly.

Throws:
java.lang.CloneNotSupportedException - if an object cannot be cloned. .

addContainerFilter

public void addContainerFilter(java.lang.Object propertyId,
                               java.lang.String filterString,
                               boolean ignoreCase,
                               boolean onlyMatchPrefix)
Description copied from interface: Container.SimpleFilterable
Add a filter for given property. The API Filterable#addContainerFilter(Filter) is recommended instead of this method. A SimpleStringFilter can be used with the new API to implement the old string filtering functionality. The filter accepts items for which toString() of the value of the given property contains or starts with given filterString. Other items are not visible in the container when filtered. If a container has multiple filters, only items accepted by all filters are visible.

Specified by:
addContainerFilter in interface Container.SimpleFilterable
Parameters:
propertyId - Property for which the filter is applied to.
filterString - String that must match the value 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 active filters from the container.

Specified by:
removeAllContainerFilters in interface Container.Filterable
Specified by:
removeAllContainerFilters in interface Container.SimpleFilterable

removeContainerFilters

public void removeContainerFilters(java.lang.Object propertyId)
Description copied from interface: Container.SimpleFilterable
Remove all filters from the given property.

Specified by:
removeContainerFilters in interface Container.SimpleFilterable
Parameters:
propertyId - for which to remove filters

addContainerFilter

public void addContainerFilter(Container.Filter filter)
                        throws UnsupportedFilterException
Description copied from interface: Container.Filterable
Adds a filter for the container. If a container has multiple filters, only items accepted by all filters are visible.

Specified by:
addContainerFilter in interface Container.Filterable
Throws:
UnsupportedFilterException - if the filter is not supported by the container

removeContainerFilter

public void removeContainerFilter(Container.Filter filter)
Description copied from interface: Container.Filterable
Removes a filter from the container. This requires that the equals() method considers the filters as equivalent (same instance or properly implemented equals() method).

Specified by:
removeContainerFilter in interface Container.Filterable


Copyright © 2000-2011 Vaadin Ltd. All Rights Reserved.