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

public interface IDataSource<T>
extends IDetachable, IClusterable

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
static interface IDataSource.IQuery
          Specifies the subset of data to be loaded.
static interface IDataSource.IQueryResult<T>
          Used to pass the total row count and the loaded item to the caller of query(IDataSource.IQuery, IDataSource.IQueryResult) method.
 
Method Summary
 IModel<T> model(T object)
          Allows 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 by query.getFrom() and query.getCount().
 
Methods inherited from interface org.apache.wicket.model.IDetachable
detach
 

Method Detail

query

void query(IDataSource.IQuery query,
           IDataSource.IQueryResult<T> result)
Implementation of this method should load subset of the data specified by query.getFrom() and query.getCount(). Also if the total item count can be determined, it should be passed to result.

Parameters:
query - Specified the amount and position of items to be queried
result - Allows to set the total item count and result items

model

IModel<T> model(T object)
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


Copyright © 2007-2012 inMethod s.r.o.. All Rights Reserved.