org.jurvis.swing.table
Class JvMappedObjectTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by org.jurvis.swing.table.JvMappedObjectTableModel
All Implemented Interfaces:
Serializable, TableModel, JvObjectTableModel

public class JvMappedObjectTableModel
extends AbstractTableModel
implements JvObjectTableModel

A JvMappedObjectTableModel is a TableModel in which each row is actually a single object and columns are determined via a specified JvMappedObjectTableModel.ColumnMapper. The columns of a row typically represent different fields of the row object.

This class is an improvement over JvAbstractObjectTableModel in that a JvObjectTableRow object isn't needed for each row.

Author:
Neil W. Weber
See Also:
Serialized Form

Nested Class Summary
static interface JvMappedObjectTableModel.ColumnMapper
          Interface for object mapping row objects to columns.
 
Field Summary
protected  JvMappedObjectTableModel.ColumnMapper columnMapper
          The object mapping from the row data to table columns.
protected  boolean editable
          True if the data within this model is editable.
protected  List rowData
          The List of row objects.
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
JvMappedObjectTableModel(JvMappedObjectTableModel.ColumnMapper columnMapper)
          Construct a JvMappedObjectTableModel with the given column mapper.
JvMappedObjectTableModel(List rowData, JvMappedObjectTableModel.ColumnMapper columnMapper)
          Construct a JvMappedObjectTableModel with the given row data and column mapper.
 
Method Summary
 void addRow(JvObjectTableRow row)
          Adds a row to the end of the model.
 Class getColumnClass(int columnIndex)
          Return the class of object displayed in the specified column.
 int getColumnCount()
          Returns 0 for the number of columns in this data table.
 Collection getEmptyCollection()
          Return an empty collection suitable for putting the selected items within.
 Object getObjectAt(int row)
          Return the domain object associated with the specified row.
 int getRowCount()
          Returns the number of rows in this data table.
 Object getValueAt(int row, int column)
          Returns an attribute value for the cell at row and column.
 boolean isCellEditable(int row, int column)
          Returns true if the cell at row and column is editable.
 boolean isEditable()
          Determine if the cell within this table is editable.
 void remove(int row, int col)
          Method called when the drop operation is MOVE.
 void removeRow(int row)
          Removes the row at row from the model.
 void setEditable(boolean editable)
          Set whether the data within this table is editable.
 void setRowData(List rowData)
          Set the list of objects representing the table rows.
 void setValueAt(Object value, int row, int column)
          Sets the object value for the cell at column and row.
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getColumnName, getListeners, getTableModelListeners, removeTableModelListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.swing.table.TableModel
addTableModelListener, getColumnName, removeTableModelListener
 

Field Detail

rowData

protected List rowData
The List of row objects.


editable

protected boolean editable
True if the data within this model is editable.


columnMapper

protected JvMappedObjectTableModel.ColumnMapper columnMapper
The object mapping from the row data to table columns.

Constructor Detail

JvMappedObjectTableModel

public JvMappedObjectTableModel(JvMappedObjectTableModel.ColumnMapper columnMapper)
Construct a JvMappedObjectTableModel with the given column mapper.

Parameters:
columnMapper - the object mapping from the row data to table columns

JvMappedObjectTableModel

public JvMappedObjectTableModel(List rowData,
                                JvMappedObjectTableModel.ColumnMapper columnMapper)
Construct a JvMappedObjectTableModel with the given row data and column mapper.

Parameters:
rowData - the list of objects representing the table rows
columnMapper - the object mapping from the row data to table columns
Method Detail

setEditable

public void setEditable(boolean editable)
Set whether the data within this table is editable.

Parameters:
editable - true if the data is editable

isEditable

public boolean isEditable()
Determine if the cell within this table is editable.


setRowData

public void setRowData(List rowData)
Set the list of objects representing the table rows.


getRowCount

public int getRowCount()
Returns the number of rows in this data table.

Specified by:
getRowCount in interface TableModel
Returns:
the number of rows in the model

getObjectAt

public Object getObjectAt(int row)
Return the domain object associated with the specified row.

Specified by:
getObjectAt in interface JvObjectTableModel
Parameters:
row - the index of the desired row
Returns:
the domain object for the specified row

getEmptyCollection

public Collection getEmptyCollection()
Return an empty collection suitable for putting the selected items within.

Specified by:
getEmptyCollection in interface JvObjectTableModel
Returns:
the empty collection

getColumnCount

public int getColumnCount()
Returns 0 for the number of columns in this data table. This method returns 0 because the TableColumnModel should not be created from this TableModel. Columns should be created using the JvSwingFactory.createTableColumn(javax.swing.JTable, java.lang.String, int) method.

Specified by:
getColumnCount in interface TableModel
Returns:
0

getColumnClass

public Class getColumnClass(int columnIndex)
Return the class of object displayed in the specified column. This method makes a guess at the class by querying the row data. If there is no row data, Object is returned.

Specified by:
getColumnClass in interface TableModel
Overrides:
getColumnClass in class AbstractTableModel
Parameters:
columnIndex - the column being queried
Returns:
the class of the object of the specified column

getValueAt

public Object getValueAt(int row,
                         int column)
Returns an attribute value for the cell at row and column.

Specified by:
getValueAt in interface TableModel
Parameters:
row - the row whose value is to be queried
column - the column whose value is to be queried
Returns:
the value Object at the specified cell

setValueAt

public void setValueAt(Object value,
                       int row,
                       int column)
Sets the object value for the cell at column and row. value is the new value. This method will generate a tableChanged notification.

Specified by:
setValueAt in interface TableModel
Overrides:
setValueAt in class AbstractTableModel
Parameters:
value - the new value; this can be null
row - the row whose value is to be changed
column - the column whose value is to be changed

isCellEditable

public boolean isCellEditable(int row,
                              int column)
Returns true if the cell at row and column is editable. Otherwise, setValueAt on the cell will not change the value of that cell.

Specified by:
isCellEditable in interface TableModel
Overrides:
isCellEditable in class AbstractTableModel
Parameters:
row - the row whose value to be queried
column - the column whose value to be queried
Returns:
true if the cell is editable

addRow

public void addRow(JvObjectTableRow row)
Adds a row to the end of the model. Notification of the row being added will be generated.

Parameters:
row - data of the row being added

removeRow

public void removeRow(int row)
Removes the row at row from the model. Notification of the row being removed will be sent to all the listeners.

Parameters:
row - the row index of the row to be removed

remove

public void remove(int row,
                   int col)
Method called when the drop operation is MOVE. For a JvObjectTableModel, each row corresponds to a single object, so the column index is ignored and removeRow(int) is called.

Parameters:
row - the row index of the data that will be removed
col - the column index of the data that will be removed


Copyright © 1999-2004 Neil W. Weber. All Rights Reserved.