com.vaadin.data.util.
Class AbstractBeanContainer<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>
Type Parameters:
IDTYPE
- The type of the item identifier
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
Direct Known Subclasses:
- extends AbstractInMemoryContainer<IDTYPE,String,BeanItem<BEANTYPE>>
- implements Container.Filterable, Container.SimpleFilterable, Container.Sortable, Property.ValueChangeListener, Container.PropertySetChangeNotifier
public abstract class AbstractBeanContainer<IDTYPE,BEANTYPE>
An abstract base class for in-memory containers for JavaBeans.
The properties of the container are determined automatically by introspecting the used JavaBean class and explicitly adding or removing properties is not supported. Only beans of the same type can be added to the container.
Subclasses should implement any public methods adding items to the container,
typically calling the protected methods addItem(Object, Object)
,
addItemAfter(Object, Object, Object)
and
addItemAt(int, Object, Object)
.
Since:
6.5
See Also:
Nested Class Summary | |
---|---|
static interface |
AbstractBeanContainer.BeanIdResolver<IDTYPE,BEANTYPE>
Resolver that maps beans to their (item) identifiers, removing the need to explicitly specify item identifiers when there is no need to customize this. |
protected class |
AbstractBeanContainer.PropertyBasedBeanIdResolver
A item identifier resolver that returns the value of a bean property. |
Nested classes/interfaces inherited from class com.vaadin.data.util.AbstractContainer |
---|
AbstractContainer.BaseItemSetChangeEvent, AbstractContainer.BasePropertySetChangeEvent |
Constructor Summary | |
---|---|
protected |
AbstractBeanContainer(Class<? super BEANTYPE> type)
Constructs a AbstractBeanContainer for beans of the given type. |
Method Summary | |
---|---|
protected void |
addAll(Collection<? extends BEANTYPE> collection)
Adds all the beans from a Collection in one operation using the
bean item identifier resolver. |
protected BeanItem<BEANTYPE> |
addBean(BEANTYPE bean)
Adds a bean to the container using the bean item id resolver to find its identifier. |
protected 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. |
protected 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. |
void |
addContainerFilter(Container.Filter filter)
Adds a filter for the container. |
void |
addContainerFilter(Object propertyId,
String filterString,
boolean ignoreCase,
boolean onlyMatchPrefix)
Add a filter for given property. |
boolean |
addContainerProperty(Object propertyId,
Class<?> type,
Object defaultValue)
Adds a new Property to all Items in the Container. |
protected boolean |
addContainerProperty(String propertyId,
VaadinPropertyDescriptor<BEANTYPE> propertyDescriptor)
Adds a property for the container and all its items. |
protected BeanItem<BEANTYPE> |
addItem(IDTYPE itemId,
BEANTYPE bean)
Adds the bean to the Container. |
protected BeanItem<BEANTYPE> |
addItemAfter(IDTYPE previousItemId,
IDTYPE newItemId,
BEANTYPE bean)
Adds the bean after the given bean. |
protected BeanItem<BEANTYPE> |
addItemAt(int index,
IDTYPE newItemId,
BEANTYPE bean)
Adds a new bean at the given index. |
void |
addListener(Container.PropertySetChangeListener listener)
Implementation of the corresponding method in PropertySetChangeNotifier , override with the corresponding public
method and implement the interface to use this. |
boolean |
addNestedContainerProperty(String propertyId)
Adds a nested container property for the container, e.g. |
protected BeanItem<BEANTYPE> |
createBeanItem(BEANTYPE bean)
Create a BeanItem for a bean using pre-parsed bean metadata (based on getBeanType() ). |
protected AbstractBeanContainer.BeanIdResolver<IDTYPE,BEANTYPE> |
createBeanPropertyResolver(Object propertyId)
Create an item identifier resolver using a named bean property. |
AbstractBeanContainer.BeanIdResolver<IDTYPE,BEANTYPE> |
getBeanIdResolver()
Returns the resolver that finds the item ID for a bean. |
Class<? super BEANTYPE> |
getBeanType()
Returns the type of beans this Container can contain. |
Property |
getContainerProperty(Object itemId,
Object propertyId)
Gets the Property identified by the given itemId and propertyId from the Container. |
Collection<String> |
getContainerPropertyIds()
Gets the ID's of all Properties stored in the Container. |
BeanItem<BEANTYPE> |
getItem(Object itemId)
Gets the Item with the given Item ID from the Container. |
Collection<IDTYPE> |
getItemIds()
Gets the ID's of all visible (after filtering and sorting) Items stored in the Container. |
ItemSorter |
getItemSorter()
Returns the ItemSorter used for comparing items in a sort. |
Collection<?> |
getSortableContainerPropertyIds()
Gets the container property IDs which can be used to sort the items. |
Class<?> |
getType(Object propertyId)
Gets the data type of all Properties identified by the given Property ID. |
protected BeanItem<BEANTYPE> |
getUnfilteredItem(Object itemId)
Get an item even if filtered out. |
protected void |
registerNewItem(int position,
IDTYPE itemId,
BeanItem<BEANTYPE> item)
Registers a new item as having been added to the container. |
void |
removeAllContainerFilters()
Remove all active filters from the container. |
boolean |
removeAllItems()
Removes all Items from the Container. |
void |
removeContainerFilter(Container.Filter filter)
Removes a filter from the container. |
void |
removeContainerFilters(Object propertyId)
Remove all filters from the given property. |
boolean |
removeContainerProperty(Object propertyId)
Removes a Property specified by the given Property ID from the Container. |
boolean |
removeItem(Object itemId)
Removes the Item identified by ItemId from the Container. |
void |
removeListener(Container.PropertySetChangeListener listener)
Implementation of the corresponding method in PropertySetChangeNotifier , override with the corresponding public
method and implement the interface to use this. |
protected IDTYPE |
resolveBeanId(BEANTYPE bean)
Use the bean resolver to get the identifier for a bean. |
protected 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. |
void |
setItemSorter(ItemSorter itemSorter)
Sets the ItemSorter used for comparing items in a sort. |
void |
sort(Object[] propertyId,
boolean[] ascending)
Sort method. |
void |
valueChange(Property.ValueChangeEvent event)
Re-filter the container when one of the monitored properties changes. |
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, addItemAfter, firstItemId, isFirstId, isLastId, lastItemId, nextItemId, prevItemId |
Constructor Detail |
---|
AbstractBeanContainer
protected AbstractBeanContainer(Class<? super BEANTYPE> type)
- Parameters:
type
- the type of the beans that will be added to the container.- Throws:
IllegalArgumentException
- Iftype
is null
Constructs a AbstractBeanContainer
for beans of the given type.
Method Detail |
---|
getType
public Class<?> getType(Object propertyId)
- Parameters:
propertyId
- ID identifying the Properties- Returns:
- data type of the Properties
Description copied from interface: Container
Gets the data type of all Properties identified by the given Property ID.
createBeanItem
protected BeanItem<BEANTYPE> createBeanItem(BEANTYPE bean)
- Parameters:
bean
-- Returns:
- created
BeanItem
or null if bean is null
Create a BeanItem for a bean using pre-parsed bean metadata (based on
getBeanType()
).
getBeanType
public Class<? super BEANTYPE> getBeanType()
- Returns:
Returns the type of beans this Container can contain. This comes from the bean type constructor parameter, and bean metadata (including container properties) is based on this.
getContainerPropertyIds
public Collection<String> getContainerPropertyIds()
- Specified by:
getContainerPropertyIds
in interfaceContainer
- Returns:
- unmodifiable collection of Property IDs
Description copied from interface: Container
Gets the ID's of all Properties stored in the Container. The ID's cannot be modified through the returned collection.
removeAllItems
public boolean removeAllItems()
- Specified by:
removeAllItems
in interfaceContainer
- Overrides:
removeAllItems
in classAbstractInMemoryContainer<IDTYPE,String,BeanItem<BEANTYPE>>
- Returns:
true
if the operation succeeded,false
if not
Description copied from interface: Container
Removes all Items from the Container.
Note that Property ID and type information is preserved. This functionality is optional.
getItem
public BeanItem<BEANTYPE> getItem(Object itemId)
Description copied from interface: Container
Gets the Item
with the given Item ID from the Container. If the
Container does not contain the requested Item, null
is
returned.
Containers should not return Items that are filtered out.
getUnfilteredItem
protected BeanItem<BEANTYPE> getUnfilteredItem(Object itemId)
- Specified by:
getUnfilteredItem
in classAbstractInMemoryContainer<IDTYPE,String,BeanItem<BEANTYPE>>
- Returns:
Description copied from class: AbstractInMemoryContainer
Get an item even if filtered out. For internal use only.
getItemIds
public Collection<IDTYPE> getItemIds()
- Specified by:
getItemIds
in interfaceContainer
- Overrides:
getItemIds
in classAbstractInMemoryContainer<IDTYPE,String,BeanItem<BEANTYPE>>
- Returns:
- unmodifiable collection of Item IDs
Description copied from interface: Container
Gets the ID's of all visible (after filtering and sorting) Items stored
in the Container. The ID's cannot be modified through the returned
collection.
If the container is Container.Ordered
, the collection returned by this
method should follow that order. If the container is Container.Sortable
,
the items should be in the sorted order.
Calling this method for large lazy containers can be an expensive
operation and should be avoided when practical.
getContainerProperty
public Property getContainerProperty(Object itemId,
Object propertyId)
- Specified by:
getContainerProperty
in interfaceContainer
- Parameters:
itemId
- ID of the visible Item which contains the PropertypropertyId
- ID of the Property to retrieve- Returns:
- Property with the given ID or
null
Description copied from interface: Container
Gets the Property identified by the given itemId and propertyId from the
Container. If the Container does not contain the item or it is filtered
out, or the Container does not have the Property, null
is
returned.
removeItem
public boolean removeItem(Object itemId)
- Specified by:
removeItem
in interfaceContainer
- Overrides:
removeItem
in classAbstractInMemoryContainer<IDTYPE,String,BeanItem<BEANTYPE>>
- Parameters:
itemId
- ID of the Item to remove- Returns:
true
if the operation succeeded,false
if not
Description copied from interface: Container
Removes the Item identified by ItemId
from the Container.
Containers that support filtering should also allow removing an item that is currently filtered out.
This functionality is optional.
valueChange
public void valueChange(Property.ValueChangeEvent event)
- Specified by:
valueChange
in interfaceProperty.ValueChangeListener
- Parameters:
event
- value change event object
Re-filter the container when one of the monitored properties changes.
addContainerFilter
public void addContainerFilter(Object propertyId,
String filterString,
boolean ignoreCase,
boolean onlyMatchPrefix)
- Specified by:
addContainerFilter
in interfaceContainer.SimpleFilterable
- Parameters:
propertyId
- Property for which the filter is applied to.filterString
- String that must match the value of the propertyignoreCase
- Determine if the casing can be ignored when comparing strings.onlyMatchPrefix
- Only match prefixes; no other matches are included.
Description copied from interface: Container.SimpleFilterable
Add a filter for given property.
The API Filterable#addContainerFilter(Filter)
is recommended
instead of this method. A SimpleStringFilter
can be used with
the new API to implement the old string filtering functionality.
The filter accepts items for which toString() of the value of the
given property contains or starts with given filterString. Other
items are not visible in the container when filtered.
If a container has multiple filters, only items accepted by all
filters are visible.
removeAllContainerFilters
public void removeAllContainerFilters()
- Specified by:
removeAllContainerFilters
in interfaceContainer.Filterable
- Specified by:
removeAllContainerFilters
in interfaceContainer.SimpleFilterable
Description copied from interface: Container.Filterable
Remove all active filters from the container.
removeContainerFilters
public void removeContainerFilters(Object propertyId)
- Specified by:
removeContainerFilters
in interfaceContainer.SimpleFilterable
- Parameters:
propertyId
- for which to remove filters
Description copied from interface: Container.SimpleFilterable
Remove all filters from the given property.
addContainerFilter
public void addContainerFilter(Container.Filter filter)
throws UnsupportedFilterException
- Specified by:
addContainerFilter
in interfaceContainer.Filterable
- Throws:
UnsupportedFilterException
- if the filter is not supported by the container
Description copied from interface: Container.Filterable
Adds a filter for the container. If a container has multiple filters, only items accepted by all filters are visible.
removeContainerFilter
public void removeContainerFilter(Container.Filter filter)
- Specified by:
removeContainerFilter
in interfaceContainer.Filterable
Description copied from interface: Container.Filterable
Removes a filter from the container. This requires that the equals() method considers the filters as equivalent (same instance or properly implemented equals() method).
getSortableContainerPropertyIds
public Collection<?> getSortableContainerPropertyIds()
- Specified by:
getSortableContainerPropertyIds
in interfaceContainer.Sortable
- Returns:
- the IDs of the properties that can be used for sorting the container
Description copied from interface: Container.Sortable
Gets the container property IDs which can be used to sort the items.
sort
public void sort(Object[] propertyId,
boolean[] ascending)
- Specified by:
sort
in interfaceContainer.Sortable
- Parameters:
propertyId
- Array of container property IDs, whose values are used to sort the items in container as primary, secondary, ... sorting criterion. All of the item IDs must be in the collection returned byContainer.Sortable.getSortableContainerPropertyIds()
ascending
- Array of sorting order flags corresponding to each property ID used in sorting. If this array is shorter than propertyId array, ascending order is assumed for items where the order is not specified. Usetrue
to sort in ascending order,false
to use descending order.
Description copied from interface: Container.Sortable
Sort method. Sorts the container items. Sorting a container can irreversibly change the order of its items or only change the order temporarily, depending on the container.
getItemSorter
public ItemSorter getItemSorter()
- Overrides:
getItemSorter
in classAbstractInMemoryContainer<IDTYPE,String,BeanItem<BEANTYPE>>
- Returns:
- The ItemSorter used for comparing two items in a sort.
Description copied from class: AbstractInMemoryContainer
Returns the ItemSorter used for comparing items in a sort. See
AbstractInMemoryContainer.setItemSorter(ItemSorter)
for more information.
setItemSorter
public void setItemSorter(ItemSorter itemSorter)
- Overrides:
setItemSorter
in classAbstractInMemoryContainer<IDTYPE,String,BeanItem<BEANTYPE>>
- Parameters:
itemSorter
- The ItemSorter used for comparing two items in a sort (not null).
Description copied from class: AbstractInMemoryContainer
Sets the ItemSorter used for comparing items in a sort. The
ItemSorter.compare(Object, Object)
method is called with item ids
to perform the sorting. A default ItemSorter is used if this is not
explicitly set.
registerNewItem
protected void registerNewItem(int position,
IDTYPE itemId,
BeanItem<BEANTYPE> item)
- Overrides:
registerNewItem
in classAbstractInMemoryContainer<IDTYPE,String,BeanItem<BEANTYPE>>
Description copied from class: AbstractInMemoryContainer
Registers a new item as having been added to the container. This can
involve storing the item or any relevant information about it in internal
container-specific collections if necessary, as well as registering
listeners etc.
The full identifier list in AbstractInMemoryContainer
has already
been updated to reflect the new item when this method is called.
addItem
protected BeanItem<BEANTYPE> addItem(IDTYPE itemId,
BEANTYPE bean)
- See Also:
Container.addItem(Object)
Adds the bean to the Container. 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.
addItemAfter
protected BeanItem<BEANTYPE> addItemAfter(IDTYPE previousItemId,
IDTYPE newItemId,
BEANTYPE bean)
Adds the bean after the given bean.
addItemAt
protected BeanItem<BEANTYPE> addItemAt(int index,
IDTYPE newItemId,
BEANTYPE bean)
- 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.
Adds a new bean at the given index. The bean is used both as the item contents and as the item identifier.
addBean
protected BeanItem<BEANTYPE> addBean(BEANTYPE bean)
throws IllegalStateException,
IllegalArgumentException
- 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:
addItem(Object, Object)
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.
addBeanAfter
protected BeanItem<BEANTYPE> addBeanAfter(IDTYPE previousItemId,
BEANTYPE bean)
throws IllegalStateException,
IllegalArgumentException
- 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:
addItemAfter(Object, Object, Object)
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.
addBeanAt
protected BeanItem<BEANTYPE> addBeanAt(int index,
BEANTYPE bean)
throws IllegalStateException,
IllegalArgumentException
- 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:
addItemAfter(Object, Object, Object)
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.
addAll
protected void addAll(Collection<? extends BEANTYPE> collection)
throws IllegalStateException,
IllegalArgumentException
- Parameters:
collection
- The collection of beans to add. Must not be null.- Throws:
IllegalStateException
- if no bean identifier resolver has been setIllegalArgumentException
- if the resolver returns a null itemId for one of the beans in the collection
Adds all the beans from a Collection
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.
resolveBeanId
protected IDTYPE resolveBeanId(BEANTYPE bean)
- Parameters:
bean
-- Returns:
- resolved bean identifier, null if could not be resolved
- Throws:
IllegalStateException
- if no bean resolver is set
Use the bean resolver to get the identifier for a bean.
setBeanIdResolver
protected void setBeanIdResolver(AbstractBeanContainer.BeanIdResolver<IDTYPE,BEANTYPE> beanIdResolver)
- Parameters:
beanIdResolver
- to use or null to disable automatic id resolution
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.
getBeanIdResolver
public AbstractBeanContainer.BeanIdResolver<IDTYPE,BEANTYPE> getBeanIdResolver()
- Returns:
- resolver used or null if automatic item id resolving is disabled
Returns the resolver that finds the item ID for a bean.
createBeanPropertyResolver
protected AbstractBeanContainer.BeanIdResolver<IDTYPE,BEANTYPE> createBeanPropertyResolver(Object propertyId)
- Parameters:
propertyId
- property identifier, which must map to a getter in BEANTYPE- Returns:
- created resolver
Create an item identifier resolver using a named bean property.
addListener
public void addListener(Container.PropertySetChangeListener listener)
- Specified by:
addListener
in interfaceContainer.PropertySetChangeNotifier
- Overrides:
addListener
in classAbstractContainer
- Parameters:
listener
- The new Listener to be registered- See Also:
PropertySetChangeNotifier#addListener(com.vaadin.data.Container.PropertySetChangeListener)
Description copied from class: AbstractContainer
Implementation of the corresponding method in
PropertySetChangeNotifier
, override with the corresponding public
method and implement the interface to use this.
removeListener
public void removeListener(Container.PropertySetChangeListener listener)
- Specified by:
removeListener
in interfaceContainer.PropertySetChangeNotifier
- Overrides:
removeListener
in classAbstractContainer
- Parameters:
listener
- Listener to be removed- See Also:
PropertySetChangeNotifier#removeListener(com.vaadin.data.Container. PropertySetChangeListener)
Description copied from class: AbstractContainer
Implementation of the corresponding method in
PropertySetChangeNotifier
, override with the corresponding public
method and implement the interface to use this.
addContainerProperty
public boolean addContainerProperty(Object propertyId,
Class<?> type,
Object defaultValue)
throws UnsupportedOperationException
- Specified by:
addContainerProperty
in interfaceContainer
- Overrides:
addContainerProperty
in classAbstractInMemoryContainer<IDTYPE,String,BeanItem<BEANTYPE>>
- Parameters:
propertyId
- ID of the Propertytype
- Data type of the new PropertydefaultValue
- The value all created Properties are initialized to- Returns:
true
if the operation succeeded,false
if not- Throws:
UnsupportedOperationException
- if the container does not support explicitly adding container properties
Description copied from interface: Container
Adds a new Property to all Items in the Container. The Property ID, data type and default value of the new Property are given as parameters. This functionality is optional.
addContainerProperty
protected final boolean addContainerProperty(String propertyId,
VaadinPropertyDescriptor<BEANTYPE> propertyDescriptor)
- Parameters:
propertyId
-propertyDescriptor
-- Returns:
- true if the property was added
Adds a property for the container and all its items. Primarily for internal use, may change in future versions.
addNestedContainerProperty
public boolean addNestedContainerProperty(String propertyId)
- Parameters:
propertyId
-propertyType
-- Returns:
- true if the property was added
- See Also:
NestedMethodProperty
Adds a nested container property for the container, e.g. "manager.address.street". All intermediate getters must exist and must return non-null values when the property value is accessed.
removeContainerProperty
public boolean removeContainerProperty(Object propertyId)
throws UnsupportedOperationException
- Specified by:
removeContainerProperty
in interfaceContainer
- Overrides:
removeContainerProperty
in classAbstractInMemoryContainer<IDTYPE,String,BeanItem<BEANTYPE>>
- Parameters:
propertyId
- ID of the Property to remove- Returns:
true
if the operation succeeded,false
if not- Throws:
UnsupportedOperationException
- if the container does not support removing container properties
Description copied from interface: Container
Removes a Property specified by the given Property ID from the Container. Note that the Property will be removed from all Items in the Container. This functionality is optional.