click-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bob Schellink <sab...@gmail.com>
Subject Promote Table getFirstRow and getLastRow to public
Date Wed, 18 Mar 2009 18:55:59 GMT
Its been suggested before to promote getFirstRow and getLastRow as 
public methods. Any reasons we should not do this for 2.1.0?

This change makes it easier to enable paging of large datasets. 
Currently a Table's rowList must contain entries (even if its just a 
placeholder object) at every index in the list.

By having the two methods as public an adapter or proxy could be used 
as the Table's rowList and it only need to be populated with the 
entries that should be displayed. So if the pageSize is 10, the 
rowList only needs 10 entries, for example:


   public class TableModel extends ArrayList {
     private Table table;
     private int numOfRows;

     public TableModel(Table table, int numOfRows) {
       this.table = table;
       this.numOfRows = numOfRows;
     }

     public Object get(final int index) {
       // Convert expected index to real index
       int realIndex = index - table.getFirstRow();
       return super.get(realIndex);
     }

     public int size() {
       // Return numOfRows e.g. 100, even if only 10 entries exist
       return numOfRows;
     }
   }

TableModel example usage:

   public void onRender() {
     TableModel model = new TableModel(table, getCustomerCount());

     table.setRowList(rows);

     List customers = getCustomers(table.getFirstRow(), 
table.getLastRow(), table.getPageSize());

     model.addAll(customers);
}

regards

bob

Mime
View raw message