T - the type of the items in the gridpublic class ListDataSource<T> extends Object implements DataSource<T>
Usage:
ListDataSource<Integer> ds = new ListDataSource<Integer>(1, 2, 3, 4); // Add item to the data source ds.asList().add(5); // Remove item from the data source ds.asList().remove(3); // Add multiple items ds.asList().addAll(Arrays.asList(5, 6, 7));
DataSource.RowHandle<T>| Constructor and Description |
|---|
ListDataSource(List<T> datasource)
Constructs a new list data source.
|
ListDataSource(T... rows)
Constructs a data source with a set of rows.
|
| Modifier and Type | Method and Description |
|---|---|
Registration |
addDataChangeHandler(DataChangeHandler dataChangeHandler)
Sets a data change handler to inform when data is updated, added or
removed.
|
List<T> |
asList()
Gets the list that backs this datasource.
|
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.
|
SelectAllHandler<T> |
getSelectAllHandler()
Returns a
SelectAllHandler for this ListDataSource. |
int |
indexOf(T row)
Retrieves the index for given row object.
|
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.
|
void |
sort(Comparator<T> comparator)
Sort entire container according to a
Comparator. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddDataChangeHandlerpublic ListDataSource(List<T> datasource)
Note: Modifications to the original list will not be reflected in the
data source after the data source has been constructed. To add or remove
items to the data source after it has been constructed use
asList().
datasource - The list to use for providing the data to the gridpublic void ensureAvailability(int firstRowIndex,
int numberOfRows)
DataSource
This method triggers lazy loading of data if necessary. The change
handler registered using DataSource.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.
ensureAvailability in interface DataSource<T>firstRowIndex - the index of the first needed rownumberOfRows - the number of needed rowspublic T getRow(int rowIndex)
DataSourcenull.
This method does not trigger loading of unavailable data.
DataSource.ensureAvailability(int, int) should be used to signal what data
will be needed.
getRow in interface DataSource<T>rowIndex - the index of the row to retrieve data fornull if no data is availablepublic int size()
DataSourcesize in interface DataSource<T>public Registration addDataChangeHandler(DataChangeHandler dataChangeHandler)
DataSourceaddDataChangeHandler in interface DataSource<T>dataChangeHandler - the data change handlerpublic List<T> asList()
Note: The list is not the same list as passed into the data source via the constructor.
public DataSource.RowHandle<T> getHandle(T row) throws IllegalStateException
DataSourceDataSource.RowHandle of a row object in the cache.getHandle in interface DataSource<T>row - the row object for which to retrieve a row handlenull row handle of the given row objectIllegalStateExceptionpublic void sort(Comparator<T> comparator)
Comparator.comparator - a comparator object, which compares two data source entries
(beans/pojos)public int indexOf(T row)
Note: This method does not verify that the given row object exists at all in this DataSource.
row - the row object-1 if row is not availablepublic SelectAllHandler<T> getSelectAllHandler()
SelectAllHandler for this ListDataSource.public boolean isWaitingForData()
DataSourceisWaitingForData in interface DataSource<T>true if waiting for data; otherwise
falseCopyright © 2021 Vaadin Ltd. All rights reserved.