com.vaadin.data.util
Class BeanItemContainer<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<BEANTYPE,BEANTYPE>
              extended by com.vaadin.data.util.BeanItemContainer<BEANTYPE>
Type Parameters:
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 BeanItemContainer<BEANTYPE>
extends AbstractBeanContainer<BEANTYPE,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.

BeanItemContainer uses the beans themselves as identifiers. The Object.hashCode() of a bean is used when storing and looking up beans so it must not change during the lifetime of the bean (it should not depend on any part of the bean that can be modified). Typically this restricts the implementation of Object.equals(Object) as well in order for it to fulfill the contract between equals() and hashCode().

To add items to the container, use the methods addBean(Object), AbstractBeanContainer.addBeanAfter(Object, Object) and AbstractBeanContainer.addBeanAt(int, Object). Also addItem(Object), addItemAfter(Object, Object) and addItemAt(int, Object) can be used as synonyms for them.

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

Since:
5.4
See Also:
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
BeanItemContainer(Class<? super BEANTYPE> type)
          Constructs a BeanItemContainer for beans of the given type.
BeanItemContainer(Class<? super BEANTYPE> type, Collection<? extends BEANTYPE> collection)
          Constructs a BeanItemContainer and adds the given beans to it.
BeanItemContainer(Collection<? extends BEANTYPE> collection)
          Deprecated. use BeanItemContainer(Class, Collection) instead
 
Method Summary
 void addAll(Collection<? extends BEANTYPE> collection)
          Adds all the beans from a Collection in one go.
 BeanItem<BEANTYPE> addBean(BEANTYPE bean)
          Adds the bean to the Container.
 BeanItem<BEANTYPE> addItem(Object itemId)
          Adds the bean to the Container.
 BeanItem<BEANTYPE> addItemAfter(Object previousItemId, Object newItemId)
          Adds the bean after the given bean.
 BeanItem<BEANTYPE> addItemAt(int index, Object newItemId)
          Adds a new bean at the given index.
protected  void setBeanIdResolver(AbstractBeanContainer.BeanIdResolver<BEANTYPE,BEANTYPE> beanIdResolver)
          Unsupported in BeanItemContainer.
 
Methods inherited from class com.vaadin.data.util.AbstractBeanContainer
addBeanAfter, addBeanAt, addContainerFilter, addContainerFilter, addContainerProperty, addContainerProperty, addItem, addItemAfter, addItemAt, 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, addItemAfter, 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, firstItemId, isFirstId, isLastId, lastItemId, nextItemId, prevItemId
 
Methods inherited from interface com.vaadin.data.Container
addItem, containsId, size
 

Constructor Detail

BeanItemContainer

public BeanItemContainer(Class<? super BEANTYPE> type)
                  throws IllegalArgumentException
Constructs a BeanItemContainer for beans of the given type.

Parameters:
type - the type of the beans that will be added to the container.
Throws:
IllegalArgumentException - If type is null

BeanItemContainer

@Deprecated
public BeanItemContainer(Collection<? extends BEANTYPE> collection)
                  throws IllegalArgumentException
Deprecated. use BeanItemContainer(Class, Collection) instead

Constructs a BeanItemContainer and adds the given beans to it. The collection must not be empty. BeanItemContainer(Class) can be used for creating an initially empty BeanItemContainer. Note that when using this constructor, the actual class of the first item in the collection is used to determine the bean properties supported by the container instance, and only beans of that class or its subclasses can be added to the collection. If this is problematic or empty collections need to be supported, use BeanItemContainer(Class) and addAll(Collection) instead.

Parameters:
collection - a non empty Collection of beans.
Throws:
IllegalArgumentException - If the collection is null or empty.

BeanItemContainer

public BeanItemContainer(Class<? super BEANTYPE> type,
                         Collection<? extends BEANTYPE> collection)
                  throws IllegalArgumentException
Constructs a BeanItemContainer and adds the given beans to it.

Parameters:
type - the type of the beans that will be added to the container.
collection - a Collection of beans (can be empty or null).
Throws:
IllegalArgumentException - If type is null
Method Detail

addAll

public void addAll(Collection<? extends BEANTYPE> collection)
Adds all the beans from a Collection in one go. More efficient than adding them one by one.

Overrides:
addAll in class AbstractBeanContainer<BEANTYPE,BEANTYPE>
Parameters:
collection - The collection of beans to add. Must not be null.

addItemAfter

public BeanItem<BEANTYPE> addItemAfter(Object previousItemId,
                                       Object newItemId)
                                throws IllegalArgumentException
Adds the bean after the given bean. The bean is used both as the item contents and as the item identifier.

Specified by:
addItemAfter in interface Container.Ordered
Overrides:
addItemAfter in class AbstractInMemoryContainer<BEANTYPE,String,BeanItem<BEANTYPE>>
Parameters:
previousItemId - the bean (of type BT) after which to add newItemId
newItemId - the bean (of type BT) to add (not null)
Returns:
new item or null if the operation fails.
Throws:
IllegalArgumentException
See Also:
Container.Ordered.addItemAfter(Object, Object)

addItemAt

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

Specified by:
addItemAt in interface Container.Indexed
Overrides:
addItemAt in class AbstractInMemoryContainer<BEANTYPE,String,BeanItem<BEANTYPE>>
Parameters:
index - Index at which the bean should be added.
newItemId - The bean to add to the container.
Returns:
Returns the new BeanItem or null if the operation fails.
Throws:
IllegalArgumentException

addItem

public BeanItem<BEANTYPE> addItem(Object itemId)
Adds the bean to the Container. The bean is used both as the item contents and as the item identifier.

Specified by:
addItem in interface Container
Overrides:
addItem in class AbstractInMemoryContainer<BEANTYPE,String,BeanItem<BEANTYPE>>
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)

addBean

public BeanItem<BEANTYPE> addBean(BEANTYPE bean)
Adds the bean to the Container. The bean is used both as the item contents and as the item identifier.

Overrides:
addBean in class AbstractBeanContainer<BEANTYPE,BEANTYPE>
Parameters:
bean - the bean to add
Returns:
BeanItem item added or null
See Also:
Container.addItem(Object)

setBeanIdResolver

protected void setBeanIdResolver(AbstractBeanContainer.BeanIdResolver<BEANTYPE,BEANTYPE> beanIdResolver)
                          throws UnsupportedOperationException
Unsupported in BeanItemContainer.

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


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