Class BeanContainer<IDTYPE,BEANTYPE>
- java.lang.Object
-
- com.vaadin.data.util.AbstractContainer
-
- com.vaadin.data.util.AbstractInMemoryContainer<IDTYPE,String,BeanItem<BEANTYPE>>
-
- com.vaadin.data.util.AbstractBeanContainer<IDTYPE,BEANTYPE>
-
- com.vaadin.data.util.BeanContainer<IDTYPE,BEANTYPE>
-
- Type Parameters:
IDTYPE
- The type of the item identifierBEANTYPE
- 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)
andaddItemAt(int, Object, Object)
.If a bean id resolver is set using
setBeanIdResolver(AbstractBeanContainer.BeanIdResolver)
orsetBeanIdProperty(Object)
, the methodsaddBean(Object)
,addBeanAfter(Object, Object)
,addBeanAt(int, Object)
andaddAll(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.
- 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.AbstractInMemoryContainer
AbstractInMemoryContainer.BaseItemAddEvent, AbstractInMemoryContainer.BaseItemRemoveEvent
-
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
-
Nested classes/interfaces inherited from interface com.vaadin.data.Container.Indexed
Container.Indexed.ItemAddEvent, Container.Indexed.ItemRemoveEvent
-
-
Constructor Summary
Constructors Constructor Description BeanContainer(Class<? super BEANTYPE> type)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAll(Collection<? extends BEANTYPE> collection)
Adds all the beans from aCollection
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, addPropertySetChangeListener, createBeanItem, createBeanPropertyResolver, getBeanIdResolver, getBeanType, getContainerFilters, getContainerProperty, getContainerPropertyIds, getItem, getItemIds, getItemSorter, getSortableContainerPropertyIds, getType, getUnfilteredItem, hasContainerFilters, registerNewItem, removeAllContainerFilters, removeAllItems, removeContainerFilter, removeContainerFilters, removeContainerProperty, removeItem, removeListener, removePropertySetChangeListener, resolveBeanId, setItemSorter, sort, valueChange
-
Methods inherited from class com.vaadin.data.util.AbstractInMemoryContainer
addFilter, addItem, addItem, addItemAfter, addItemAfter, addItemAt, addItemAt, addItemSetChangeListener, addListener, containsId, doFilterContainer, doSort, filterAll, fireItemAdded, fireItemRemoved, fireItemsAdded, fireItemsRemoved, firstItemId, getAllItemIds, getFilteredItemIds, getFilters, getFirstVisibleItem, getIdByIndex, 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, 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
addItem, addItem, containsId, size
-
Methods inherited from interface com.vaadin.data.Container.Ordered
addItemAfter, addItemAfter, firstItemId, isFirstId, isLastId, lastItemId, nextItemId, prevItemId
-
-
-
-
Method Detail
-
addItem
public BeanItem<BEANTYPE> addItem(IDTYPE itemId, BEANTYPE bean)
Adds the bean to the Container.- Overrides:
addItem
in classAbstractBeanContainer<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 classAbstractBeanContainer<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 classAbstractBeanContainer<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 classAbstractBeanContainer<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 classAbstractBeanContainer<IDTYPE,BEANTYPE>
- Parameters:
bean
- the bean to add- Returns:
- BeanItem
item added or null - Throws:
IllegalStateException
- if no bean identifier resolver has been setIllegalArgumentException
- 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 classAbstractBeanContainer<IDTYPE,BEANTYPE>
- Parameters:
previousItemId
- the identifier of the bean after which this bean should be added, null to add to the beginningbean
- the bean to add- Returns:
- BeanItem
item added or null - Throws:
IllegalStateException
- if no bean identifier resolver has been setIllegalArgumentException
- 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 classAbstractBeanContainer<IDTYPE,BEANTYPE>
- Parameters:
index
- the index (in the filtered view) at which to add the itembean
- the bean to add- Returns:
- BeanItem
item added or null - Throws:
IllegalStateException
- if no bean identifier resolver has been setIllegalArgumentException
- 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 aCollection
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 classAbstractBeanContainer<IDTYPE,BEANTYPE>
- Parameters:
collection
- The collection of beans to add. Must not be null.- Throws:
IllegalStateException
- if no bean identifier resolver has been set
-
-