Package com.inmethod.grid
Interface IDataSource<T>
- Type Parameters:
T
- row/item model object type
- All Superinterfaces:
IClusterable
,IDetachable
,Serializable
- All Known Subinterfaces:
IAppendableDataSource<T>
- All Known Implementing Classes:
AppendableDataProviderAdapter
,DataProviderAdapter
Interface used to provide data to data views. This interface allows to create a paged DataGrid
without being able to know the exact amount of rows upfront.
An example of situation when the row count can be determined:
IDataSource<User> source = new IDataSource<User>() { public void query(IQuery query, IQueryResult<User> result) { UserDao dao = DaoManager.getUserDao(); // code to get a DAO or service object result.setTotalCount(dao.getUserCount()); Collection<User> users = dao.getUsers(query.getFrom(), query.getCount()); result.setItems(users.iterator()); } public IModel<User> model(User object) { return new DetachableUserModel(object); } }An example of situation when the row count can't be determined. The pagination then only allows to advance by one page. The idea is to retrieve n + 1 rows when n rows are requested to decide whether the next page should be available:
IDataSource<User> source = new IDataSource<User>() { public void query(IQuery query, IQueryResult<User> result) { UserDao dao = DaoManager.getUserDao(); // code to get a DAO or service object Collection<User> users = dao.getUsers(query.getFrom(), query.getCount() + 1); if (users.size() < query.getCount() + 1) { result.setTotalCount(IQueryResult.NO_MORE_ITEMS); } else { result.setTotalCount(IQueryResult.MORE_ITEMS); } result.setItems(users.iterator()); } public IModel<User> model(User object) { return new DetachableUserModel(object); } }
- Author:
- Matej Knopp
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
Specifies the subset of data to be loaded.static interface
Used to pass the total row count and the loaded item to the caller ofquery(IDataSource.IQuery, IDataSource.IQueryResult)
method. -
Method Summary
Modifier and TypeMethodDescriptionAllows wrapping the object in a model which will be set as model of the appropriate row.void
query
(IDataSource.IQuery query, IDataSource.IQueryResult<T> result) Implementation of this method should load subset of the data specified byquery.getFrom()
andquery.getCount()
.Methods inherited from interface org.apache.wicket.model.IDetachable
detach
-
Method Details
-
query
Implementation of this method should load subset of the data specified byquery.getFrom()
andquery.getCount()
. Also if the total item count can be determined, it should be passed toresult
.- Parameters:
query
- Specified the amount and position of items to be queriedresult
- Allows to set the total item count and result items
-
model
Allows wrapping the object in a model which will be set as model of the appropriate row. In most cases the model should be detachable.- Parameters:
object
-- Returns:
- model that can be used to access the object
-