SPT Core API

com.sptci.echo2.table
Class RowSetTableModel

java.lang.Object
  extended by nextapp.echo2.app.table.AbstractTableModel
      extended by com.sptci.echo2.table.AbstractTableModel<RowSet>
          extended by com.sptci.echo2.table.RowSetTableModel
All Implemented Interfaces:
Serializable, TableModel
Direct Known Subclasses:
DatabaseTableModel

public class RowSetTableModel
extends AbstractTableModel<RowSet>

A custom TableModel used to represent data contained in RowSet objects.

© Copyright 2007 Sans Pareil Technologies, Inc.

Version:
$Id: RowSetTableModel.java 4553 2008-12-24 10:34:16Z rakesh $
Author:
Rakesh Vidyadharan 2007-09-19
See Also:
Serialized Form

Field Summary
protected  List<ColumnMetaData> columns
          The list of columns displayed in the Table.
protected  String prefix
          The prefix to use to look up localised column headers.
protected  int rowCount
          The rowCount number of records available in rowSet.
protected  RowSet rowSet
          The RowSet backing this table model.
 
Fields inherited from class com.sptci.echo2.table.AbstractTableModel
sortDirection, sortIndex
 
Constructor Summary
protected RowSetTableModel()
          Default constructor.
protected RowSetTableModel(String prefix)
          Create a new instance of the model configured to use the specified prefix for localised column names.
  RowSetTableModel(String prefix, RowSet rowSet)
          Create a new instance of the model using the specified collection of data objects.
 
Method Summary
 void addRow(Map<String,Object> row)
          Add the specified row to the end of the model.
 void deleteRow(int row)
          Delete the specified row from the model.
 void dispose()
          Close the rowSet and release any resources held by it.
 Class getColumnClass(int column)
          Returns the class of the objects displayed in the specified column.
 int getColumnCount()
          Returns the number of columns displayed in the table.
 String getColumnName(int column)
          Returns the name of the specified column.
 RowSet getObjectAt(int row)
          Return the object stored at the specified index in rowSet.
 String getPrefix()
          Returns prefix.
 int getRowCount()
          Return the rowCount number of entries in rowSet.
 Object getValueAt(int column, int row)
          Return the value at the specified coordinate in the table.
 void init()
          Initialise this table model.
protected  void processColumns()
          Process the RowSetMetaData associated with rowSet and populate columns.
protected  void setColumn(Map.Entry<String,Object> column)
          Set the value of the specified cell in rowSet.
 void setPrefix(String prefix)
          Set prefix.
protected  void setRowCount()
          Sets the value of rowCount from rowSet.
protected  void setRowCount(int rowCount)
          Sets the value of rowCount.
 void updateRow(int row, Map<String,Object> rowData)
          Replace the row specified with the object specified.
 
Methods inherited from class com.sptci.echo2.table.AbstractTableModel
getSortDirection
 
Methods inherited from class nextapp.echo2.app.table.AbstractTableModel
addTableModelListener, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getEventListenerList, removeTableModelListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rowSet

protected RowSet rowSet
The RowSet backing this table model.


prefix

protected String prefix
The prefix to use to look up localised column headers.


rowCount

protected int rowCount
The rowCount number of records available in rowSet.


columns

protected List<ColumnMetaData> columns
The list of columns displayed in the Table. This is used by the getColumnName(int) and getColumnCount() methods.

Constructor Detail

RowSetTableModel

protected RowSetTableModel()
Default constructor.


RowSetTableModel

protected RowSetTableModel(String prefix)
Create a new instance of the model configured to use the specified prefix for localised column names.

Parameters:
prefix - The prefix to use to look up localised titles for the column names. The prefix should not have a trailing dot.

RowSetTableModel

public RowSetTableModel(String prefix,
                        RowSet rowSet)
Create a new instance of the model using the specified collection of data objects.

Parameters:
prefix - The prefix to use to look up localised titles for the column names. The prefix should not have a trailing dot.
rowSet - The rowSet to use as the backing data store.
Method Detail

init

public void init()
          throws RuntimeException
Initialise this table model.

Specified by:
init in class AbstractTableModel<RowSet>
Throws:
RuntimeException - If a SQLException is thrown by the methods invoked.
See Also:
processColumns(), setRowCount()

addRow

public void addRow(Map<String,Object> row)
            throws SQLException
Add the specified row to the end of the model. It is assumed that the key values in the row match the column names in rowSet and that the value objects match the appropriate type required for the column.

Parameters:
row - The data object that is to be added to the model.
Throws:
SQLException - If errors are encountered while adding the data.
See Also:
setColumn(java.util.Map.Entry), AbstractTableModel.fireTableRowsInserted(int, int)

deleteRow

public void deleteRow(int row)
               throws SQLException
Delete the specified row from the model.

Parameters:
row - The index of the row that is to be deleted.
Throws:
SQLException - If errors are encountered while deleting the data.
See Also:
AbstractTableModel.fireTableRowsDeleted(int, int)

updateRow

public void updateRow(int row,
                      Map<String,Object> rowData)
               throws SQLException
Replace the row specified with the object specified.

Parameters:
row - The index at which the object is to be updated.
rowData - The data object that is to be updated to the model.
Throws:
SQLException - If errors are encountered while updating the rowSet.
See Also:
setColumn(java.util.Map.Entry), AbstractTableModel.fireTableRowsUpdated(int, int)

getColumnClass

public Class getColumnClass(int column)
Returns the class of the objects displayed in the specified column.

Specified by:
getColumnClass in interface TableModel
Overrides:
getColumnClass in class AbstractTableModel
Parameters:
column - The column whose class is to be returned.
Returns:
The class of the objects displayed.
See Also:
TableModel.getColumnClass(int)

getColumnCount

public int getColumnCount()
Returns the number of columns displayed in the table.

Returns:
The number of columns displayed.
See Also:
TableModel.getColumnCount()

getColumnName

public String getColumnName(int column)
Returns the name of the specified column.

Specified by:
getColumnName in interface TableModel
Overrides:
getColumnName in class AbstractTableModel
Parameters:
column - The index of the column whose name is to be returned.
Returns:
The name of the specified column.
See Also:
TableModel.getColumnName(int)

getRowCount

public int getRowCount()
Return the rowCount number of entries in rowSet.

Returns:
The rowCount number of rows displayed in the table.
See Also:
TableModel.getRowCount()

getValueAt

public Object getValueAt(int column,
                         int row)
                  throws RuntimeException
Return the value at the specified coordinate in the table.

Parameters:
column - The column index.
row - The row index.
Returns:
The object that is displayed at the coordinate specified.
Throws:
IllegalArgumentException - If column or row indices are invalid for this model.
RuntimeException - If errors are encountered while fetching the value from the underlying data object at index row in rowSet.
See Also:
TableModel.getValueAt(int, int)

getObjectAt

public RowSet getObjectAt(int row)
                   throws SQLException
Return the object stored at the specified index in rowSet. This is equivalent to returning the rowSet with the row set to the specified index.

Parameters:
row - The index of the row whose underlying object is to be returned.
Returns:
The rowSet pointing to the row number specified.
Throws:
SQLException - If errors are encountered while setting the cursor position to the row specified.

processColumns

protected void processColumns()
                       throws SQLException
Process the RowSetMetaData associated with rowSet and populate columns.

Throws:
SQLException - If errors are encountered while introspecting the meta data.

setRowCount

protected void setRowCount()
                    throws SQLException
Sets the value of rowCount from rowSet.

Throws:
SQLException - If errors are encountered while traversing the rowset.

setRowCount

protected void setRowCount(int rowCount)
Sets the value of rowCount.

Parameters:
rowCount - The value to set.

setColumn

protected void setColumn(Map.Entry<String,Object> column)
                  throws SQLException
Set the value of the specified cell in rowSet.

Parameters:
column - A Map.Entry that contains the name of the column and its value.
Throws:
SQLException - If errors are encountered while setting the value of the column.

dispose

public void dispose()
Close the rowSet and release any resources held by it.


getPrefix

public String getPrefix()
Returns prefix.

Returns:
The value/reference of/to prefix.

setPrefix

public void setPrefix(String prefix)
Set prefix.

Parameters:
prefix - The value to set.

SPT Core API