com.vaadin.data.util.
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
- extends AbstractBeanContainer<BEANTYPE,BEANTYPE>
public class BeanItemContainer<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:
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 |
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.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 |
Constructor Detail |
---|
BeanItemContainer
public BeanItemContainer(Class<? super BEANTYPE> type)
throws IllegalArgumentException
- Parameters:
type
- the type of the beans that will be added to the container.- Throws:
IllegalArgumentException
- Iftype
is null
Constructs a BeanItemContainer
for beans of the given type.
BeanItemContainer
@Deprecated
public BeanItemContainer(Collection<? extends BEANTYPE> collection)
throws IllegalArgumentException
- Parameters:
collection
- a non emptyCollection
of beans.- Throws:
IllegalArgumentException
- If the collection is null or empty.
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.
BeanItemContainer
public BeanItemContainer(Class<? super BEANTYPE> type,
Collection<? extends BEANTYPE> collection)
throws IllegalArgumentException
- 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
Constructs a BeanItemContainer
and adds the given beans to it.
Method Detail |
---|
addAll
public void addAll(Collection<? extends BEANTYPE> collection)
- Overrides:
addAll
in classAbstractBeanContainer<BEANTYPE,BEANTYPE>
- Parameters:
collection
- The collection of beans to add. Must not be null.
Adds all the beans from a Collection
in one go. More efficient
than adding them one by one.
addItemAfter
public BeanItem<BEANTYPE> addItemAfter(Object previousItemId,
Object newItemId)
throws IllegalArgumentException
- 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)
Adds the bean after the given bean. The bean is used both as the item contents and as the item identifier.
addItemAt
public BeanItem<BEANTYPE> addItemAt(int index,
Object newItemId)
throws IllegalArgumentException
- 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
Adds a new bean at the given index. The bean is used both as the item contents and as the item identifier.
addItem
public BeanItem<BEANTYPE> addItem(Object itemId)
- 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)
Adds the bean to the Container. The bean is used both as the item contents and as the item identifier.
addBean
public BeanItem<BEANTYPE> addBean(BEANTYPE bean)
- Overrides:
addBean
in classAbstractBeanContainer<BEANTYPE,BEANTYPE>
- Parameters:
bean
- the bean to add- Returns:
- BeanItem
item added or null - See Also:
Container.addItem(Object)
Adds the bean to the Container. The bean is used both as the item contents and as the item identifier.
setBeanIdResolver
protected void setBeanIdResolver(AbstractBeanContainer.BeanIdResolver<BEANTYPE,BEANTYPE> beanIdResolver)
throws UnsupportedOperationException
- Overrides:
setBeanIdResolver
in classAbstractBeanContainer<BEANTYPE,BEANTYPE>
- Parameters:
beanIdResolver
- to use or null to disable automatic id resolution- Throws:
UnsupportedOperationException
Unsupported in BeanItemContainer.