T - the type of the Java objects that back each Item in the containerpublic abstract class AbstractQueryContainer<T> extends AbstractContainer implements PropertyExtractor<T>, Container.Ordered, Container.Indexed, Container.PropertySetChangeNotifier, Container.ItemSetChangeNotifier, Connectable
Container implementations where each Item in the container
is backed by a Java object, and the Java objects are generated via a query that returns
a QueryList containing only some portion of the total list of backing objects at any one time.
This Container's Propertys are defined via PropertyDefs, and a PropertyExtractor
is used to actually extract the property values from each underlying object (alternately, subclasses can override
getPropertyValue()). However, the easist way to configure the container Propertys
is to pass a @ProvidesProperty-annotated Java class to the AbstractQueryContainer(Class)
constructor.
This Container's item ID's are simply the indexes of the corresponding objects in the overall list. The QueryList
interface is designed for scalability; at minimum, it is required to provide only the size of the total list
(which may only be an estimate) and one backing object at a specified index.
This class will invoke query(long) as needed to (re)generate the QueryList; the QueryList is then cached.
However, if any invocation of QueryList.get(long) throws an InvalidQueryListException, then the cached
list is discarded and query(long) is invoked again to regenerate it. In this way, the QueryList is
allowed to decide, on demand, when it is invalid or incapable of providing a specific list member. For example,
when using JPA, a list may be considered invalid if the current EntityManager session has changed.
Note that the QueryList being invalid is an orthogonal concept from the contents of the list having changed.
Invalid means "this list can no longer be used" while changed means "this list contains out-of-date information".
Normally, the latter implies the former (but not vice-versa). The list becoming invalid does not in itself not cause
any notifications to be sent, so no new query will be performed until e.g. the user interface explicitly requests
more information.
Therefore, if the list size or content changes, first invoke invalidate() to discard the cached QueryList,
and then AbstractContainer.fireItemSetChange() to notify listeners; for convenience, reload() will perform these two steps for
you. The new size and content will be provided by the QueryList returned by the next invocation of query(long).
The subclass may forcibly invalidate the current QueryList via invalidate(); this merely discards it
and will force a new invocation of query(long) on the next container access. In many situations, however,
the use of invalidate() is never required.
For scalability reasons the QueryList may actually only contain a portion of the list, throwing
InvalidQueryListExceptions when other list members are accessed. An "index hint" parameter provided to
query(long) indicates which member of the container is of current interest. The returned QueryList
is required to provide exception-free access only to the indicated member, so in the extreme case only a single
list member could be kept. In practice, normally range of members near to the index hint would be kept;
see for example WindowQueryList.
AbstractContainer.BaseItemSetChangeEvent, AbstractContainer.BasePropertySetChangeEventContainer.Indexed.ItemAddEvent, Container.Indexed.ItemRemoveEventContainer.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| Modifier | Constructor and Description |
|---|---|
protected |
AbstractQueryContainer()
Constructor.
|
protected |
AbstractQueryContainer(Class<? super T> type)
Constructor.
|
protected |
AbstractQueryContainer(Collection<? extends PropertyDef<?>> propertyDefs)
Constructor.
|
protected |
AbstractQueryContainer(PropertyExtractor<? super T> propertyExtractor)
Constructor.
|
protected |
AbstractQueryContainer(PropertyExtractor<? super T> propertyExtractor,
Collection<? extends PropertyDef<?>> propertyDefs)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
addContainerProperty(Object propertyId,
Class<?> type,
Object defaultValue) |
Item |
addItem() |
Item |
addItem(Object itemId) |
Item |
addItemAfter(Object previousItemId) |
Item |
addItemAfter(Object previousItemId,
Object newItemId) |
Object |
addItemAt(int index) |
Item |
addItemAt(int index,
Object newItemId) |
void |
addItemSetChangeListener(Container.ItemSetChangeListener listener) |
void |
addListener(Container.ItemSetChangeListener listener) |
void |
addListener(Container.PropertySetChangeListener listener) |
void |
addPropertySetChangeListener(Container.PropertySetChangeListener listener) |
void |
connect()
Connect this instance to non-Vaadin resources.
|
boolean |
containsId(Object itemId) |
protected BackedItem<T> |
createBackedItem(T object,
Collection<PropertyDef<?>> propertyDefs,
PropertyExtractor<? super T> propertyExtractor)
Create a
BackedItem for the given backing Java object. |
void |
disconnect()
Disconnect this instance from non-Vaadin resources.
|
protected long |
ensureList(int hint)
Ensure we have a cached query list.
|
Integer |
firstItemId() |
Property |
getContainerProperty(Object itemId,
Object propertyId) |
Set<String> |
getContainerPropertyIds() |
Integer |
getIdByIndex(int index) |
BackedItem<T> |
getItem(Object itemId) |
Collection<Integer> |
getItemIds() |
List<Integer> |
getItemIds(int startIndex,
int numberOfItems) |
protected T |
getJavaObject(int index)
Get the Java backing object at the given index in the list.
|
PropertyExtractor<? super T> |
getPropertyExtractor()
Get the configured
PropertyExtractor for this container. |
<V> V |
getPropertyValue(T obj,
PropertyDef<V> propertyDef)
Read the value of the property defined by
propertyDef from the given object. |
Class<?> |
getType(Object propertyId) |
protected void |
handleSizeChange()
|
int |
indexOfId(Object itemId) |
protected void |
invalidate()
Discard the current cached
QueryList, if any. |
boolean |
isFirstId(Object itemId) |
boolean |
isLastId(Object itemId) |
Integer |
lastItemId() |
Integer |
nextItemId(Object itemId) |
Integer |
prevItemId(Object itemId) |
protected abstract QueryList<? extends T> |
query(long hint)
Perform a query to (re)generate the list of Java objects backing this container.
|
void |
reload()
Reload this container.
|
boolean |
removeAllItems() |
boolean |
removeContainerProperty(Object propertyId) |
boolean |
removeItem(Object itemId) |
void |
removeItemSetChangeListener(Container.ItemSetChangeListener listener) |
void |
removeListener(Container.ItemSetChangeListener listener) |
void |
removeListener(Container.PropertySetChangeListener listener) |
void |
removePropertySetChangeListener(Container.PropertySetChangeListener listener) |
void |
setProperties(Collection<? extends PropertyDef<?>> propertyDefs)
Change the configured properties of this container.
|
void |
setPropertyExtractor(PropertyExtractor<? super T> propertyExtractor)
Change the configured
PropertyExtractor for this container. |
int |
size() |
fireContainerPropertySetChange, fireContainerPropertySetChange, fireItemSetChange, fireItemSetChange, getItemSetChangeListeners, getListeners, getPropertySetChangeListeners, setItemSetChangeListeners, setPropertySetChangeListenersprotected AbstractQueryContainer()
After using this constructor, subsequent invocations of setPropertyExtractor()
and setProperties() are required to define the properties of this container
and how to extract them.
protected AbstractQueryContainer(PropertyExtractor<? super T> propertyExtractor)
After using this constructor, a subsequent invocation of setProperties() is required
to define the properties of this container.
propertyExtractor - used to extract properties from the underlying Java objects;
may be null but then container is not usable until one is configured via
setPropertyExtractor()protected AbstractQueryContainer(Collection<? extends PropertyDef<?>> propertyDefs)
After using this constructor, a subsequent invocation of setPropertyExtractor()
is required to define how to extract the properties of this container; alternately, subclasses can override
getPropertyValue().
propertyDefs - container property definitions; null is treated like the empty setprotected AbstractQueryContainer(PropertyExtractor<? super T> propertyExtractor, Collection<? extends PropertyDef<?>> propertyDefs)
propertyExtractor - used to extract properties from the underlying Java objects;
may be null but then container is not usable until one is configured via
setPropertyExtractor()propertyDefs - container property definitions; null is treated like the empty setprotected AbstractQueryContainer(Class<? super T> type)
Properties will be determined by the @ProvidesProperty and
@ProvidesPropertySort annotated methods in the given class.
type - class to introspect for annotated methodsIllegalArgumentException - if type is nullIllegalArgumentException - if type has two @ProvidesProperty
or @ProvidesPropertySort annotated 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" methodProvidesProperty,
ProvidesPropertySort,
ProvidesPropertyScannerpublic PropertyExtractor<? super T> getPropertyExtractor()
PropertyExtractor for this container.PropertyExtractorpublic void setPropertyExtractor(PropertyExtractor<? super T> propertyExtractor)
PropertyExtractor for this container.
Invoking this method does not result in any container notifications.propertyExtractor - used to extract properties from the underlying Java objects;
may be null but the container is not usable without onepublic <V> V getPropertyValue(T obj, PropertyDef<V> propertyDef)
propertyDef from the given object.
The implementation in AbstractQueryContainer just delegates to the configured
PropertyExtractor; subclasses may override to customize property extraction.
getPropertyValue in interface PropertyExtractor<T>V - value typeobj - Java objectpropertyDef - definition of which property to readNullPointerException - if either parameter is nullIllegalStateException - if no PropertyExtractor is configured for this containerpublic void setProperties(Collection<? extends PropertyDef<?>> propertyDefs)
propertyDefs - container property definitions; null is treated like the empty setIllegalArgumentException - if propertyDefs contains a property with a duplicate namepublic void reload()
This discards the current cached QueryList (if any) and fires an item set change event.
public void connect()
The implementation in AbstractQueryContainer does nothing.
connect in interface ConnectableIllegalStateException - if there is no VaadinSession associated with the current threadpublic void disconnect()
The implementation in AbstractQueryContainer does nothing.
disconnect in interface ConnectableIllegalStateException - if there is no VaadinSession associated with the current threadprotected abstract QueryList<? extends T> query(long hint)
The particular position in the list we are interested in is given as a hint by the hint parameter.
That is, an invocation of QueryList.get(long)(hint) is likely immediately after this method
returns and if so it must complete without throwing an exception, unless hint is out of range.
The hint can be used to implement a highly scalable query list containing external objects
(such as from a database) where only a small "window" of objects is actually kept in memory at any one time.
Of course, implementations are also free to ignore hint. However, the returned QueryList
must at least tolerate one invocation of get(hint) without throwing an exception
when hint is less that the size() of the returned QueryList.
hint - index of the list element we are interested inprotected void invalidate()
QueryList, if any.protected T getJavaObject(int index)
index - list indexindex is out of rangeprotected long ensureList(int hint)
hint - index of the list element we are interested in, passed to query(long) if no query list is cachedprotected void handleSizeChange()
QueryList has returned a changed size()
for the underlying list.
Normally, this implies an item set change notification will be generated elsewhere and so
no additional action needs to be taken by this method. However, some implementations may
lack such a mechanism, for example, when the container's size is only ever calculated when
query(long) is invoked. In such cases, this method may trigger a notification.
Note: to avoid re-entrancy problems, this method should not send out any notifications itself;
instead, it may schedule notifications to be delivered later, e.g., via VaadinUtil.invokeLater(com.vaadin.server.VaadinSession, java.lang.Runnable).
The implementation in AbstractQueryContainer does nothing, assuming the notification is handled
elsewhere. Subclasses may override if needed.
protected BackedItem<T> createBackedItem(T object, Collection<PropertyDef<?>> propertyDefs, PropertyExtractor<? super T> propertyExtractor)
BackedItem for the given backing Java object.
The implementation in AbstractQueryContainer returns
new SimpleItem<T>(object, propertyDefs, propertyExtractor).
object - underlying Java objectpropertyDefs - property definitionspropertyExtractor - extracts the property value from objectBackedItemIllegalArgumentException - if any parameter is nullpublic BackedItem<T> getItem(Object itemId)
public Collection<Integer> getItemIds()
getItemIds in interface Containerpublic Set<String> getContainerPropertyIds()
getContainerPropertyIds in interface Containerpublic Property getContainerProperty(Object itemId, Object propertyId)
getContainerProperty in interface Containerpublic boolean containsId(Object itemId)
containsId in interface Containerpublic Item addItem(Object itemId)
addItem in interface ContainerUnsupportedOperationException - alwayspublic Item addItem()
addItem in interface ContainerUnsupportedOperationException - alwayspublic boolean removeItem(Object itemId)
removeItem in interface ContainerUnsupportedOperationException - alwayspublic boolean addContainerProperty(Object propertyId, Class<?> type, Object defaultValue)
addContainerProperty in interface ContainerUnsupportedOperationException - alwayspublic boolean removeContainerProperty(Object propertyId)
removeContainerProperty in interface ContainerUnsupportedOperationException - alwayspublic boolean removeAllItems()
removeAllItems in interface ContainerUnsupportedOperationException - alwayspublic Object addItemAt(int index)
addItemAt in interface Container.IndexedUnsupportedOperationException - alwayspublic Item addItemAt(int index, Object newItemId)
addItemAt in interface Container.IndexedUnsupportedOperationException - alwayspublic Integer getIdByIndex(int index)
getIdByIndex in interface Container.Indexedpublic List<Integer> getItemIds(int startIndex, int numberOfItems)
getItemIds in interface Container.Indexedpublic int indexOfId(Object itemId)
indexOfId in interface Container.Indexedpublic Integer nextItemId(Object itemId)
nextItemId in interface Container.Orderedpublic Integer prevItemId(Object itemId)
prevItemId in interface Container.Orderedpublic Integer firstItemId()
firstItemId in interface Container.Orderedpublic Integer lastItemId()
lastItemId in interface Container.Orderedpublic boolean isFirstId(Object itemId)
isFirstId in interface Container.Orderedpublic boolean isLastId(Object itemId)
isLastId in interface Container.Orderedpublic Item addItemAfter(Object previousItemId)
addItemAfter in interface Container.OrderedUnsupportedOperationException - alwayspublic Item addItemAfter(Object previousItemId, Object newItemId)
addItemAfter in interface Container.OrderedUnsupportedOperationException - alwayspublic void addListener(Container.PropertySetChangeListener listener)
addListener in interface Container.PropertySetChangeNotifieraddListener in class AbstractContainerpublic void addPropertySetChangeListener(Container.PropertySetChangeListener listener)
addPropertySetChangeListener in interface Container.PropertySetChangeNotifieraddPropertySetChangeListener in class AbstractContainerpublic void removeListener(Container.PropertySetChangeListener listener)
removeListener in interface Container.PropertySetChangeNotifierremoveListener in class AbstractContainerpublic void removePropertySetChangeListener(Container.PropertySetChangeListener listener)
removePropertySetChangeListener in interface Container.PropertySetChangeNotifierremovePropertySetChangeListener in class AbstractContainerpublic void addListener(Container.ItemSetChangeListener listener)
addListener in interface Container.ItemSetChangeNotifieraddListener in class AbstractContainerpublic void addItemSetChangeListener(Container.ItemSetChangeListener listener)
addItemSetChangeListener in interface Container.ItemSetChangeNotifieraddItemSetChangeListener in class AbstractContainerpublic void removeListener(Container.ItemSetChangeListener listener)
removeListener in interface Container.ItemSetChangeNotifierremoveListener in class AbstractContainerpublic void removeItemSetChangeListener(Container.ItemSetChangeListener listener)
removeItemSetChangeListener in interface Container.ItemSetChangeNotifierremoveItemSetChangeListener in class AbstractContainerCopyright © 2017. All rights reserved.