com.vaadin.data.util
Class BeanContainer<IDTYPE,BEANTYPE>

java.lang.Object
  extended by com.vaadin.data.util.AbstractContainer
      extended by com.vaadin.data.util.AbstractInMemoryContainer<IDTYPE,String,BeanItem<BEANTYPE>>
          extended by com.vaadin.data.util.AbstractBeanContainer<IDTYPE,BEANTYPE>
              extended by com.vaadin.data.util.BeanContainer<IDTYPE,BEANTYPE>
Type Parameters:
IDTYPE - The type of the item identifier
BEANTYPE - The type of the Bean
All Implemented Interfaces:
Container, Container.Filterable, Container.Indexed, Container.ItemSetChangeNotifier, Container.Ordered, Container.PropertySetChangeNotifier, Container.SimpleFilterable, Container.Sortable, Property.ValueChangeListener, Serializable

public class BeanContainer<IDTYPE,BEANTYPE>
extends AbstractBeanContainer<IDTYPE,BEANTYPE>

An in-memory container for JavaBeans.

The properties of the container are determined automatically by introspecting the used JavaBean class. Only beans of the same type can be added to the container.

In BeanContainer (unlike BeanItemContainer), the item IDs do not have to be the beans themselves. The container can be used either with explicit item IDs or the item IDs can be generated when adding beans.

To use explicit item IDs, use the methods addItem(Object, Object), addItemAfter(Object, Object, Object) and addItemAt(int, Object, Object).

If a bean id resolver is set using setBeanIdResolver(com.vaadin.data.util.AbstractBeanContainer.BeanIdResolver) or setBeanIdProperty(Object), the methods addBean(Object), addBeanAfter(Object, Object), addBeanAt(int, Object) and addAll(java.util.Collection) can be used to add items to the container. If one of these methods is called, the resolver is used to generate an identifier for the item (must not return null).

Note that explicit item identifiers can also be used when a resolver has been set by calling the addItem*() methods - the resolver is only used when adding beans using the addBean*() or addAll(Collection) methods.

It is not possible to add additional properties to the container and nested bean properties are not supported.

Since:
6.5
See Also:
AbstractBeanContainer, BeanItemContainer, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class com.vaadin.data.util.AbstractBeanContainer
AbstractBeanContainer.BeanIdResolver<IDTYPE,BEANTYPE>, AbstractBeanContainer.PropertyBasedBeanIdResolver
 
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.ItemSetChangeEvent, Container.ItemSetChangeListener, Container.ItemSetChangeNotifier, Container.Ordered, Container.PropertySetChangeEvent, Container.PropertySetChangeListener, Container.PropertySetChangeNotifier, Container.SimpleFilterable, Container.Sortable, Container.Viewer
 
Constructor Summary
BeanContainer(Class<? super BEANTYPE> type)
           
 
Method Summary
 void addAll(Collection<? extends BEANTYPE> collection)
          Adds all the beans from a Collection in one operation using the bean item identifier resolver.
 BeanItem<BEANTYPE> addBean(BEANTYPE bean)
          Adds a bean to the container using the bean item id resolver to find its identifier.
 BeanItem<BEANTYPE> addBeanAfter(IDTYPE previousItemId, BEANTYPE bean)
          Adds a bean to the container after a specified item identifier, using the bean item id resolver to find its identifier.
 BeanItem<BEANTYPE> addBeanAt(int index, BEANTYPE bean)
          Adds a bean at a specified (filtered view) position in the container using the bean item id resolver to find its identifier.
 BeanItem<BEANTYPE> addItem(IDTYPE itemId, BEANTYPE bean)
          Adds the bean to the Container.
 BeanItem<BEANTYPE> addItemAfter(IDTYPE previousItemId, IDTYPE newItemId, BEANTYPE bean)
          Adds the bean after the given item id.
 BeanItem<BEANTYPE> addItemAt(int index, IDTYPE newItemId, BEANTYPE bean)
          Adds a new bean at the given index.
 void setBeanIdProperty(Object propertyId)
          Sets the bean id resolver to use a property of the beans as the identifier.
 void setBeanIdResolver(AbstractBeanContainer.BeanIdResolver<IDTYPE,BEANTYPE> beanIdResolver)
          Sets the resolver that finds the item id for a bean, or null not to use automatic resolving.
 
Methods inherited from class com.vaadin.data.util.AbstractBeanContainer
addContainerFilter, addContainerFilter, addContainerProperty, addContainerProperty, addListener, addNestedContainerBean, addNestedContainerProperty, createBeanItem, createBeanPropertyResolver, getBeanIdResolver, getBeanType, getContainerProperty, getContainerPropertyIds, getItem, getItemIds, getItemSorter, getSortableContainerPropertyIds, getType, getUnfilteredItem, registerNewItem, removeAllContainerFilters, removeAllItems, removeContainerFilter, removeContainerFilters, removeContainerProperty, removeItem, removeListener, resolveBeanId, setItemSorter, sort, valueChange
 
Methods inherited from class com.vaadin.data.util.AbstractInMemoryContainer
addFilter, addItem, addItem, addItemAfter, addItemAfter, addItemAt, addItemAt, addListener, containsId, doFilterContainer, doSort, filterAll, fireItemAdded, fireItemRemoved, firstItemId, getAllItemIds, getFilteredItemIds, getFilters, getIdByIndex, getSortablePropertyIds, getVisibleItemIds, indexOfId, internalAddItemAfter, internalAddItemAt, internalAddItemAtEnd, internalRemoveAllItems, internalRemoveItem, isFiltered, isFirstId, isLastId, isPropertyFiltered, lastItemId, nextItemId, passesFilters, prevItemId, removeAllFilters, removeFilter, removeFilters, removeListener, setAllItemIds, setFilteredItemIds, setFilters, size, sortContainer
 
Methods inherited from class com.vaadin.data.util.AbstractContainer
fireContainerPropertySetChange, fireContainerPropertySetChange, fireItemSetChange, fireItemSetChange, getItemSetChangeListeners, getListeners, getPropertySetChangeListeners, setItemSetChangeListeners, setPropertySetChangeListeners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.vaadin.data.Container.Ordered
addItemAfter, addItemAfter, firstItemId, isFirstId, isLastId, lastItemId, nextItemId, prevItemId
 
Methods inherited from interface com.vaadin.data.Container
addItem, addItem, containsId, size
 

Constructor Detail

BeanContainer

public BeanContainer(Class<? super BEANTYPE> type)
Method Detail

addItem

public BeanItem<BEANTYPE> addItem(IDTYPE itemId,
                                  BEANTYPE bean)
Adds the bean to the Container.

Overrides:
addItem in class AbstractBeanContainer<IDTYPE,BEANTYPE>
See Also:
Container.addItem(Object)

addItemAfter

public BeanItem<BEANTYPE> addItemAfter(IDTYPE previousItemId,
                                       IDTYPE newItemId,
                                       BEANTYPE bean)
Adds the bean after the given item id.

Overrides:
addItemAfter in class AbstractBeanContainer<IDTYPE,BEANTYPE>
See Also:
Container.Ordered.addItemAfter(Object, Object)

addItemAt

public BeanItem<BEANTYPE> addItemAt(int index,
                                    IDTYPE newItemId,
                                    BEANTYPE bean)
Adds a new bean at the given index. The bean is used both as the item contents and as the item identifier.

Overrides:
addItemAt in class AbstractBeanContainer<IDTYPE,BEANTYPE>
Parameters:
index - Index at which the bean should be added.
newItemId - The item id for the bean to add to the container.
bean - The bean to add to the container.
Returns:
Returns the new BeanItem or null if the operation fails.

setBeanIdProperty

public void setBeanIdProperty(Object propertyId)
Sets the bean id resolver to use a property of the beans as the identifier.

Parameters:
propertyId - the identifier of the property to use to find item identifiers

setBeanIdResolver

public void setBeanIdResolver(AbstractBeanContainer.BeanIdResolver<IDTYPE,BEANTYPE> beanIdResolver)
Description copied from class: AbstractBeanContainer
Sets the resolver that finds the item id for a bean, or null not to use automatic resolving. Methods that add a bean without specifying an id must not be called if no resolver has been set. Note that methods taking an explicit id can be used whether a resolver has been defined or not.

Overrides:
setBeanIdResolver in class AbstractBeanContainer<IDTYPE,BEANTYPE>
Parameters:
beanIdResolver - to use or null to disable automatic id resolution

addBean

public BeanItem<BEANTYPE> addBean(BEANTYPE bean)
                           throws IllegalStateException,
                                  IllegalArgumentException
Description copied from class: AbstractBeanContainer
Adds a bean to the container using the bean item id resolver to find its identifier. A bean id resolver must be set before calling this method.

Overrides:
addBean in class AbstractBeanContainer<IDTYPE,BEANTYPE>
Parameters:
bean - the bean to add
Returns:
BeanItem item added or null
Throws:
IllegalStateException - if no bean identifier resolver has been set
IllegalArgumentException - if an identifier cannot be resolved for the bean
See Also:
AbstractBeanContainer.addItem(Object, Object)

addBeanAfter

public BeanItem<BEANTYPE> addBeanAfter(IDTYPE previousItemId,
                                       BEANTYPE bean)
                                throws IllegalStateException,
                                       IllegalArgumentException
Description copied from class: AbstractBeanContainer
Adds a bean to the container after a specified item identifier, using the bean item id resolver to find its identifier. A bean id resolver must be set before calling this method.

Overrides:
addBeanAfter in class AbstractBeanContainer<IDTYPE,BEANTYPE>
Parameters:
previousItemId - the identifier of the bean after which this bean should be added, null to add to the beginning
bean - the bean to add
Returns:
BeanItem item added or null
Throws:
IllegalStateException - if no bean identifier resolver has been set
IllegalArgumentException - if an identifier cannot be resolved for the bean
See Also:
AbstractBeanContainer.addItemAfter(Object, Object, Object)

addBeanAt

public BeanItem<BEANTYPE> addBeanAt(int index,
                                    BEANTYPE bean)
                             throws IllegalStateException,
                                    IllegalArgumentException
Description copied from class: AbstractBeanContainer
Adds a bean at a specified (filtered view) position in the container using the bean item id resolver to find its identifier. A bean id resolver must be set before calling this method.

Overrides:
addBeanAt in class AbstractBeanContainer<IDTYPE,BEANTYPE>
Parameters:
index - the index (in the filtered view) at which to add the item
bean - the bean to add
Returns:
BeanItem item added or null
Throws:
IllegalStateException - if no bean identifier resolver has been set
IllegalArgumentException - if an identifier cannot be resolved for the bean
See Also:
AbstractBeanContainer.addItemAfter(Object, Object, Object)

addAll

public void addAll(Collection<? extends BEANTYPE> collection)
            throws IllegalStateException
Description copied from class: AbstractBeanContainer
Adds all the beans from a Collection in one operation using the bean item identifier resolver. More efficient than adding them one by one. A bean id resolver must be set before calling this method. Note: the behavior of this method changed in Vaadin 6.6 - now items are added at the very end of the unfiltered container and not after the last visible item if filtering is used.

Overrides:
addAll in class AbstractBeanContainer<IDTYPE,BEANTYPE>
Parameters:
collection - The collection of beans to add. Must not be null.
Throws:
IllegalStateException - if no bean identifier resolver has been set


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