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

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

public abstract class TableModel<R>
extends java.lang.Object
implements SourceTableModelEvents

A class to retrieve row data to be used in a table.


Nested Class Summary
static interface TableModel.Callback<R>
          Callback for TableModel.
static class TableModel.ColumnSortInfo
          Information about the sort order of a specific column in a table.
static class TableModel.ColumnSortList
          An ordered list of sorting info where each entry tells us how to sort a single column.
static class TableModel.Request
          A TableModel request.
static class TableModel.Response<R>
          A response from the TableModel.
static class TableModel.SerializableResponse<R extends java.io.Serializable>
          A response from the TableModel that is serializable, and can by used over RPC.
 
Field Summary
static int ALL_ROWS
          Use the ALL_ROWS value in place of the numRows variable when requesting all rows.
static int UNKNOWN_ROW_COUNT
          Indicates that the number of rows is unknown, and therefore unbounded.
 
Constructor Summary
TableModel()
           
 
Method Summary
 void addTableModelListener(TableModelListener listener)
          Add a new TableModelListener.
 int getRowCount()
          Return the total number of rows.
 void insertRow(int beforeRow)
          Insert a row and increment the row count by one.
protected abstract  boolean onRowInserted(int beforeRow)
          Event fired when a row is inserted.
protected abstract  boolean onRowRemoved(int row)
          Event fired when a row is removed.
protected abstract  boolean onSetData(int row, int cell, java.lang.Object data)
          Event fired when the local data changes.
 void removeRow(int row)
          Remove a row and decrement the row count by one.
 void removeTableModelListener(TableModelListener listener)
          Remove a TableModelListener.
abstract  void requestRows(TableModel.Request request, TableModel.Callback<R> callback)
          Generate a TableModel.Response based on a specific TableModel.Request.
 void setData(int row, int cell, java.lang.Object data)
          Set the data in a specific cell.
 void setRowCount(int rowCount)
          Set the total number of rows.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ALL_ROWS

public static final int ALL_ROWS
Use the ALL_ROWS value in place of the numRows variable when requesting all rows.

See Also:
Constant Field Values

UNKNOWN_ROW_COUNT

public static final int UNKNOWN_ROW_COUNT
Indicates that the number of rows is unknown, and therefore unbounded.

See Also:
Constant Field Values
Constructor Detail

TableModel

public TableModel()
Method Detail

addTableModelListener

public void addTableModelListener(TableModelListener listener)
Add a new TableModelListener.

Specified by:
addTableModelListener in interface SourceTableModelEvents
Parameters:
listener - the listener

getRowCount

public int getRowCount()
Return the total number of rows. If the number is not known, return UNKNOWN_ROW_COUNT.

Returns:
the total number of rows, or UNKNOWN_ROW_COUNT

insertRow

public void insertRow(int beforeRow)
Insert a row and increment the row count by one.

Parameters:
beforeRow - the row index of the new row

removeRow

public void removeRow(int row)
Remove a row and decrement the row count by one.

Parameters:
row - the row index of the removed row

removeTableModelListener

public void removeTableModelListener(TableModelListener listener)
Remove a TableModelListener.

Specified by:
removeTableModelListener in interface SourceTableModelEvents
Parameters:
listener - the listener to remove

requestRows

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

Parameters:
request - the TableModel.Request for row data
callback - the TableModel.Callback to use for the TableModel.Response

setData

public void setData(int row,
                    int cell,
                    java.lang.Object data)
Set the data in a specific cell.

Parameters:
row - the row index
cell - the cell index
data - the new contents of the cell

setRowCount

public void setRowCount(int rowCount)
Set the total number of rows.

Parameters:
rowCount - the row count

onRowInserted

protected abstract boolean onRowInserted(int beforeRow)
Event fired when a row is inserted. Returning true will increment the row count by one.

Parameters:
beforeRow - the row index of the new row
Returns:
true if the action is successful

onRowRemoved

protected abstract boolean onRowRemoved(int row)
Event fired when a row is removed. Returning true will decrement the row count by one.

Parameters:
row - the row index of the removed row
Returns:
true if the action is successful

onSetData

protected abstract boolean onSetData(int row,
                                     int cell,
                                     java.lang.Object data)
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.

Parameters:
row - the row index
cell - the cell index
data - the new contents of the cell
Returns:
true if the action is successful