Class AbstractUnsizedContainer<T>
- java.lang.Object
-
- com.vaadin.data.util.AbstractContainer
-
- org.dellroad.stuff.vaadin7.AbstractQueryContainer<T>
-
- org.dellroad.stuff.vaadin7.AbstractUnsizedContainer<T>
-
- Type Parameters:
T- the type of the Java objects that back eachItemin the container
- All Implemented Interfaces:
Container,Container.Indexed,Container.ItemSetChangeNotifier,Container.Ordered,Container.PropertySetChangeNotifier,Serializable,Connectable,PropertyExtractor<T>
public abstract class AbstractUnsizedContainer<T> extends AbstractQueryContainer<T>
A specialization ofAbstractQueryContainerthat doesn't require up-front knowledge of the underlying data's size.Subclasses only need support retrieving a contiguous window of fixed size from the underlying data via
queryWindow(); when the requested window goes beyond the end of the underlying data, a short or empty result is returned. Based on just this information, this class maintains an estimate of the size of the underlying data. Each time that size estimate changes,handleSizeChange()is invoked to schedule a (non-reentrant) property set change notification. Once the end of the underlying data is reached, the size is known.If the actual size of the underlying data is constant, this class will eventually find it. If the actual size of the underlying data can change (either up or down), this class will adapt accordingly, but only when it learns of the new size through an invocation of
queryWindow(); as this depends on how the container is used, this may not occur for a long time.When used to back a Vaadin table, the user will see a table that automatically grows as the user scrolls downward, until the actual end of the data is detected.
- See Also:
AbstractQueryContainer, Serialized Form
-
-
Nested Class Summary
-
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
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_WINDOW_SIZE
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractUnsizedContainer()Convenience constructor.protectedAbstractUnsizedContainer(int windowSize)Constructor.protectedAbstractUnsizedContainer(int windowSize, Class<? super T> type)Constructor.protectedAbstractUnsizedContainer(int windowSize, Collection<? extends PropertyDef<?>> propertyDefs)Constructor.protectedAbstractUnsizedContainer(int windowSize, PropertyExtractor<? super T> propertyExtractor)Constructor.protectedAbstractUnsizedContainer(int windowSize, PropertyExtractor<? super T> propertyExtractor, Collection<? extends PropertyDef<?>> propertyDefs)Constructor.protectedAbstractUnsizedContainer(Class<? super T> type)Convenience constructor.protectedAbstractUnsizedContainer(Collection<? extends PropertyDef<?>> propertyDefs)Convenience constructor.protectedAbstractUnsizedContainer(PropertyExtractor<? super T> propertyExtractor)Convenience constructor.protectedAbstractUnsizedContainer(PropertyExtractor<? super T> propertyExtractor, Collection<? extends PropertyDef<?>> propertyDefs)Convenience constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidfireItemSetChange(Container.ItemSetChangeEvent event)longgetCurrentSizeEstimate()Get the current size estimate for the underlying data.protected longgetLargerEstimate(long lowerBound)Estimate the size of the underlying data given thatlowerBoundis a lower bound.protected longgetSmallerEstimate(long upperBound)Handle the case where the underlying data's size has suddenly shrunk, so we need to estimate the new size.intgetWindowSize()Get the window size configured at construction time.protected abstract voidhandleSizeChange()Emit a property set change notification.protected QueryList<T>query(long hint)Perform a query to (re)generate the list of Java objects backing this container.protected abstract List<? extends T>queryWindow(long offset, int length)Query the underlying data for a window of items in the given range.-
Methods inherited from class org.dellroad.stuff.vaadin7.AbstractQueryContainer
addContainerProperty, addItem, addItem, addItemAfter, addItemAfter, addItemAt, addItemAt, addItemSetChangeListener, addListener, addListener, addPropertySetChangeListener, connect, containsId, createBackedItem, disconnect, ensureList, firstItemId, getContainerProperty, getContainerPropertyIds, getIdByIndex, getItem, getItemIds, getItemIds, getJavaObject, getPropertyExtractor, getPropertyValue, getType, indexOfId, invalidate, isFirstId, isLastId, lastItemId, nextItemId, prevItemId, reload, removeAllItems, removeContainerProperty, removeItem, removeItemSetChangeListener, removeListener, removeListener, removePropertySetChangeListener, setProperties, setPropertyExtractor, size
-
Methods inherited from class com.vaadin.data.util.AbstractContainer
fireContainerPropertySetChange, fireContainerPropertySetChange, fireItemSetChange, getItemSetChangeListeners, getListeners, getPropertySetChangeListeners, setItemSetChangeListeners, setPropertySetChangeListeners
-
-
-
-
Field Detail
-
DEFAULT_WINDOW_SIZE
public static final int DEFAULT_WINDOW_SIZE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AbstractUnsizedContainer
protected AbstractUnsizedContainer()
Convenience constructor. Equivalent to:AbstractUnsizedContainer(DEFAULT_WINDOW_SIZE)After using this constructor, subsequent invocations of
setPropertyExtractor()andsetProperties()are required to define the properties of this container and how to extract them.
-
AbstractUnsizedContainer
protected AbstractUnsizedContainer(PropertyExtractor<? super T> propertyExtractor)
Convenience constructor. Equivalent to:AbstractUnsizedContainer(DEFAULT_WINDOW_SIZE, propertyExtractor)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()
-
AbstractUnsizedContainer
protected AbstractUnsizedContainer(Collection<? extends PropertyDef<?>> propertyDefs)
Convenience constructor. Equivalent to:AbstractUnsizedContainer(DEFAULT_WINDOW_SIZE, 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 overridegetPropertyValue().- Parameters:
propertyDefs- container property definitions; null is treated like the empty set
-
AbstractUnsizedContainer
protected AbstractUnsizedContainer(PropertyExtractor<? super T> propertyExtractor, Collection<? extends PropertyDef<?>> propertyDefs)
Convenience constructor. Equivalent to:AbstractUnsizedContainer(DEFAULT_WINDOW_SIZE, propertyExtractor, propertyDefs)- 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
-
AbstractUnsizedContainer
protected AbstractUnsizedContainer(int windowSize)
Constructor.After using this constructor, subsequent invocations of
setPropertyExtractor()andsetProperties()are required to define the properties of this container and how to extract them.- Parameters:
windowSize- size of the query window- Throws:
IllegalArgumentException- ifwindowSizeis less than 1
-
AbstractUnsizedContainer
protected AbstractUnsizedContainer(int windowSize, PropertyExtractor<? super T> propertyExtractor)Constructor.After using this constructor, a subsequent invocation of
setProperties()is required to define the properties of this container.- Parameters:
windowSize- size of the query windowpropertyExtractor- used to extract properties from the underlying Java objects; may be null but then container is not usable until one is configured viasetPropertyExtractor()- Throws:
IllegalArgumentException- ifwindowSizeis less than 1
-
AbstractUnsizedContainer
protected AbstractUnsizedContainer(int windowSize, 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:
windowSize- size of the query windowpropertyDefs- container property definitions; null is treated like the empty set- Throws:
IllegalArgumentException- ifwindowSizeis less than 1
-
AbstractUnsizedContainer
protected AbstractUnsizedContainer(int windowSize, PropertyExtractor<? super T> propertyExtractor, Collection<? extends PropertyDef<?>> propertyDefs)Constructor.- Parameters:
windowSize- size of the query window (how big of a chunk we query at one time)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- Throws:
IllegalArgumentException- ifwindowSizeis less than 1
-
AbstractUnsizedContainer
protected AbstractUnsizedContainer(Class<? super T> type)
Convenience constructor. Equivalent to:AbstractUnsizedContainer(DEFAULT_WINDOW_SIZE, type)- Parameters:
type- class to introspect for@ProvidesProperty-annotated fields and 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
-
AbstractUnsizedContainer
protected AbstractUnsizedContainer(int windowSize, Class<? super T> type)Constructor.Properties will be determined by the
@ProvidesPropertyand@ProvidesPropertySortannotated methods in the given class.- Parameters:
windowSize- size of the query windowtype- 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
-
query
protected QueryList<T> query(long hint)
Description copied from class:AbstractQueryContainerPerform a query to (re)generate the list of Java objects backing this container.The particular position in the list we are interested in is given as a hint by the
hintparameter. That is, an invocation ofQueryList.get(long)(hint)is likely immediately after this method returns and if so it must complete without throwing an exception, unlesshintis out of range.The
hintcan 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 ignorehint. However, the returnedQueryListmust at least tolerate one invocation ofget(hint)without throwing an exception whenhintis less that thesize()of the returnedQueryList.- Specified by:
queryin classAbstractQueryContainer<T>- Parameters:
hint- index of the list element we are interested in- Returns:
- list of Java objects backing this container
-
getWindowSize
public int getWindowSize()
Get the window size configured at construction time.- Returns:
- configured window size
-
getCurrentSizeEstimate
public long getCurrentSizeEstimate()
Get the current size estimate for the underlying data.- Returns:
- current size estimate
-
getSmallerEstimate
protected long getSmallerEstimate(long upperBound)
Handle the case where the underlying data's size has suddenly shrunk, so we need to estimate the new size. All we know is that the actual new size isupperBoundor less. This method should guess at the new value and, when called repeatedly, should converge rapidly to zero.Note: this situation will not occur if the underlying data's size never decreases.
The implementation in
AbstractUnsizedContainerreturnsupperBound * 0.75.- Parameters:
upperBound- an upper bound on the size of the underlying data- Returns:
- estimate of the actual size of the underlying data
-
getLargerEstimate
protected long getLargerEstimate(long lowerBound)
Estimate the size of the underlying data given thatlowerBoundis a lower bound. This effectively determines how much data will appear to be "beyond" the current window.The implementation in
AbstractUnsizedContainerreturnslowerBound * 1.25.- Parameters:
lowerBound- a lower bound on the size of the underlying data- Returns:
- estimate of the actual size of the underlying data
-
fireItemSetChange
protected void fireItemSetChange(Container.ItemSetChangeEvent event)
- Overrides:
fireItemSetChangein classAbstractContainer
-
queryWindow
protected abstract List<? extends T> queryWindow(long offset, int length)
Query the underlying data for a window of items in the given range. This should return the "window" of underlying data items starting at offsetoffsetand having at least lengthlength, or else however many remain. Ifoffsetis greater than or equal to the size of the underlying data, an empty list should be returned.- Parameters:
offset- starting offset for windowlength- window size, always greater than zero- Returns:
- list containing at least
lengthitems in the window starting at offsetoffset; or less thanlengthitems ifoffset + lengthis greater than the size of the underlying data
-
handleSizeChange
protected abstract void handleSizeChange()
Emit a property set change notification.Subclasses are required to implement this so that size changes are detected.
Note: to avoid re-entrancy problems, this method should not send out any notifications itself; instead, it must schedule notifications to be delivered later (perhaps in a different thread).
- Overrides:
handleSizeChangein classAbstractQueryContainer<T>
-
-