org.tentackle.ui
Class FormTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by org.tentackle.ui.AbstractFormTableModel
          extended by org.tentackle.ui.FormTableModel
All Implemented Interfaces:
Serializable, TableModel

public class FormTableModel
extends AbstractFormTableModel

Table-model for FormTables.

Author:
harald
See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
FormTableModel(FormTableEntry template)
          Creates an empty table model for a given template.
FormTableModel(FormTableEntry template, DbCursor<? extends DbObject> cursor)
          Creates a table model for a database cursor.
FormTableModel(FormTableEntry template, List<?> list)
          Creates a table model for a list of objects.
FormTableModel(FormTableEntry template, Object[] array)
          Creates a table model for an array of objects.
 
Method Summary
 void cursorChanged(DbCursor<? extends DbObject> cursor)
          Sets a new cursor and fires tableDataChanged.
 Class getColumnClass(int columnIndex)
          Returns Object.class regardless of columnIndex.
 int getColumnCount()
          Returns the number of columns in the model.
 String getColumnName(int columnIndex)
          Returns a default name for the column using spreadsheet conventions: A, B, C, ...
 String getDisplayedColumnName(int columnIndex)
          Gets the displayed column name.
 FormTableEntry getEntryAt(int row)
          Gets the form table entry at given row.
 int getRowCount()
          Returns the number of rows in the model.
 FormTable getTable()
          Gets the table.
 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.
 void listCellUpdated(int rowIndex, int columnIndex)
          Denotes that a table cell has changed and fires tableCellUpdated.
 void listChanged(List<?> list)
          Sets a new list of objects and fires tableDataChanged.
 void listChanged(Object[] array)
          Sets a new array of objects and fires tableDataChanged.
 void listDeleted(int firstRow, int lastRow)
          Denotes that a range of rows have been deleted and fires tableRowsDeleted.
 void listInserted(int firstRow, int lastRow)
          Denotes that a range of rows have been insert and fires tableRowsInserted.
 void listUpdated(int firstRow, int lastRow)
          Denotes that a range of rows have been changed and fires tableRowsUpdated.
 void setDataChanged(boolean dataChanged)
          Sets a flag that model data has changed.
 boolean setEntryAt(FormTableEntry entry, int row)
          Sets the form table entry at given row.
The default implementation just triggers a value changed event for the table.
 void setTemplate(FormTableEntry template)
          Sets the template (useful if context changed)
 void setValueAt(Object aValue, int rowIndex, int columnIndex)
          Sets the cell value.
 
Methods inherited from class org.tentackle.ui.AbstractFormTableModel
getMap, getMappedIndex, getMappedIndex, getModelIndex, getModelIndex, isDataChanged, 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
 

Constructor Detail

FormTableModel

public FormTableModel(FormTableEntry template,
                      DbCursor<? extends DbObject> cursor)
Creates a table model for a database cursor.

Parameters:
template - the table entry as a template to create other entries
cursor - the database cursor

FormTableModel

public FormTableModel(FormTableEntry template,
                      List<?> list)
Creates a table model for a list of objects.

Parameters:
template - the table entry as a template to create other entries
list - the list of objects

FormTableModel

public FormTableModel(FormTableEntry template,
                      Object[] array)
Creates a table model for an array of objects.

Parameters:
template - the table entry as a template to create other entries
array - the array of objects

FormTableModel

public FormTableModel(FormTableEntry template)
Creates an empty table model for a given template.

Parameters:
template - the table entry as a template to create other entries
Method Detail

setTemplate

public void setTemplate(FormTableEntry template)
Sets the template (useful if context changed)

Parameters:
template - the new template

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

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.

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.

Returns:
the number of columns in the model
See Also:
TableModel.getRowCount()

getColumnName

public String getColumnName(int columnIndex)
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:
columnIndex - the column being queried
Returns:
a string containing the default name of column

getDisplayedColumnName

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

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

getValueAt

public Object getValueAt(int rowIndex,
                         int columnIndex)
Description copied from interface: javax.swing.table.TableModel
Returns the value for the cell at columnIndex and rowIndex.

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)
Sets the cell value.

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)

setDataChanged

public void setDataChanged(boolean dataChanged)
Sets a flag that model data has changed. Will be cleared on listChanged() or cursorChanged().

Overridden to propagate triggerValueChanged()

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

getTable

public FormTable getTable()
Gets the table.

Overridden to get the table if models are chained

Overrides:
getTable in class AbstractFormTableModel
Returns:
the form table or null if this model is not the direct data model for the table

getEntryAt

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

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

setEntryAt

public boolean setEntryAt(FormTableEntry entry,
                          int row)
Description copied from class: AbstractFormTableModel
Sets the form table entry at given row.
The default implementation just triggers a value changed event for the table. Must be overridden for another mapping than 1:1.

Overrides:
setEntryAt in class AbstractFormTableModel
Parameters:
entry - the formtable entry
row - the row of the table entry
Returns:
true if replaced, false if not (rowIndex out of range)

getColumnClass

public Class getColumnClass(int columnIndex)
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:
columnIndex - 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)

cursorChanged

public void cursorChanged(DbCursor<? extends DbObject> cursor)
Sets a new cursor and fires tableDataChanged.

Parameters:
cursor - the new cursor

listChanged

public void listChanged(List<?> list)
Sets a new list of objects and fires tableDataChanged.

Parameters:
list - the new list of objects

listChanged

public void listChanged(Object[] array)
Sets a new array of objects and fires tableDataChanged.

Parameters:
array - the new array of objects

listUpdated

public void listUpdated(int firstRow,
                        int lastRow)
Denotes that a range of rows have been changed and fires tableRowsUpdated. The row numbers are silently aligned if out of range.

Parameters:
firstRow - the first row
lastRow - the last changed row (>= firstRow)

listCellUpdated

public void listCellUpdated(int rowIndex,
                            int columnIndex)
Denotes that a table cell has changed and fires tableCellUpdated. If the row is out of range, nothing will be done. The handling of the column depends on the listener for the TableModelEvent.

Parameters:
rowIndex - the row number
columnIndex - the column index

listInserted

public void listInserted(int firstRow,
                         int lastRow)
Denotes that a range of rows have been insert and fires tableRowsInserted. The row numbers are silently aligned if out of range. Will nullpex if not in list-mode.

Parameters:
firstRow - the first row
lastRow - the last changed row (>= firstRow)

listDeleted

public void listDeleted(int firstRow,
                        int lastRow)
Denotes that a range of rows have been deleted and fires tableRowsDeleted. The row numbers are silently aligned if out of range. Will nullpex if not in list-mode.

Parameters:
firstRow - the first row
lastRow - the last changed row (>= firstRow)


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