com.google.gwt.widgetideas.table.client
Class CachedTableController

java.lang.Object
  extended by com.google.gwt.widgetideas.table.client.TableController
      extended by com.google.gwt.widgetideas.table.client.CachedTableController

public class CachedTableController
extends TableController

A controller that interfaces between a TableModel and mutliple views of the data. This controller has its own cache so subsequent requests for the same data will not require another TableModel request.

Cache

The CachedTableController supports caching rows of data before they are needed, allowing listeners to request data much more quickly. When another class requests data, the CachedTableController 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 PagingGrid, 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

This cache controller has some significant limitations. Row values are not cached for performance reasons and are not passed to the Controlled Tables, even on new requests to the model. You need to set them manually or keep track of them separately if they are important to you.

Additionally, 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 CachedTableController.CacheCallback
          A callback that automatically updates a ControllableTable.
 
Nested classes/interfaces inherited from class com.google.gwt.widgetideas.table.client.TableController
TableController.ControllableTableCallback
 
Constructor Summary
CachedTableController(TableModel tableModel)
          Constructor.
 
Method Summary
 java.lang.Object getData(int row, int column)
          Get data from the cache.
 int getNumPostCachedRows()
           
 int getNumPreCachedRows()
           
 void insertRow(int beforeRow)
          Insert a row of data.
 void removeRow(int row)
          Remove a row of data and decrement all rows after the removed row.
 void setData(int row, int column, java.lang.Object data)
          Set data in the controller.
 void setNumPostCachedRows(int postCacheRows)
          Set the number of rows to cache after the visible data area.
 void setNumPreCachedRows(int preCacheRows)
          Set the number of rows to cache before the visible data area.
 
Methods inherited from class com.google.gwt.widgetideas.table.client.TableController
addControllableTable, getNumRows, getTableModel, removeControllableTable, setNumRows
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CachedTableController

public CachedTableController(TableModel tableModel)
Constructor.

Parameters:
tableModel - the underlying TableModel
Method Detail

getData

public java.lang.Object getData(int row,
                                int column)
Get data from the cache. If the data is not available, this method will not request the data from the table model.

Parameters:
row - the row index
column - the column index
Returns:
the data at the index

getNumPostCachedRows

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

getNumPreCachedRows

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

insertRow

public void insertRow(int beforeRow)
Description copied from class: TableController
Insert a row of data.

Overrides:
insertRow in class TableController
Parameters:
beforeRow - the row to insert
See Also:
TableController

removeRow

public void removeRow(int row)
Description copied from class: TableController
Remove a row of data and decrement all rows after the removed row.

Overrides:
removeRow in class TableController
Parameters:
row - the row to remove
See Also:
TableController

setData

public void setData(int row,
                    int column,
                    java.lang.Object data)
Description copied from class: TableController
Set data in the controller.

Overrides:
setData in class TableController
Parameters:
row - the row index
column - the column index
data - the data to set
See Also:
TableController

setNumPostCachedRows

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

Parameters:
postCacheRows - the number of rows to post cache

setNumPreCachedRows

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

Parameters:
preCacheRows - the number of rows to pre cache