Class BeanItemContainer<BEANTYPE>
- java.lang.Object
-
- com.vaadin.data.util.AbstractContainer
-
- com.vaadin.data.util.AbstractInMemoryContainer<IDTYPE,String,BeanItem<BEANTYPE>>
-
- com.vaadin.data.util.AbstractBeanContainer<BEANTYPE,BEANTYPE>
-
- 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 ofObject.equals(Object)
as well in order for it to fulfill the contract betweenequals()
andhashCode()
.To add items to the container, use the methods
addBean(Object)
,AbstractBeanContainer.addBeanAfter(Object, Object)
andAbstractBeanContainer.addBeanAt(int, Object)
. AlsoaddItem(Object)
,addItemAfter(Object, Object)
andaddItemAt(int, Object)
can be used as synonyms for them.It is not possible to add additional properties to the container.
- 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.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 BeanItemContainer(Class<? super BEANTYPE> type)
Constructs aBeanItemContainer
for beans of the given type.BeanItemContainer(Class<? super BEANTYPE> type, Collection<? extends BEANTYPE> collection)
Constructs aBeanItemContainer
and adds the given beans to it.BeanItemContainer(Collection<? extends BEANTYPE> collection)
Deprecated.As of 6.5, useBeanItemContainer(Class, Collection)
instead
-
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 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, 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, addItemAfter, 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, containsId, size
-
Methods inherited from interface com.vaadin.data.Container.Ordered
addItemAfter, firstItemId, isFirstId, isLastId, lastItemId, nextItemId, prevItemId
-
-
-
-
Constructor Detail
-
BeanItemContainer
public BeanItemContainer(Class<? super BEANTYPE> type) throws IllegalArgumentException
Constructs aBeanItemContainer
for beans of the given type.- Parameters:
type
- the type of the beans that will be added to the container.- Throws:
IllegalArgumentException
- Iftype
is null
-
BeanItemContainer
@Deprecated public BeanItemContainer(Collection<? extends BEANTYPE> collection) throws IllegalArgumentException
Deprecated.As of 6.5, useBeanItemContainer(Class, Collection)
insteadConstructs aBeanItemContainer
and adds the given beans to it. The collection must not be empty.BeanItemContainer(Class)
can be used for creating an initially emptyBeanItemContainer
. 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, useBeanItemContainer(Class)
andaddAll(Collection)
instead.- Parameters:
collection
- a non emptyCollection
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 aBeanItemContainer
and adds the given beans to it.- Parameters:
type
- the type of the beans that will be added to the container.collection
- aCollection
of beans (can be empty or null).- Throws:
IllegalArgumentException
- Iftype
is null
-
-
Method Detail
-
addAll
public void addAll(Collection<? extends BEANTYPE> collection)
Adds all the beans from aCollection
in one go. More efficient than adding them one by one.- Overrides:
addAll
in classAbstractBeanContainer<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 interfaceContainer.Ordered
- Overrides:
addItemAfter
in classAbstractInMemoryContainer<BEANTYPE,String,BeanItem<BEANTYPE>>
- Parameters:
previousItemId
- the bean (of type BT) after which to add newItemIdnewItemId
- 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 interfaceContainer.Indexed
- Overrides:
addItemAt
in classAbstractInMemoryContainer<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 interfaceContainer
- Overrides:
addItem
in classAbstractInMemoryContainer<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 classAbstractBeanContainer<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 classAbstractBeanContainer<BEANTYPE,BEANTYPE>
- Parameters:
beanIdResolver
- to use or null to disable automatic id resolution- Throws:
UnsupportedOperationException
-
-