Class ListDataSource<T>
- java.lang.Object
-
- com.vaadin.v7.client.widget.grid.datasources.ListDataSource<T>
-
- All Implemented Interfaces:
DataSource<T>
public class ListDataSource<T> extends Object implements DataSource<T>
A simple list based on an in-memory data source for simply adding a list of row pojos to the grid. Based on a wrapped list instance which supports adding and removing of items.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));
- Since:
- 7.4
- Author:
- Vaadin Ltd
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.vaadin.client.data.DataSource
DataSource.RowHandle<T extends Object>
-
-
Constructor Summary
Constructors Constructor Description ListDataSource(List<T> datasource)Constructs a new list data source.ListDataSource(T... rows)Constructs a data source with a set of rows.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description com.vaadin.shared.RegistrationaddDataChangeHandler(DataChangeHandler dataChangeHandler)List<T>asList()Gets the list that backs this datasource.voidensureAvailability(int firstRowIndex, int numberOfRows)DataSource.RowHandle<T>getHandle(T row)TgetRow(int rowIndex)SelectAllHandler<T>getSelectAllHandler()Returns aSelectAllHandlerfor this ListDataSource.intindexOf(T row)Retrieves the index for given row object.booleanisWaitingForData()intsize()voidsort(Comparator<T> comparator)Sort entire container according to aComparator.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.vaadin.client.data.DataSource
addDataChangeHandler
-
-
-
-
Constructor Detail
-
ListDataSource
public ListDataSource(List<T> datasource)
Constructs a new list data source.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().- Parameters:
datasource- The list to use for providing the data to the grid
-
-
Method Detail
-
ensureAvailability
public void ensureAvailability(int firstRowIndex, int numberOfRows)- Specified by:
ensureAvailabilityin interfaceDataSource<T>
-
getRow
public T getRow(int rowIndex)
- Specified by:
getRowin interfaceDataSource<T>
-
size
public int size()
- Specified by:
sizein interfaceDataSource<T>
-
addDataChangeHandler
public com.vaadin.shared.Registration addDataChangeHandler(DataChangeHandler dataChangeHandler)
- Specified by:
addDataChangeHandlerin interfaceDataSource<T>
-
asList
public List<T> asList()
Gets the list that backs this datasource. Any changes made to this list will be reflected in the datasource.Note: The list is not the same list as passed into the data source via the constructor.
- Returns:
- Returns a list implementation that wraps the real list that backs the data source and provides events for the data source listeners.
-
getHandle
public DataSource.RowHandle<T> getHandle(T row) throws IllegalStateException
- Specified by:
getHandlein interfaceDataSource<T>- Throws:
IllegalStateException
-
sort
public void sort(Comparator<T> comparator)
Sort entire container according to aComparator.- Parameters:
comparator- a comparator object, which compares two data source entries (beans/pojos)
-
indexOf
public int indexOf(T row)
Retrieves the index for given row object.Note: This method does not verify that the given row object exists at all in this DataSource.
- Parameters:
row- the row object- Returns:
- index of the row; or
-1if row is not available
-
getSelectAllHandler
public SelectAllHandler<T> getSelectAllHandler()
Returns aSelectAllHandlerfor this ListDataSource.- Returns:
- select all handler
-
isWaitingForData
public boolean isWaitingForData()
- Specified by:
isWaitingForDatain interfaceDataSource<T>
-
-