Class AbstractSimpleContainer<I,T>
- java.lang.Object
-
- com.vaadin.data.util.AbstractContainer
-
- com.vaadin.data.util.AbstractInMemoryContainer<I,String,BackedItem<T>>
-
- org.dellroad.stuff.vaadin7.AbstractSimpleContainer<I,T>
-
- Type Parameters:
I- the item ID typeT- the type of the Java objects that back eachItemin the container
- All Implemented Interfaces:
Container,Container.Filterable,Container.Indexed,Container.ItemSetChangeNotifier,Container.Ordered,Container.SimpleFilterable,Container.Sortable,Serializable,Connectable,PropertyExtractor<T>
- Direct Known Subclasses:
SimpleContainer,SimpleKeyedContainer
public abstract class AbstractSimpleContainer<I,T> extends AbstractInMemoryContainer<I,String,BackedItem<T>> implements PropertyExtractor<T>, Container.Filterable, Container.SimpleFilterable, Container.Sortable, Connectable
Support superclass for simple read-only, in-memoryContainerimplementations where eachItemin the container is backed by a Java object.This
Container'sPropertys are defined viaPropertyDefs, and aPropertyExtractoris used to actually extract the property values from each underlying object (alternately, subclasses can overridegetPropertyValue()). However, the easist way to configure the containerPropertys is to pass a@ProvidesProperty-annotated Java class to theAbstractSimpleContainer(Class)constructor.Use
load()to load or reload the container.- See Also:
SimpleItem, Serialized Form
-
-
Nested Class Summary
-
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 Modifier Constructor Description protectedAbstractSimpleContainer()Constructor.protectedAbstractSimpleContainer(Class<? super T> type)Constructor.protectedAbstractSimpleContainer(Collection<? extends PropertyDef<?>> propertyDefs)Constructor.protectedAbstractSimpleContainer(PropertyExtractor<? super T> propertyExtractor)Constructor.protectedAbstractSimpleContainer(PropertyExtractor<? super T> propertyExtractor, Collection<? extends PropertyDef<?>> propertyDefs)Constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddContainerFilter(Container.Filter filter)voidaddContainerFilter(Object propertyId, String filterString, boolean ignoreCase, boolean onlyMatchPrefix)protected voidafterReload()Subclass hook invoked after each reload but prior to invokingAbstractContainer.fireItemSetChange().voidconnect()Connect this instance to non-Vaadin resources.protected BackedItem<T>createBackedItem(T object, Collection<PropertyDef<?>> propertyDefs, PropertyExtractor<? super T> propertyExtractor)Create aBackedItemfor the given backing Java object.voiddisconnect()Disconnect this instance from non-Vaadin resources.protected abstract IgenerateItemId(T obj)Create a new, unique item ID for the given object.Collection<Container.Filter>getContainerFilters()Property<?>getContainerProperty(Object itemId, Object propertyId)Set<String>getContainerPropertyIds()IgetItemIdFor(T obj)Get the container item ID corresponding to the given underlying Java object which is wrapped by this container.IgetItemIdForSame(T obj)Get the container item ID corresponding to the given underlying Java object which is wrapped by this container.List<I>getItemIds()abstract TgetJavaObject(Object itemId)Get the underlying Java object corresponding to the given item ID.PropertyExtractor<? super T>getPropertyExtractor()Get the configuredPropertyExtractorfor this container.<V> VgetPropertyValue(T obj, PropertyDef<V> propertyDef)Read the value of the property defined bypropertyDeffrom the given object.Collection<?>getSortableContainerPropertyIds()Class<?>getType(Object propertyId)BackedItem<T>getUnfilteredItem(Object itemId)protected voidinternalRemoveAllItems()voidload(Iterable<? extends T> contents)Change this container's contents.voidload(Iterator<? extends T> contents)Change this container's contents.voidremoveAllContainerFilters()voidremoveContainerFilter(Container.Filter filter)voidremoveContainerFilters(Object propertyId)protected abstract voidresetItemIds()Subclass hook invoked prior to each reload.voidsetProperties(Collection<? extends PropertyDef<?>> propertyDefs)Change the configured properties of this container.voidsetProperty(PropertyDef<?> propertyDef)Add or replace a configured property of this container.voidsetPropertyExtractor(PropertyExtractor<? super T> propertyExtractor)Change the configuredPropertyExtractorfor this container.voidsort(Object[] propertyId, boolean[] ascending)-
Methods inherited from class com.vaadin.data.util.AbstractInMemoryContainer
addContainerProperty, addFilter, addItem, addItem, addItemAfter, addItemAfter, addItemAt, addItemAt, addItemSetChangeListener, addListener, containsId, doFilterContainer, doSort, filterAll, fireItemAdded, fireItemRemoved, fireItemsAdded, fireItemsRemoved, firstItemId, getAllItemIds, getFilteredItemIds, getFilters, getFirstVisibleItem, getIdByIndex, getItem, getItemIds, getItemSorter, getSortablePropertyIds, getVisibleItemIds, hasContainerFilters, indexOfId, internalAddItemAfter, internalAddItemAt, internalAddItemAtEnd, internalRemoveItem, isFiltered, isFirstId, isLastId, isPropertyFiltered, lastItemId, nextItemId, passesFilters, prevItemId, registerNewItem, removeAllFilters, removeAllItems, removeContainerProperty, removeFilter, removeFilters, removeItem, removeItemSetChangeListener, removeListener, setAllItemIds, setFilteredItemIds, setFilters, setItemSorter, size, sortContainer
-
Methods inherited from class com.vaadin.data.util.AbstractContainer
addListener, addPropertySetChangeListener, fireContainerPropertySetChange, fireContainerPropertySetChange, fireItemSetChange, fireItemSetChange, getItemSetChangeListeners, getListeners, getPropertySetChangeListeners, removeListener, removePropertySetChangeListener, 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
addContainerProperty, addItem, addItem, containsId, getItem, removeAllItems, removeContainerProperty, removeItem, size
-
Methods inherited from interface com.vaadin.data.Container.Ordered
addItemAfter, addItemAfter, firstItemId, isFirstId, isLastId, lastItemId, nextItemId, prevItemId
-
-
-
-
Constructor Detail
-
AbstractSimpleContainer
protected AbstractSimpleContainer()
Constructor.After using this constructor, subsequent invocations of
setPropertyExtractor()andsetProperties()are required to define the properties of this container and how to extract them.
-
AbstractSimpleContainer
protected AbstractSimpleContainer(PropertyExtractor<? super T> propertyExtractor)
Constructor.After using this constructor, a subsequent invocation of
setProperties()is required to define the properties of this container.- Parameters:
propertyExtractor- used to extract properties from the underlying Java objects; may be null but then container is not usable until one is configured viasetPropertyExtractor()
-
AbstractSimpleContainer
protected AbstractSimpleContainer(Collection<? extends PropertyDef<?>> propertyDefs)
Constructor.After using this constructor, a subsequent invocation of
setPropertyExtractor()is required to define how to extract the properties of this container; alternately, subclasses can overridegetPropertyValue().- Parameters:
propertyDefs- container property definitions; null is treated like the empty set
-
AbstractSimpleContainer
protected AbstractSimpleContainer(PropertyExtractor<? super T> propertyExtractor, Collection<? extends PropertyDef<?>> propertyDefs)
Constructor.- Parameters:
propertyExtractor- used to extract properties from the underlying Java objects; may be null but then container is not usable until one is configured viasetPropertyExtractor()propertyDefs- container property definitions; null is treated like the empty set
-
AbstractSimpleContainer
protected AbstractSimpleContainer(Class<? super T> type)
Constructor.Properties will be determined by the
@ProvidesPropertyand@ProvidesPropertySortannotated methods in the given class.- Parameters:
type- class to introspect for annotated methods- Throws:
IllegalArgumentException- iftypeis nullIllegalArgumentException- iftypehas two@ProvidesPropertyor@ProvidesPropertySortannotated methods for the same propertyIllegalArgumentException- if a@ProvidesProperty-annotated method with no property name specified has a name which cannot be interpreted as a bean property "getter" method- See Also:
ProvidesProperty,ProvidesPropertySort,ProvidesPropertyScanner
-
-
Method Detail
-
getPropertyExtractor
public PropertyExtractor<? super T> getPropertyExtractor()
Get the configuredPropertyExtractorfor this container.- Returns:
- configured
PropertyExtractor
-
setPropertyExtractor
public void setPropertyExtractor(PropertyExtractor<? super T> propertyExtractor)
Change the configuredPropertyExtractorfor this container. Invoking this method does not result in any container notifications.- Parameters:
propertyExtractor- used to extract properties from the underlying Java objects; may be null but the container is not usable without one
-
getPropertyValue
public <V> V getPropertyValue(T obj, PropertyDef<V> propertyDef)
Read the value of the property defined bypropertyDeffrom the given object.The implementation in
AbstractSimpleContainerjust delegates to the configuredPropertyExtractor; subclasses may override to customize property extraction.- Specified by:
getPropertyValuein interfacePropertyExtractor<I>- Type Parameters:
V- value type- Parameters:
obj- Java objectpropertyDef- definition of which property to read- Returns:
- property value
- Throws:
NullPointerException- if either parameter is nullIllegalStateException- if noPropertyExtractoris configured for this container
-
setProperties
public void setProperties(Collection<? extends PropertyDef<?>> propertyDefs)
Change the configured properties of this container.- Parameters:
propertyDefs- container property definitions; null is treated like the empty set- Throws:
IllegalArgumentException- ifpropertyDefscontains a property with a duplicate name
-
setProperty
public void setProperty(PropertyDef<?> propertyDef)
Add or replace a configured property of this container.- Parameters:
propertyDef- new container property definitions- Throws:
IllegalArgumentException- ifpropertyDefis null
-
load
public void load(Iterable<? extends T> contents)
Change this container's contents.- Parameters:
contents- new container contents- Throws:
IllegalArgumentException- ifcontentsor any item incontentsis null
-
load
public void load(Iterator<? extends T> contents)
Change this container's contents.- Parameters:
contents- new container contents- Throws:
IllegalArgumentException- ifcontentsor any item incontentsis null
-
internalRemoveAllItems
protected void internalRemoveAllItems()
- Overrides:
internalRemoveAllItemsin classAbstractInMemoryContainer<I,String,BackedItem<T>>
-
getItemIdFor
public I getItemIdFor(T obj)
Get the container item ID corresponding to the given underlying Java object which is wrapped by this container. Objects are tested for equality usingObject.equals().The implementation in
AbstractSimpleContainerrequires a linear search of the container. Some subclasses may provide a more efficient implementation.This method is not used by this class but is defined as a convenience for subclasses.
Note: items that are filtered out will not be found.
- Parameters:
obj- underlying container object- Returns:
- item ID corresponding to
object, or null ifobjectis not found in this container - Throws:
IllegalArgumentException- ifobjectis null- See Also:
getItemIdForSame(T)
-
getItemIdForSame
public I getItemIdForSame(T obj)
Get the container item ID corresponding to the given underlying Java object which is wrapped by this container. Objects are tested for equality using object equality, notObject.equals().The implementation in
AbstractSimpleContainerrequires a linear search of the container. Some subclasses may provide a more efficient implementation.This method is not used by this class but is defined as a convenience for subclasses.
Note: items that are filtered out will not be found.
- Parameters:
obj- underlying container object- Returns:
- item ID corresponding to
object, or null ifobjectis not found in this container - Throws:
IllegalArgumentException- ifobjectis null- See Also:
getItemIdFor(T)
-
connect
public void connect()
Connect this instance to non-Vaadin resources.The implementation in
AbstractSimpleContainerdoes nothing.- Specified by:
connectin interfaceConnectable- Throws:
IllegalStateException- if there is noVaadinSessionassociated with the current thread
-
disconnect
public void disconnect()
Disconnect this instance from non-Vaadin resources.The implementation in
AbstractSimpleContainerdoes nothing.- Specified by:
disconnectin interfaceConnectable- Throws:
IllegalStateException- if there is noVaadinSessionassociated with the current thread
-
getItemIds
public List<I> getItemIds()
- Specified by:
getItemIdsin interfaceContainer- Overrides:
getItemIdsin classAbstractInMemoryContainer<I,String,BackedItem<T>>
-
getContainerPropertyIds
public Set<String> getContainerPropertyIds()
- Specified by:
getContainerPropertyIdsin interfaceContainer
-
getContainerProperty
public Property<?> getContainerProperty(Object itemId, Object propertyId)
- Specified by:
getContainerPropertyin interfaceContainer
-
getUnfilteredItem
public BackedItem<T> getUnfilteredItem(Object itemId)
- Specified by:
getUnfilteredItemin classAbstractInMemoryContainer<I,String,BackedItem<T>>
-
getJavaObject
public abstract T getJavaObject(Object itemId)
Get the underlying Java object corresponding to the given item ID. This method ignores any filtering (i.e., filtered-out objects are still accessible).- Parameters:
itemId- item ID- Returns:
- the corresponding Java object, or null if not found
-
resetItemIds
protected abstract void resetItemIds()
Subclass hook invoked prior to each reload. The subclass should reset its state (e.g., issued item IDs) as required.
-
generateItemId
protected abstract I generateItemId(T obj)
Create a new, unique item ID for the given object. This method is invoked during a reload operation, once for each container object. Both visible and filtered objects will be passed to this method.The returned item ID must be unique, i.e., not returned by this method since the most recent invocation of
resetItemIds().- Parameters:
obj- underlying container object, never null- Returns:
- item ID, never null
-
afterReload
protected void afterReload()
Subclass hook invoked after each reload but prior to invokingAbstractContainer.fireItemSetChange().The implementation in
AbstractSimpleContainerdoes nothing.
-
createBackedItem
protected BackedItem<T> createBackedItem(T object, Collection<PropertyDef<?>> propertyDefs, PropertyExtractor<? super T> propertyExtractor)
Create aBackedItemfor the given backing Java object.The implementation in
AbstractSimpleContainerreturnsnew SimpleItem<T>(object, propertyDefs, propertyExtractor).- Parameters:
object- underlying Java objectpropertyDefs- property definitionspropertyExtractor- extracts the property value fromobject- Returns:
- new
BackedItem - Throws:
IllegalArgumentException- if any parameter is null
-
sort
public void sort(Object[] propertyId, boolean[] ascending)
- Specified by:
sortin interfaceContainer.Sortable
-
addContainerFilter
public void addContainerFilter(Object propertyId, String filterString, boolean ignoreCase, boolean onlyMatchPrefix)
- Specified by:
addContainerFilterin interfaceContainer.SimpleFilterable
-
getContainerFilters
public Collection<Container.Filter> getContainerFilters()
- Specified by:
getContainerFiltersin interfaceContainer.Filterable- Overrides:
getContainerFiltersin classAbstractInMemoryContainer<I,String,BackedItem<T>>
-
removeAllContainerFilters
public void removeAllContainerFilters()
- Specified by:
removeAllContainerFiltersin interfaceContainer.Filterable- Specified by:
removeAllContainerFiltersin interfaceContainer.SimpleFilterable
-
removeContainerFilters
public void removeContainerFilters(Object propertyId)
- Specified by:
removeContainerFiltersin interfaceContainer.SimpleFilterable
-
addContainerFilter
public void addContainerFilter(Container.Filter filter)
- Specified by:
addContainerFilterin interfaceContainer.Filterable
-
removeContainerFilter
public void removeContainerFilter(Container.Filter filter)
- Specified by:
removeContainerFilterin interfaceContainer.Filterable
-
getSortableContainerPropertyIds
public Collection<?> getSortableContainerPropertyIds()
- Specified by:
getSortableContainerPropertyIdsin interfaceContainer.Sortable
-
-