Class 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
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(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.
- Since:
- 6.5
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.vaadin.featurepack.data.util.AbstractBeanContainer
AbstractBeanContainer.BeanIdResolver<IDTYPE,BEANTYPE>, AbstractBeanContainer.PropertyBasedBeanIdResolver Nested classes/interfaces inherited from class com.vaadin.featurepack.data.util.AbstractInMemoryContainer
AbstractInMemoryContainer.BaseItemAddEvent, AbstractInMemoryContainer.BaseItemRemoveEventNested classes/interfaces inherited from class com.vaadin.featurepack.data.util.AbstractContainer
AbstractContainer.BaseItemSetChangeEvent, AbstractContainer.BasePropertySetChangeEventNested classes/interfaces inherited from interface com.vaadin.featurepack.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.ViewerNested classes/interfaces inherited from interface com.vaadin.featurepack.data.Container.Indexed
Container.Indexed.ItemAddEvent, Container.Indexed.ItemRemoveEvent -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAll(Collection<? extends BEANTYPE> collection) Adds all the beans from aCollectionin one operation using the bean item identifier resolver.Adds a bean to the container using the bean item id resolver to find its identifier.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.Adds a bean at a specified (filtered view) position in the container using the bean item id resolver to find its identifier.Adds the bean to the Container.addItemAfter(IDTYPE previousItemId, IDTYPE newItemId, BEANTYPE bean) Adds the bean after the given item id.Adds a new bean at the given index.voidsetBeanIdProperty(Object propertyId) Sets the bean id resolver to use a property of the beans as the identifier.voidsetBeanIdResolver(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.featurepack.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, valueChangeMethods inherited from class com.vaadin.featurepack.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, sortContainerMethods inherited from class com.vaadin.featurepack.data.util.AbstractContainer
fireContainerPropertySetChange, fireContainerPropertySetChange, fireItemSetChange, fireItemSetChange, getItemSetChangeListeners, getListeners, getPropertySetChangeListeners, setItemSetChangeListeners, setPropertySetChangeListenersMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.featurepack.data.Container
addItem, addItem, containsId, sizeMethods inherited from interface com.vaadin.featurepack.data.Container.Ordered
addItemAfter, addItemAfter, firstItemId, isFirstId, isLastId, lastItemId, nextItemId, prevItemId
-
Constructor Details
-
BeanContainer
-
-
Method Details
-
addItem
Adds the bean to the Container.- Overrides:
addItemin classAbstractBeanContainer<IDTYPE,BEANTYPE> - See Also:
-
addItemAfter
Adds the bean after the given item id.- Overrides:
addItemAfterin classAbstractBeanContainer<IDTYPE,BEANTYPE> - See Also:
-
addItemAt
Adds a new bean at the given index. The bean is used both as the item contents and as the item identifier.- Overrides:
addItemAtin 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
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
Description copied from class:AbstractBeanContainerSets 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:
setBeanIdResolverin 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:AbstractBeanContainerAdds 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:
addBeanin 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:
-
addBeanAfter
public BeanItem<BEANTYPE> addBeanAfter(IDTYPE previousItemId, BEANTYPE bean) throws IllegalStateException, IllegalArgumentException Description copied from class:AbstractBeanContainerAdds 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:
addBeanAfterin 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:
-
addBeanAt
public BeanItem<BEANTYPE> addBeanAt(int index, BEANTYPE bean) throws IllegalStateException, IllegalArgumentException Description copied from class:AbstractBeanContainerAdds 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:
addBeanAtin 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:
-
addAll
Description copied from class:AbstractBeanContainerAdds all the beans from aCollectionin 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:
addAllin 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
-