com.vaadin.flow.data.provider.
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 dataAll Implemented Interfaces:
DataView<T>
,LazyDataView<T>
,Serializable
Direct Known Subclasses:
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:
-
-
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 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.
T
getItem(int index)
Gets the item at the given index from the data available to the component.
int
getItemCountEstimate()
Gets the item count estimate.
int
getItemCountEstimateIncrease()
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 supported
DataProvider
type for thisDataView
.void
setItemCountEstimate(int itemCountEstimate)
Sets the estimated item count for the component.
void
setItemCountEstimateIncrease(int itemCountEstimateIncrease)
Sets how much the item count estimate is increased once the previous item count estimate has been reached.
void
setItemCountFromDataProvider()
Switches the component to get the exact item count from the data provider's
DataProvider.size(Query)
.void
setItemCountUnknown()
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
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:
getItem
in interfaceDataView<T>
Parameters:
index
- the index of the item to getReturns:
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:
DataView
Get 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:
AbstractDataView
Returns supported
DataProvider
type for thisDataView
.Specified by:
getSupportedDataProviderType
in classAbstractDataView<T>
Returns:
supported data provider type
-
setItemCountEstimate
public void setItemCountEstimate(int itemCountEstimate)
Description copied from interface:
LazyDataView
Sets 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:
setItemCountEstimate
in interfaceLazyDataView<T>
Parameters:
itemCountEstimate
- estimated item count of the backendSee Also:
LazyDataView.setItemCountUnknown()
,LazyDataView.setItemCountEstimateIncrease(int)
-
getItemCountEstimate
public int getItemCountEstimate()
Description copied from interface:
LazyDataView
Gets the item count estimate. The default value depends on the component.
Specified by:
getItemCountEstimate
in interfaceLazyDataView<T>
Returns:
item count estimate
See Also:
-
setItemCountEstimateIncrease
public void setItemCountEstimateIncrease(int itemCountEstimateIncrease)
Description copied from interface:
LazyDataView
Sets 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
1000
and 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:
setItemCountEstimateIncrease
in interfaceLazyDataView<T>
Parameters:
itemCountEstimateIncrease
- how much the item count estimate is increasedSee Also:
-
getItemCountEstimateIncrease
public int getItemCountEstimateIncrease()
Description copied from interface:
LazyDataView
Gets 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:
getItemCountEstimateIncrease
in interfaceLazyDataView<T>
Returns:
the item count estimate increase
See Also:
-
setItemCountFromDataProvider
public void setItemCountFromDataProvider()
Description copied from interface:
LazyDataView
Switches the component to get the exact item count from the data provider's
DataProvider.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:
setItemCountFromDataProvider
in interfaceLazyDataView<T>
-
setItemCountUnknown
public void setItemCountUnknown()
Description copied from interface:
LazyDataView
Switches 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:
setItemCountUnknown
in interfaceLazyDataView<T>
-
-