Class SimpleKeyedContainer<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>
-
- org.dellroad.stuff.vaadin7.SimpleKeyedContainer<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:
SelfKeyedContainer
public abstract class SimpleKeyedContainer<I,T> extends AbstractSimpleContainer<I,T>
AnAbstractSimpleContainerwhere the item IDs are generated from the items themselves by the subclass-provided methodgetKeyFor(T).Restriction: instances can never contain two objects whose keys are equal (in the sense of
Object.equals(java.lang.Object)).- See Also:
AbstractSimpleContainer, 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 protectedSimpleKeyedContainer()Constructor.protectedSimpleKeyedContainer(Class<? super T> type)Constructor.protectedSimpleKeyedContainer(Collection<? extends PropertyDef<?>> propertyDefs)Constructor.protectedSimpleKeyedContainer(PropertyExtractor<? super T> propertyExtractor)Constructor.protectedSimpleKeyedContainer(PropertyExtractor<? super T> propertyExtractor, Collection<? extends PropertyDef<?>> propertyDefs)Constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected IgenerateItemId(T obj)Create a new, unique item ID for the given object.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.TgetJavaObject(Object itemId)Get the underlying Java object corresponding to the given item ID.protected abstract IgetKeyFor(T obj)Get the key to be used as item ID for the given object.protected voidresetItemIds()Subclass hook invoked prior to each reload.-
Methods inherited from class org.dellroad.stuff.vaadin7.AbstractSimpleContainer
addContainerFilter, addContainerFilter, afterReload, connect, createBackedItem, disconnect, getContainerFilters, getContainerProperty, getContainerPropertyIds, getItemIds, getPropertyExtractor, getPropertyValue, getSortableContainerPropertyIds, getType, getUnfilteredItem, internalRemoveAllItems, load, load, removeAllContainerFilters, removeContainerFilter, removeContainerFilters, setProperties, setProperty, setPropertyExtractor, sort
-
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
-
SimpleKeyedContainer
protected SimpleKeyedContainer()
Constructor.After using this constructor, subsequent invocations of
setPropertyExtractor()andsetProperties()are required to define the properties of this container and how to extract them.
-
SimpleKeyedContainer
protected SimpleKeyedContainer(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()
-
SimpleKeyedContainer
protected SimpleKeyedContainer(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
-
SimpleKeyedContainer
protected SimpleKeyedContainer(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
-
SimpleKeyedContainer
protected SimpleKeyedContainer(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
-
getJavaObject
public T getJavaObject(Object itemId)
Description copied from class:AbstractSimpleContainerGet the underlying Java object corresponding to the given item ID. This method ignores any filtering (i.e., filtered-out objects are still accessible).- Specified by:
getJavaObjectin classAbstractSimpleContainer<I,T>- Parameters:
itemId- item ID- Returns:
- the corresponding Java object, or null if not found
-
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().This method uses an internal hash map for efficiency, and assumes that two underlying container objects that are equal will have the same key.
This method is not used by this class but is defined as a convenience for subclasses.
- Overrides:
getItemIdForin classAbstractSimpleContainer<I,T>- 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().This method uses an internal hash map for efficiency.
This method is not used by this class but is defined as a convenience for subclasses.
- Overrides:
getItemIdForSamein classAbstractSimpleContainer<I,T>- 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)
-
resetItemIds
protected void resetItemIds()
Description copied from class:AbstractSimpleContainerSubclass hook invoked prior to each reload. The subclass should reset its state (e.g., issued item IDs) as required.- Specified by:
resetItemIdsin classAbstractSimpleContainer<I,T>
-
generateItemId
protected final I generateItemId(T obj)
Description copied from class:AbstractSimpleContainerCreate 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
AbstractSimpleContainer.resetItemIds().- Specified by:
generateItemIdin classAbstractSimpleContainer<I,T>- Parameters:
obj- underlying container object, never null- Returns:
- item ID, never null
-
getKeyFor
protected abstract I getKeyFor(T obj)
Get the key to be used as item ID for the given object. All objects in the container must have unique keys. This method must return the same key for the same object even if invoked multiple times.- Parameters:
obj- underlying container object- Returns:
- key for object
-
-