com.vaadin.client.data.
Interface DataSource<T>
-
Type Parameters:
T
- the row typeAll Known Implementing Classes:
AbstractRemoteDataSource
,DataCommunicatorConnector.VaadinDataSource
,ListDataSource
public interface DataSource<T>
Source of data for widgets showing lazily loaded data based on indexable items (e.g. rows) of a specified type. The data source is a lazy view into a larger data set.
Since:
7.4
Author:
Vaadin Ltd
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
DataSource.RowHandle<T>
A handle that contains information on whether a row should be
pinned
orunpinned
, and also always the most recent representation for that particular row.
-
Method Summary
All Methods Modifier and Type Method Description Registration
addDataChangeHandler(DataChangeHandler dataChangeHandler)
Sets a data change handler to inform when data is updated, added or removed.
default Registration
addDataChangeHandler(Consumer<Range> refreshMethod)
Sets a simple data change handler for a widget without lazy loading.
void
ensureAvailability(int firstRowIndex, int numberOfRows)
Informs the data source that data for the given range is needed.
DataSource.RowHandle<T>
getHandle(T row)
Gets a
DataSource.RowHandle
of a row object in the cache.T
getRow(int rowIndex)
Retrieves the data for the row at the given index.
boolean
isWaitingForData()
Checks whether this data source is currently waiting for more rows to become available.
int
size()
Returns the number of rows in the data source.
-
-
-
Method Detail
-
ensureAvailability
void ensureAvailability(int firstRowIndex, int numberOfRows)
Informs the data source that data for the given range is needed. A data source only has one active region at a time, so calling this method discards the previously set range.
This method triggers lazy loading of data if necessary. The change handler registered using
addDataChangeHandler(DataChangeHandler)
is informed when new data has been loaded.After any possible lazy loading and updates are done, the change handler is informed that new data is available.
Parameters:
firstRowIndex
- the index of the first needed rownumberOfRows
- the number of needed rows
-
getRow
T getRow(int rowIndex)
Retrieves the data for the row at the given index. If the row data is not available, returns
null
.This method does not trigger loading of unavailable data.
ensureAvailability(int, int)
should be used to signal what data will be needed.Parameters:
rowIndex
- the index of the row to retrieve data forReturns:
data for the row; or
null
if no data is available
-
size
int size()
Returns the number of rows in the data source.
Returns:
the current size of the data source
-
addDataChangeHandler
Registration addDataChangeHandler(DataChangeHandler dataChangeHandler)
Sets a data change handler to inform when data is updated, added or removed.
Parameters:
dataChangeHandler
- the data change handlerReturns:
registration for removing the handler
-
addDataChangeHandler
default Registration addDataChangeHandler(Consumer<Range> refreshMethod)
Sets a simple data change handler for a widget without lazy loading. Refresh method should reset all the data in the widget.
Parameters:
refreshMethod
- a method to refresh all data in the widgetReturns:
registration for removing the handler
-
getHandle
DataSource.RowHandle<T> getHandle(T row)
Gets a
DataSource.RowHandle
of a row object in the cache.Parameters:
row
- the row object for which to retrieve a row handleReturns:
a non-
null
row handle of the given row object
-
isWaitingForData
boolean isWaitingForData()
Checks whether this data source is currently waiting for more rows to become available.
Returns:
true
if waiting for data; otherwisefalse
Since:
7.7.2
-
-