suncertify.client.models
Class TableSorter

java.lang.Object
  |
  +--javax.swing.table.AbstractTableModel
        |
        +--suncertify.client.models.TableSorter
All Implemented Interfaces:
java.util.EventListener, java.io.Serializable, javax.swing.table.TableModel, javax.swing.event.TableModelListener

public class TableSorter
extends javax.swing.table.AbstractTableModel
implements javax.swing.event.TableModelListener

A sorter for TableModels. The sorter has a model (conforming to TableModel) and itself implements TableModel. TableSorter does not modify the TableModel, instead it maintains an array of integers which it keeps the same size as the number of rows in its model. When the model changes it notifies the sorter that something has changed eg. "rowsAdded" so that its internal array of integers can be reallocated. As requests are made of the sorter (like getValueAt(row, col) it redirects them to its model via the mapping array. That way the TableSorter appears to hold another copy of the table with the rows in a different order. The mapping only affects the contents of the data rows. Pass all requests to these rows through the mapping array: "indexes".

See Also:
Serialized Form

Constructor Summary
TableSorter(java.lang.Object[][] data, java.lang.String[] columnNames)
          Constructs table sorter for specified data and column headers.
 
Method Summary
 void addMouseListenerToHeaderInTable(javax.swing.JTable table)
          Add a mouse listener to the Table to trigger a table sort when a column heading is clicked in the JTable.
 int getColumnCount()
          Return number of columns.
 java.lang.Object getRecordIdForRow(int row)
          Returns the recordId of the given row.
 int getRowCount()
          Return number of rows.
 java.lang.Object getValueAt(int aRow, int aColumn)
          Return value of the data at a given row and column.
 void setData(java.lang.Object[][] data)
          Sets new data set to be displayed.
 void tableChanged(javax.swing.event.TableModelEvent e)
          Perform action requierd in case the tableModel change.
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getColumnClass, getColumnName, getListeners, getTableModelListeners, isCellEditable, removeTableModelListener, setValueAt
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TableSorter

public TableSorter(java.lang.Object[][] data,
                   java.lang.String[] columnNames)
Constructs table sorter for specified data and column headers. Internally creates Table model instance. First column in the data model is the row id and will not be displayed

Parameters:
data - - the date to be placed in the table, the first column will not be displayed
columnNames - - column headers
Method Detail

tableChanged

public void tableChanged(javax.swing.event.TableModelEvent e)
Perform action requierd in case the tableModel change. It relocate index (set to default) and fire tab;e refresh. Method is required by TableModelListener

Specified by:
tableChanged in interface javax.swing.event.TableModelListener
Parameters:
e - event details, not used by implmentation

getValueAt

public java.lang.Object getValueAt(int aRow,
                                   int aColumn)
Return value of the data at a given row and column. The mapping only affects the contents of the data rows. Pass all requests to these rows through the mapping array: "indexes".

Specified by:
getValueAt in interface javax.swing.table.TableModel
Parameters:
aRow - index of data's row
aColumn - index of data's column
Returns:
the data object itself
See Also:
TableSorter.IdLessTableModel.getValueAt(int,int)

getColumnCount

public int getColumnCount()
Return number of columns.

Specified by:
getColumnCount in interface javax.swing.table.TableModel
Returns:
number of columns
See Also:
TableSorter.IdLessTableModel.getColumnCount()

getRowCount

public int getRowCount()
Return number of rows. number of rows

Specified by:
getRowCount in interface javax.swing.table.TableModel
See Also:
TableSorter.IdLessTableModel.getRowCount()

setData

public void setData(java.lang.Object[][] data)
Sets new data set to be displayed. It set the data in underlaying table model and fire tableChange

Parameters:
data - - new data set
See Also:
tableChanged(TableModelEvent), TableSorter.IdLessTableModel.setData(Object[][])

getRecordIdForRow

public java.lang.Object getRecordIdForRow(int row)
Returns the recordId of the given row. It cannot be take directly from the model becouse user see sorted elementes so the index of selected element is not the index from the tableModel

Parameters:
row - the index of the row
Returns:
recordId of the row

addMouseListenerToHeaderInTable

public void addMouseListenerToHeaderInTable(javax.swing.JTable table)
Add a mouse listener to the Table to trigger a table sort when a column heading is clicked in the JTable.