org.tentackle.ui
Class FormTableMap

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by org.tentackle.ui.AbstractFormTableModel
          extended by org.tentackle.ui.FormTableMap
All Implemented Interfaces:
Serializable, EventListener, TableModelListener, TableModel
Direct Known Subclasses:
FormTableSorter

public class FormTableMap
extends AbstractFormTableModel
implements TableModelListener

Generic mapping of the rows within a FormTable.
Implementing a sorter is easily done by subclassing FormTableMap.

Author:
harald
See Also:
Serialized Form

Field Summary
protected  AbstractFormTableModel model
          chained table model
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
FormTableMap(AbstractFormTableModel model)
          Creates a form table map on top of a given table model.
 
Method Summary
 Class getColumnClass(int col)
          Returns Object.class regardless of columnIndex.
 int getColumnCount()
          Returns the number of columns in the model.
 String getColumnName(int column)
          Returns a default name for the column using spreadsheet conventions: A, B, C, ...
 String getDisplayedColumnName(int column)
          Gets the displayed column name.
 FormTableEntry getEntryAt(int rowIndex)
          Gets the form table entry at given row.
 int getMappedIndex(int mappedRow)
          Gets the mapped row index according to a given model row.
Inversion of getModelIndex().
 int[] getMappedIndex(int[] mappedRows)
          Gets the mapped row indexes according to given model rows.
Inversion of getModelIndex().
 AbstractFormTableModel getModel()
          Gets the table model this table mapper maps.
 int getModelIndex(int row)
          Gets the row in the original model according to the mapping.
The default implementation returns the same row.
 int[] getModelIndex(int[] rows)
          Gets the rows in the original model according to the mapping.
The default implementation returns the same rows.
 int getRowCount()
          Returns the number of rows in the model.
 FormTableEntry getTemplate()
          Gets the table entry template from the model.
 Object getValueAt(int rowIndex, int columnIndex)
          Returns the value for the cell at columnIndex and rowIndex.
 boolean isCellEditable(int rowIndex, int columnIndex)
          Returns false.
 boolean isDataChanged()
          Returns whether data has changed.
 void setDataChanged(boolean dataChanged)
          Sets a flag that model data has changed.
 void setModel(AbstractFormTableModel model)
          Sets the table model.
 void setValueAt(Object aValue, int rowIndex, int columnIndex)
          This empty implementation is provided so users don't have to implement this method if their data model is not editable.
 void tableChanged(TableModelEvent e)
          This fine grain notification tells listeners the exact range of cells, rows, or columns that changed.
 
Methods inherited from class org.tentackle.ui.AbstractFormTableModel
getMap, getTable, setEntryAt, setMap, setTable
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

model

protected AbstractFormTableModel model
chained table model

Constructor Detail

FormTableMap

public FormTableMap(AbstractFormTableModel model)
Creates a form table map on top of a given table model.

Parameters:
model - the chained table model
Method Detail

getModel

public AbstractFormTableModel getModel()
Gets the table model this table mapper maps.

Returns:
the table model

setModel

public void setModel(AbstractFormTableModel model)
Sets the table model.

Parameters:
model - the table model

getTemplate

public FormTableEntry getTemplate()
Description copied from class: AbstractFormTableModel
Gets the table entry template from the model.

Specified by:
getTemplate in class AbstractFormTableModel
Returns:
the form table entry template

getValueAt

public Object getValueAt(int rowIndex,
                         int columnIndex)
Returns the value for the cell at columnIndex and rowIndex.

This method must be overridden for another mapping than 1:1.

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

setValueAt

public void setValueAt(Object aValue,
                       int rowIndex,
                       int columnIndex)
This empty implementation is provided so users don't have to implement this method if their data model is not editable.

This method must be overridden for another mapping than 1:1.

Specified by:
setValueAt in interface TableModel
Overrides:
setValueAt in class AbstractTableModel
Parameters:
aValue - value to assign to cell
rowIndex - row of cell
columnIndex - column of cell
See Also:
TableModel.getValueAt(int, int), TableModel.isCellEditable(int, int)

getEntryAt

public FormTableEntry getEntryAt(int rowIndex)
Description copied from class: AbstractFormTableModel
Gets the form table entry at given row.

Specified by:
getEntryAt in class AbstractFormTableModel
Parameters:
rowIndex - the row of the table entry
Returns:
the table entry, null if rowIndex out of range

getRowCount

public int getRowCount()
Description copied from interface: javax.swing.table.TableModel
Returns the number of rows in the model. A JTable uses this method to determine how many rows it should display. This method should be quick, as it is called frequently during rendering.

Specified by:
getRowCount in interface TableModel
Returns:
the number of rows in the model
See Also:
TableModel.getColumnCount()

getColumnCount

public int getColumnCount()
Description copied from interface: javax.swing.table.TableModel
Returns the number of columns in the model. A JTable uses this method to determine how many columns it should create and display by default.

Specified by:
getColumnCount in interface TableModel
Returns:
the number of columns in the model
See Also:
TableModel.getRowCount()

getColumnName

public String getColumnName(int column)
Description copied from class: javax.swing.table.AbstractTableModel
Returns a default name for the column using spreadsheet conventions: A, B, C, ... Z, AA, AB, etc. If column cannot be found, returns an empty string.

Specified by:
getColumnName in interface TableModel
Overrides:
getColumnName in class AbstractTableModel
Parameters:
column - the column being queried
Returns:
a string containing the default name of column

getDisplayedColumnName

public String getDisplayedColumnName(int column)
Description copied from class: AbstractFormTableModel
Gets the displayed column name.

Specified by:
getDisplayedColumnName in class AbstractFormTableModel
Parameters:
column - column index
Returns:
the column name

getColumnClass

public Class getColumnClass(int col)
Description copied from class: javax.swing.table.AbstractTableModel
Returns Object.class regardless of columnIndex.

Specified by:
getColumnClass in interface TableModel
Overrides:
getColumnClass in class AbstractTableModel
Parameters:
col - the column being queried
Returns:
the Object.class

isCellEditable

public boolean isCellEditable(int rowIndex,
                              int columnIndex)
Description copied from class: javax.swing.table.AbstractTableModel
Returns false. This is the default implementation for all cells.

Specified by:
isCellEditable in interface TableModel
Overrides:
isCellEditable in class AbstractTableModel
Parameters:
rowIndex - the row being queried
columnIndex - the column being queried
Returns:
false
See Also:
TableModel.setValueAt(java.lang.Object, int, int)

getMappedIndex

public int getMappedIndex(int mappedRow)
Description copied from class: AbstractFormTableModel
Gets the mapped row index according to a given model row.
Inversion of getModelIndex(). The default implementation returns the same row. Must be overridden for another mapping than 1:1.

Overrides:
getMappedIndex in class AbstractFormTableModel
Parameters:
mappedRow - the original row
Returns:
the mapped row index

getMappedIndex

public int[] getMappedIndex(int[] mappedRows)
Description copied from class: AbstractFormTableModel
Gets the mapped row indexes according to given model rows.
Inversion of getModelIndex(). The default implementation returns the same rows. Must be overridden for another mapping than 1:1.

Overrides:
getMappedIndex in class AbstractFormTableModel
Parameters:
mappedRows - the original rows
Returns:
the mapped row indexes

getModelIndex

public int getModelIndex(int row)
Description copied from class: AbstractFormTableModel
Gets the row in the original model according to the mapping.
The default implementation returns the same row. Must be overridden for another mapping than 1:1.

Overrides:
getModelIndex in class AbstractFormTableModel
Parameters:
row - the row of this model
Returns:
the row of the mapped model

getModelIndex

public int[] getModelIndex(int[] rows)
Description copied from class: AbstractFormTableModel
Gets the rows in the original model according to the mapping.
The default implementation returns the same rows. Must be overridden for another mapping than 1:1.

Overrides:
getModelIndex in class AbstractFormTableModel
Parameters:
rows - the array of rows of this model
Returns:
the rows of the mapped model

tableChanged

public void tableChanged(TableModelEvent e)
This fine grain notification tells listeners the exact range of cells, rows, or columns that changed.

Event handler for TableModelListener: table data has changed.
This method must be overridden for another mapping than 1:1. The default implementation just invokes fireTableChanged.

Specified by:
tableChanged in interface TableModelListener
Parameters:
e - the table model event

isDataChanged

public boolean isDataChanged()
Description copied from class: AbstractFormTableModel
Returns whether data has changed. Used to for the famous "discard any changes?"-question.

Overrides:
isDataChanged in class AbstractFormTableModel
Returns:
true if model data has been changed

setDataChanged

public void setDataChanged(boolean dataChanged)
Description copied from class: AbstractFormTableModel
Sets a flag that model data has changed. Will be cleared on listChanged() or cursorChanged().

Overrides:
setDataChanged in class AbstractFormTableModel
Parameters:
dataChanged - true if model data has changed


Copyright © 2001-2008 Harald Krake, Bergstr. 48, 78098 Triberg, Germany, harald@krake.de