com.vaadin.flow.data.provider.
Class DataCommunicator<T>
- java.lang.Object
-
- com.vaadin.flow.data.provider.DataCommunicator<T>
-
Type Parameters:
T
- the bean typeAll Implemented Interfaces:
public class DataCommunicator<T> extends Object implements Serializable
DataProvider base class. This class is the base for all DataProvider communication implementations. It uses data generators (
BiFunction
s) to writeJsonObject
s representing each data object to be sent to the client-side.See Also:
-
-
Constructor Summary
Constructors Constructor and Description DataCommunicator(DataGenerator<T> dataGenerator, ArrayUpdater arrayUpdater, SerializableConsumer<elemental.json.JsonArray> dataUpdater, StateNode stateNode)
Creates a new instance.
-
Method Summary
All Methods Modifier and Type Method and Description void
confirmUpdate(int updateId)
Confirm update with the given
updateId
.protected Stream<T>
fetchFromProvider(int offset, int limit)
Fetches a list of items from the DataProvider.
List<QuerySortOrder>
getBackEndSorting()
Returns the
QuerySortOrder
to use with backend sorting.DataProvider<T,?>
getDataProvider()
Gets the current data provider from this DataCommunicator.
protected int
getDataProviderSize()
Getter method for finding the size of DataProvider.
protected Object
getFilter()
Get the object used for filtering in this data communicator.
SerializableComparator<T>
getInMemorySorting()
Returns the
Comparator
to use with in-memory sorting.DataKeyMapper<T>
getKeyMapper()
Gets the
DataKeyMapper
used by thisDataCommunicator
.void
refresh(T data)
Informs the DataCommunicator that a data object has been updated.
void
reset()
Resets all the data.
void
setBackEndSorting(List<QuerySortOrder> sortOrder)
Sets the
QuerySortOrder
s to use with backend sorting.<F> SerializableConsumer<F>
setDataProvider(DataProvider<T,F> dataProvider, F initialFilter)
Sets the current data provider for this DataCommunicator.
void
setInMemorySorting(SerializableComparator<T> comparator)
Sets the
Comparator
to use with in-memory sorting.void
setRequestedRange(int start, int length)
Sets the requested range of data to be sent.
-
-
-
Constructor Detail
-
DataCommunicator
public DataCommunicator(DataGenerator<T> dataGenerator, ArrayUpdater arrayUpdater, SerializableConsumer<elemental.json.JsonArray> dataUpdater, StateNode stateNode)
Creates a new instance.
Parameters:
dataGenerator
- the data generator functionarrayUpdater
- array updater strategydataUpdater
- data updater strategystateNode
- the state node used to communicate for
-
-
Method Detail
-
setRequestedRange
public void setRequestedRange(int start, int length)
Sets the requested range of data to be sent.
Parameters:
start
- the start of the requested rangelength
- the end of the requested range
-
reset
public void reset()
Resets all the data.
It effectively resends all available data.
-
refresh
public void refresh(T data)
Informs the DataCommunicator that a data object has been updated.
Parameters:
data
- updated data object; notnull
-
confirmUpdate
public void confirmUpdate(int updateId)
Confirm update with the given
updateId
.Parameters:
updateId
- the update identifier
-
getDataProvider
public DataProvider<T,?> getDataProvider()
Gets the current data provider from this DataCommunicator.
Returns:
the data provider
-
setDataProvider
public <F> SerializableConsumer<F> setDataProvider(DataProvider<T,F> dataProvider, F initialFilter)
Sets the current data provider for this DataCommunicator.
The returned consumer can be used to set some other filter value that should be included in queries sent to the data provider. It is only valid until another data provider is set.
Type Parameters:
F
- the filter typeParameters:
dataProvider
- the data provider to set, notnull
initialFilter
- the initial filter value to use, ornull
to not use any initial filter valueReturns:
a consumer that accepts a new filter value to use
-
getKeyMapper
public DataKeyMapper<T> getKeyMapper()
Gets the
DataKeyMapper
used by thisDataCommunicator
. Key mapper can be used to map keys sent to the client-side back to their respective data objects.Returns:
key mapper
-
setInMemorySorting
public void setInMemorySorting(SerializableComparator<T> comparator)
Sets the
Comparator
to use with in-memory sorting.Parameters:
comparator
- comparator used to sort data
-
getInMemorySorting
public SerializableComparator<T> getInMemorySorting()
Returns the
Comparator
to use with in-memory sorting.Returns:
comparator used to sort data
-
setBackEndSorting
public void setBackEndSorting(List<QuerySortOrder> sortOrder)
Sets the
QuerySortOrder
s to use with backend sorting.Parameters:
sortOrder
- list of sort order information to pass to a query
-
getBackEndSorting
public List<QuerySortOrder> getBackEndSorting()
Returns the
QuerySortOrder
to use with backend sorting.Returns:
an unmodifiable list of sort order information to pass to a query
-
getDataProviderSize
protected int getDataProviderSize()
Getter method for finding the size of DataProvider. Can be overridden by a subclass that uses a specific type of DataProvider and/or query.
Returns:
the size of data provider with current filter
-
getFilter
protected Object getFilter()
Get the object used for filtering in this data communicator.
Returns:
the filter object of this data communicator
-
-