Class SwingTableModel
- java.lang.Object
-
- javax.swing.table.AbstractTableModel
-
- net.sf.jguiraffe.gui.platform.swing.builder.components.table.SwingTableModel
-
- All Implemented Interfaces:
Serializable,TableModel
public class SwingTableModel extends AbstractTableModel
A table model implementation for tables defined by the
TableTagtag handler class.This class implements the typical table model functionality based on an
TableFormControllerobject provided by aTableTaginstance. Many methods can directly delegate to the controller object.- Version:
- $Id: SwingTableModel.java 205 2012-01-29 18:29:57Z oheger $
- Author:
- Oliver Heger
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
-
-
Constructor Summary
Constructors Constructor Description SwingTableModel(net.sf.jguiraffe.gui.builder.components.tags.table.TableTag tt, JTable tab)Creates a new instance ofSwingTableModeland initializes it.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidfireTableChanged(TableModelEvent event)Notifies listeners about a change in the data of this model.Class<?>getColumnClass(int col)Returns the data class of the specified column.intgetColumnCount()Returns the number of columns of the represented table.StringgetColumnName(int col)Returns the name for the specified column.TableCellEditorgetEditor()Returns the cell editor associated with this model.List<Object>getModelData()Returns the list with the data of this model.TableCellRenderergetRenderer()Returns the cell renderer associated with this model.intgetRowCount()Returns the number of rows of the represented table.JTablegetTable()Returns a reference to the associated table.net.sf.jguiraffe.gui.builder.components.tags.table.TableTaggetTableTag()Returns the table tag this model is based onto.ObjectgetValueAt(int row, int col)Returns the value at the specified cell.booleanhasEditor(int col)Checks whether for the specified column a custom editor is specified.booleanhasRenderer(int col)Tests whether for the specified column a custom renderer is specified.booleanisCellEditable(int row, int col)Returns a flag whether the specified cell can be modified.voidsetValueAt(Object value, int row, int col)Sets the value for the specified cell.protected booleanvalidateColumn(int col)Validates the column with the specified index.-
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
-
-
-
-
Constructor Detail
-
SwingTableModel
public SwingTableModel(net.sf.jguiraffe.gui.builder.components.tags.table.TableTag tt, JTable tab)Creates a new instance ofSwingTableModeland initializes it.- Parameters:
tt- the tag defining the underlying tabletab- the associated table
-
-
Method Detail
-
getModelData
public List<Object> getModelData()
Returns the list with the data of this model. The list contains beans that define the values of the single columns.- Returns:
- the data list of this model
-
getTableTag
public net.sf.jguiraffe.gui.builder.components.tags.table.TableTag getTableTag()
Returns the table tag this model is based onto.- Returns:
- the table tag
-
getTable
public JTable getTable()
Returns a reference to the associated table.- Returns:
- the table
-
getColumnCount
public int getColumnCount()
Returns the number of columns of the represented table.- Returns:
- the number of columns of this table
-
getRowCount
public int getRowCount()
Returns the number of rows of the represented table.- Returns:
- the number of rows of this table
-
getValueAt
public Object getValueAt(int row, int col)
Returns the value at the specified cell.- Parameters:
row- the row indexcol- the column index- Returns:
- the value of this cell
-
getColumnClass
public Class<?> getColumnClass(int col)
Returns the data class of the specified column. This implementation checks whether a logic column class was specified. If this is the case, it is mapped to the corresponding Java class. Otherwise, the Java class is directly obtained from the column definition.- Specified by:
getColumnClassin interfaceTableModel- Overrides:
getColumnClassin classAbstractTableModel- Parameters:
col- the column index- Returns:
- the data class for the specified column
-
getColumnName
public String getColumnName(int col)
Returns the name for the specified column.- Specified by:
getColumnNamein interfaceTableModel- Overrides:
getColumnNamein classAbstractTableModel- Parameters:
col- the column index- Returns:
- the title for this column
-
isCellEditable
public boolean isCellEditable(int row, int col)Returns a flag whether the specified cell can be modified.- Specified by:
isCellEditablein interfaceTableModel- Overrides:
isCellEditablein classAbstractTableModel- Parameters:
row- the row indexcol- the column index- Returns:
- a flag whether this cell can be edited
-
setValueAt
public void setValueAt(Object value, int row, int col)
Sets the value for the specified cell.- Specified by:
setValueAtin interfaceTableModel- Overrides:
setValueAtin classAbstractTableModel- Parameters:
value- the value to setrow- the row indexcol- the column index
-
fireTableChanged
public void fireTableChanged(TableModelEvent event)
Notifies listeners about a change in the data of this model. This implementation also notifies theTableFormControllerabout this change.- Overrides:
fireTableChangedin classAbstractTableModel- Parameters:
event- the event
-
hasEditor
public boolean hasEditor(int col)
Checks whether for the specified column a custom editor is specified.- Parameters:
col- the column index- Returns:
- a flag if this column has its own editor
-
getEditor
public TableCellEditor getEditor()
Returns the cell editor associated with this model. There is exactly one editor that is capable to serve all columns of this table (that define a custom editor).- Returns:
- the cell editor used for the represented table
-
hasRenderer
public boolean hasRenderer(int col)
Tests whether for the specified column a custom renderer is specified.- Parameters:
col- the column index- Returns:
- a flag whether this column has a custom renderer
-
getRenderer
public TableCellRenderer getRenderer()
Returns the cell renderer associated with this model. There is exactly one renderer that is capable of rendering all columns of this table that define a custom renderer.- Returns:
- the cell renderer used for the represented table
-
validateColumn
protected boolean validateColumn(int col)
Validates the column with the specified index. This method is always called when the user has entered data into a cell of the table. It delegates to the editor form to validate the input fields used in this column. It will also notify theTableEditorValidationHandlerset for this table. If validation is successful, the value(s) will be written into the model.- Parameters:
col- the column to be validated- Returns:
- a flag whether the data is valid
-
-