schmitzm.swing.table
Class SelectionTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by schmitzm.swing.table.SelectionTableModel
All Implemented Interfaces:
Serializable, TableModel, PipedTableModel

public class SelectionTableModel
extends AbstractTableModel
implements PipedTableModel

This table model extends an other TableModel by inserting an additional column 0 which shows and controls the row selection. To realize this functionality it is necessary to connect this table model to an explicit JTable. Besides it is necessary that this table is a SelectableJTable to overcome the "normal" click behavior (clear selection when no Ctrl/Shift key is hold), when clicking the selection column.

Author:
Martin Schmitz (University of Bonn/Germany)
See Also:
Serialized Form

Field Summary
protected  TableModel model
          Holds the base data.
protected  SelectableJTable table
          Holds the table which controls the selection.
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
SelectionTableModel(TableModel model, SelectableJTable table)
          Creates a new table model
 
Method Summary
 void addTableModelListener(TableModelListener listener)
          Adds a listener to the list that's notified each time a change to the data model occurs.
 Class<?> getColumnClass(int col)
          Returns the type of a column.
 int getColumnCount()
          Returns the type of a column.
 String getColumnName(int col)
          Returns the name of a column.
 TableModel getPipedModel()
          Returns the original TableModel.
 int getRowCount()
          Returns the number of rows in the model.
 Object getValueAt(int row, int col)
          Returns the value for a cell.
 boolean isCellEditable(int row, int col)
          Returns the value for a cell.
 void removeTableModelListener(TableModelListener listener)
          Removes a listener from the list that's notified each time a change to the data model occurs.
 void setValueAt(Object value, int row, int col)
          Sets a value for a cell.
 
Methods inherited from class javax.swing.table.AbstractTableModel
findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

table

protected SelectableJTable table
Holds the table which controls the selection.


model

protected TableModel model
Holds the base data.

Constructor Detail

SelectionTableModel

public SelectionTableModel(TableModel model,
                           SelectableJTable table)
Creates a new table model

Parameters:
model - provides the data
table - used to determine the row selection
Method Detail

getPipedModel

public TableModel getPipedModel()
Returns the original TableModel.

Specified by:
getPipedModel in interface PipedTableModel

addTableModelListener

public void addTableModelListener(TableModelListener listener)
Adds a listener to the list that's notified each time a change to the data model occurs.

Specified by:
addTableModelListener in interface TableModel
Overrides:
addTableModelListener in class AbstractTableModel

removeTableModelListener

public void removeTableModelListener(TableModelListener listener)
Removes a listener from the list that's notified each time a change to the data model occurs.

Specified by:
removeTableModelListener in interface TableModel
Overrides:
removeTableModelListener in class AbstractTableModel

getColumnClass

public Class<?> getColumnClass(int col)
Returns the type of a column.

Specified by:
getColumnClass in interface TableModel
Overrides:
getColumnClass in class AbstractTableModel
Returns:
Boolean.class for column 0

getColumnCount

public int getColumnCount()
Returns the type of a column.

Specified by:
getColumnCount in interface TableModel
Returns:
Boolean.class for column 0

getColumnName

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

Specified by:
getColumnName in interface TableModel
Overrides:
getColumnName in class AbstractTableModel
Returns:
empty string for column 0

getRowCount

public int getRowCount()
Returns the number of rows in the model.

Specified by:
getRowCount in interface TableModel

getValueAt

public Object getValueAt(int row,
                         int col)
Returns the value for a cell.

Specified by:
getValueAt in interface TableModel
Parameters:
row - row index
col - column index

setValueAt

public void setValueAt(Object value,
                       int row,
                       int col)
Sets a value for a cell.

Specified by:
setValueAt in interface TableModel
Overrides:
setValueAt in class AbstractTableModel
Parameters:
value - new cell value
row - row index
col - column index

isCellEditable

public boolean isCellEditable(int row,
                              int col)
Returns the value for a cell.

Specified by:
isCellEditable in interface TableModel
Overrides:
isCellEditable in class AbstractTableModel
Parameters:
row - row index
col - column index
{@code - true} for column 0