Class AbstractLazyDataView<T>
- Type Parameters:
T
- the type of data
- All Implemented Interfaces:
DataView<T>
,LazyDataView<T>
,Serializable
- Direct Known Subclasses:
ComboBoxLazyDataView
,GridLazyDataView
- 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
ConstructorDescriptionAbstractLazyDataView
(DataCommunicator<T> dataCommunicator, Component component) Creates a new instance and verifies the passed data provider is compatible with this data view implementation. -
Method Summary
Modifier and TypeMethodDescriptionprotected DataCommunicator<T>
Returns the data communicator for the component and checks that the data provider is of the correct type.getItem
(int index) Gets the item at the given index from the data available to the component.int
Gets the item count estimate.int
Gets the item count estimate increase - how much the item count estimate is increased once the previous item count estimate has been reached.getItems()
Get the full data available to the component.protected Class<?>
Returns supportedDataProvider
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
Switches the component to get the exact item count from the data provider'sDataProvider.size(Query)
.void
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 Details
-
AbstractLazyDataView
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 Details
-
getDataCommunicator
Returns the data communicator for the component and checks that the data provider is of the correct type.- Returns:
- the data communicator
-
getItem
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 get- Returns:
- item on index
- Throws:
IndexOutOfBoundsException
- requested index is outside of the filtered and sorted data set
-
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.Consumers of the returned stream are responsible for closing it when all the stream operations are done to ensure that any resources feeding the stream are properly released. Failure to close the stream might lead to resource leaks.
It is strongly recommended to use a try-with-resources block to automatically close the stream after its terminal operation has been executed. Below is an example of how to properly use and close the stream:
try (Stream<T> stream = dataView.getItems()) { stream.forEach(System.out::println); // Example terminal operation }
-
getSupportedDataProviderType
Description copied from class:AbstractDataView
Returns supportedDataProvider
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 backend- See Also:
-
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 increased- See 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'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:
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>
-