Class AbstractLazyDataView<T>
- java.lang.Object
-
- com.vaadin.flow.data.provider.AbstractDataView<T>
-
- com.vaadin.flow.data.provider.AbstractLazyDataView<T>
-
- Type Parameters:
T- the type of data
- All Implemented Interfaces:
DataView<T>,LazyDataView<T>,Serializable
public abstract class AbstractLazyDataView<T> extends AbstractDataView<T> implements LazyDataView<T>
Abstract lazy data view implementation which handles the interaction with a data communicator.- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class com.vaadin.flow.data.provider.AbstractDataView
component, dataProviderSupplier, NULL_IDENTIFIER_ERROR_MESSAGE, NULL_ITEM_ERROR_MESSAGE
-
-
Constructor Summary
Constructors Constructor Description AbstractLazyDataView(DataCommunicator<T> dataCommunicator, Component component)Creates a new instance and verifies the passed data provider is compatible with this data view implementation.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected DataCommunicator<T>getDataCommunicator()Returns the data communicator for the component and checks that the data provider is of the correct type.TgetItem(int index)Gets the item at the given index from the data available to the component.intgetItemCountEstimate()Gets the item count estimate.intgetItemCountEstimateIncrease()Gets the item count estimate increase - how much the item count estimate is increased once the previous item count estimate has been reached.Stream<T>getItems()Get the full data available to the component.protected Class<?>getSupportedDataProviderType()Returns supportedDataProvidertype for thisDataView.voidsetItemCountEstimate(int itemCountEstimate)Sets the estimated item count for the component.voidsetItemCountEstimateIncrease(int itemCountEstimateIncrease)Sets how much the item count estimate is increased once the previous item count estimate has been reached.voidsetItemCountFromDataProvider()Switches the component to get the exact item count from the data provider'sDataProvider.size(Query).voidsetItemCountUnknown()Switches the component to automatically extend the number of items as the previous end is almost reached.-
Methods inherited from class com.vaadin.flow.data.provider.AbstractDataView
addIdentifierProviderChangeListener, addItemCountChangeListener, equals, getIdentifierProvider, refreshAll, refreshItem, setIdentifierProvider, verifyDataProviderType
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.vaadin.flow.data.provider.DataView
addItemCountChangeListener, refreshAll, refreshItem, setIdentifierProvider
-
-
-
-
Constructor Detail
-
AbstractLazyDataView
public AbstractLazyDataView(DataCommunicator<T> dataCommunicator, Component component)
Creates a new instance and verifies the passed data provider is compatible with this data view implementation.- Parameters:
dataCommunicator- the data communicator of the componentcomponent- the component
-
-
Method Detail
-
getDataCommunicator
protected DataCommunicator<T> getDataCommunicator()
Returns the data communicator for the component and checks that the data provider is of the correct type.- Returns:
- the data communicator
-
getItem
public T getItem(int index)
Gets the item at the given index from the data available to the component. Data is filtered and sorted the same way as in the component.Calling this method with an index that is not currently active in the component will cause a query to the backend, so do not call this method carelessly. Use
UI.beforeClientResponse(Component, SerializableConsumer)to access items that will be fetched later on.- Specified by:
getItemin interfaceDataView<T>- Parameters:
index- the index of the item to get- Returns:
- item on index
- Throws:
IndexOutOfBoundsException- requested index is outside of the filtered and sorted data set
-
getItems
public Stream<T> getItems()
Description copied from interface:DataViewGet the full data available to the component. Data is filtered and sorted the same way as in the component.
-
getSupportedDataProviderType
protected Class<?> getSupportedDataProviderType()
Description copied from class:AbstractDataViewReturns supportedDataProvidertype for thisDataView.- Specified by:
getSupportedDataProviderTypein classAbstractDataView<T>- Returns:
- supported data provider type
-
setItemCountEstimate
public void setItemCountEstimate(int itemCountEstimate)
Description copied from interface:LazyDataViewSets the estimated item count for the component. The component will automatically fetch more items once the estimate is reached or adjust the count if the backend runs out of items before the end. Use this when the backend will have a lot more items than shown by default and it should be shown to the user.The given estimate is discarded if it is less than the currently shown range or if the actual number of items has been determined. The estimate shouldn't be less than two pages (see
setPageSize(int)in the component) or it causes unnecessary backend requests.- Specified by:
setItemCountEstimatein interfaceLazyDataView<T>- Parameters:
itemCountEstimate- estimated item count of the backend- See Also:
LazyDataView.setItemCountUnknown(),LazyDataView.setItemCountEstimateIncrease(int)
-
getItemCountEstimate
public int getItemCountEstimate()
Description copied from interface:LazyDataViewGets the item count estimate. The default value depends on the component.- Specified by:
getItemCountEstimatein interfaceLazyDataView<T>- Returns:
- item count estimate
- See Also:
LazyDataView.setItemCountEstimate(int)
-
setItemCountEstimateIncrease
public void setItemCountEstimateIncrease(int itemCountEstimateIncrease)
Description copied from interface:LazyDataViewSets how much the item count estimate is increased once the previous item count estimate has been reached. Use this when the user should be able to scroll down faster. The default value depends on the component.As an example, with an estimate of
1000and an increase of500, when scrolling down the item count will be:1000, 1500, 2000, 2500...until the backend runs out of items.NOTE: the given increase should not be less than the
setPageSize(int)set in the component, or there will be unnecessary backend requests.- Specified by:
setItemCountEstimateIncreasein interfaceLazyDataView<T>- Parameters:
itemCountEstimateIncrease- how much the item count estimate is increased- See Also:
LazyDataView.setItemCountEstimate(int)
-
getItemCountEstimateIncrease
public int getItemCountEstimateIncrease()
Description copied from interface:LazyDataViewGets the item count estimate increase - how much the item count estimate is increased once the previous item count estimate has been reached. The default value depends on the component.- Specified by:
getItemCountEstimateIncreasein interfaceLazyDataView<T>- Returns:
- the item count estimate increase
- See Also:
LazyDataView.setItemCountEstimateIncrease(int)
-
setItemCountFromDataProvider
public void setItemCountFromDataProvider()
Description copied from interface:LazyDataViewSwitches the component to get the exact item count from the data provider'sDataProvider.size(Query). Use this when it is cheap to get the exact item count and it is desired that the user sees the "full scrollbar size".- Specified by:
setItemCountFromDataProviderin interfaceLazyDataView<T>
-
setItemCountUnknown
public void setItemCountUnknown()
Description copied from interface:LazyDataViewSwitches the component to automatically extend the number of items as the previous end is almost reached. The component stops increasing the number of items once the backend has run out of items. Not getting the exact size of the backend upfront can improve performance with large sets of data.The default initial item count and how much the item count is increased depends on the component. These values can be customized with
LazyDataView.setItemCountEstimate(int)andLazyDataView.setItemCountEstimateIncrease(int)when the backend has a lot of items and faster scrolling down is desired.- Specified by:
setItemCountUnknownin interfaceLazyDataView<T>
-
-