com.google.gwt.widgetideas.table.client
Class CachedTableModel<R>

java.lang.Object
  extended by com.google.gwt.widgetideas.table.client.TableModel<R>
      extended by com.google.gwt.widgetideas.table.client.CachedTableModel<R>
Type Parameters:
R - the data type of the row values
All Implemented Interfaces:
SourceTableModelEvents

public class CachedTableModel<R>
extends TableModel<R>

A TableModel that wraps another TableModel and adds its own cache so subsequent requests for the same data will not require another TableModel request.

Cache

The CachedTableModel supports caching rows of data before they are needed, allowing listeners to request data much more quickly. When another class requests data, the CachedTableModel will feed data from its cache if available, and then it will request unavailable data from your specific implementation.

The pre cache and post cache refers to the number of rows to request in addition to the actual request. Pre cache refers to rows before the request, and post cache refers to rows after the request. For example, in applications where you expect the user to move forward quickly, you would want a large post cache.

The size of your cache depends on the implementation and usage of your view component. If you are using a view that supports paging, such as the PagingScrollTable, you should set your cache to a multiple of the page size so the user can go to the next and previous pages quickly.

Limitations

The cache is cleared every time the sort order changes. However, if you disallow column sorting or expect that the user will not sort the columns repeatedly, the cache will still improve paging performance.


Nested Class Summary
 class CachedTableModel.CacheCallback
          A callback that retrieves data from the cache.
 
Nested classes/interfaces inherited from class com.google.gwt.widgetideas.table.client.TableModel
TableModel.Callback<R>, TableModel.ColumnSortInfo, TableModel.ColumnSortList, TableModel.Request, TableModel.Response<R>, TableModel.SerializableResponse<R extends java.io.Serializable>
 
Field Summary
 
Fields inherited from class com.google.gwt.widgetideas.table.client.TableModel
ALL_ROWS, UNKNOWN_ROW_COUNT
 
Constructor Summary
CachedTableModel(TableModel<R> tableModel)
          Constructor.
 
Method Summary
 void clearCache()
          Clear all data from the cache.
 int getPostCachedRowCount()
           
 int getPreCachedRowCount()
           
protected  boolean onRowInserted(int beforeRow)
          Event fired when a row is inserted.
protected  boolean onRowRemoved(int row)
          Event fired when a row is removed.
protected  boolean onSetData(int row, int cell, java.lang.Object data)
          Event fired when the local data changes.
 void requestRows(TableModel.Request request, TableModel.Callback<R> callback)
          Generate a TableModel.Response based on a specific TableModel.Request.
 void setPostCachedRowCount(int postCacheRows)
          Set the number of rows to cache after the visible data area.
 void setPreCachedRowCount(int preCacheRows)
          Set the number of rows to cache before the visible data area.
 
Methods inherited from class com.google.gwt.widgetideas.table.client.TableModel
addTableModelListener, getRowCount, insertRow, removeRow, removeTableModelListener, setData, setRowCount
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CachedTableModel

public CachedTableModel(TableModel<R> tableModel)
Constructor.

Parameters:
tableModel - the underlying TableModel
Method Detail

clearCache

public void clearCache()
Clear all data from the cache.


getPostCachedRowCount

public int getPostCachedRowCount()
Returns:
the number of rows to cache after the requested rows

getPreCachedRowCount

public int getPreCachedRowCount()
Returns:
the number of rows to cache before the requested rows

requestRows

public void requestRows(TableModel.Request request,
                        TableModel.Callback<R> callback)
Description copied from class: TableModel
Generate a TableModel.Response based on a specific TableModel.Request. The response is passed into the TableModel.Callback.

Specified by:
requestRows in class TableModel<R>
Parameters:
request - the TableModel.Request for row data
callback - the TableModel.Callback to use for the TableModel.Response

setPostCachedRowCount

public void setPostCachedRowCount(int postCacheRows)
Set the number of rows to cache after the visible data area.

Parameters:
postCacheRows - the number of rows to post cache

setPreCachedRowCount

public void setPreCachedRowCount(int preCacheRows)
Set the number of rows to cache before the visible data area.

Parameters:
preCacheRows - the number of rows to pre cache

onRowInserted

protected boolean onRowInserted(int beforeRow)
Description copied from class: TableModel
Event fired when a row is inserted. Returning true will increment the row count by one.

Specified by:
onRowInserted in class TableModel<R>
Parameters:
beforeRow - the row index of the new row
Returns:
true if the action is successful

onRowRemoved

protected boolean onRowRemoved(int row)
Description copied from class: TableModel
Event fired when a row is removed. Returning true will decrement the row count by one.

Specified by:
onRowRemoved in class TableModel<R>
Parameters:
row - the row index of the removed row
Returns:
true if the action is successful

onSetData

protected boolean onSetData(int row,
                            int cell,
                            java.lang.Object data)
Description copied from class: TableModel
Event fired when the local data changes. Returning true will ensure that the row count is at least as one greater than the row index.

Specified by:
onSetData in class TableModel<R>
Parameters:
row - the row index
cell - the cell index
data - the new contents of the cell
Returns:
true if the action is successful