Package groovy.swing.model

# Class DefaultTableModel

java.lang.Object
javax.swing.table.AbstractTableModel
groovy.swing.model.DefaultTableModel

All Implemented Interfaces:
  `Serializable`, `TableModel`

public class DefaultTableModel extends AbstractTableModel
A table model built from row and column `ValueModel` instances.

See Also:
  - Serialized Form

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `protected static class`
  `DefaultTableModel.MyTableColumnModel`
  Column model implementation that keeps model indexes aligned with the current column order.

- ## Field Summary

  ### Fields inherited from class javax.swing.table.AbstractTableModel

  `listenerList`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `DefaultTableModel(ValueModel rowsModel)`
  Creates a table model with its own row holder.
  `DefaultTableModel(ValueModel rowsModel, ValueModel rowModel)`
  Creates a table model with explicit row and rows models.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `DefaultTableColumn`
  `addClosureColumn(Object headerValue, Closure readClosure, Closure writeClosure, Class type)`
  Adds a closure based column to the table
  `void`
  `addColumn(DefaultTableColumn column)`
  Adds a new column definition to the table
  `DefaultTableColumn`
  `addColumn(Object headerValue, ValueModel columnValueModel)`
  Adds a column whose header value is also used as its identifier.
  `DefaultTableColumn`
  `addColumn(Object headerValue, Object identifier, ValueModel columnValueModel)`
  Adds a column definition with an explicit identifier.
  `DefaultTableColumn`
  `addPropertyColumn(Object headerValue, String property, Class type)`
  Adds a property model column to the table
  `DefaultTableColumn`
  `addPropertyColumn(Object headerValue, String property, Class type, boolean editable)`
  Adds a property model column to the table
  `Class`
  `getColumnClass(int columnIndex)`
  Returns the declared value type for the supplied column.
  `int`
  `getColumnCount()`
  Returns the number of configured columns.
  `List`
  `getColumnList()`
  `TableColumnModel`
  `getColumnModel()`
  Returns the Swing column model maintained by this table model.
  `protected ValueModel`
  `getColumnModel(int columnIndex)`
  Returns the value model used by the supplied column.
  `String`
  `getColumnName(int columnIndex)`
  Returns the header text for the supplied column.
  `int`
  `getRowCount()`
  Returns the number of rows currently exposed by the rows model.
  `ValueModel`
  `getRowModel()`
  Returns the value model representing the current row object.
  `protected List`
  `getRows()`
  `ValueModel`
  `getRowsModel()`
  Returns the model that supplies the backing row collection.
  `Object`
  `getValueAt(int rowIndex, int columnIndex)`
  Reads the value for the supplied row and column.
  `boolean`
  `isCellEditable(int rowIndex, int columnIndex)`
  Indicates whether the supplied cell can be edited through its column model.
  `void`
  `removeColumn(DefaultTableColumn column)`
  Removes a column definition from the table
  `void`
  `setValueAt(Object value, int rowIndex, int columnIndex)`
  Writes a value to the supplied row and column when both coordinates are valid.

  ### 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 Details

  - ### DefaultTableModel

    public DefaultTableModel(ValueModel rowsModel)
    Creates a table model with its own row holder.
    Parameters:
      `rowsModel` - the model that supplies the row collection

  - ### DefaultTableModel

    public DefaultTableModel(ValueModel rowsModel, ValueModel rowModel)
    Creates a table model with explicit row and rows models.
    Parameters:
      `rowsModel` - the model that supplies the row collection
      `rowModel` - the model reused for exposing the current row

- ## Method Details

  - ### getColumnList

    public List getColumnList()
    Returns:
      the column definitions.

  - ### getColumnModel

    public TableColumnModel getColumnModel()
    Returns the Swing column model maintained by this table model.
    Returns:
      the column model

  - ### addPropertyColumn

    public DefaultTableColumn addPropertyColumn(Object headerValue, String property, Class type)
    Adds a property model column to the table

  - ### addPropertyColumn

    public DefaultTableColumn addPropertyColumn(Object headerValue, String property, Class type, boolean editable)
    Adds a property model column to the table

  - ### addClosureColumn

    public DefaultTableColumn addClosureColumn(Object headerValue, Closure readClosure, Closure writeClosure, Class type)
    Adds a closure based column to the table

  - ### addColumn

    public DefaultTableColumn addColumn(Object headerValue, ValueModel columnValueModel)
    Adds a column whose header value is also used as its identifier.
    Parameters:
      `headerValue` - the header value and identifier
      `columnValueModel` - the value model used by the column
    Returns:
      the created column

  - ### addColumn

    public DefaultTableColumn addColumn(Object headerValue, Object identifier, ValueModel columnValueModel)
    Adds a column definition with an explicit identifier.
    Parameters:
      `headerValue` - the header value
      `identifier` - the column identifier
      `columnValueModel` - the value model used by the column
    Returns:
      the created column

  - ### addColumn

    public void addColumn(DefaultTableColumn column)
    Adds a new column definition to the table

  - ### removeColumn

    public void removeColumn(DefaultTableColumn column)
    Removes a column definition from the table

  - ### getRowCount

    public int getRowCount()
    Returns the number of rows currently exposed by the rows model.
    Returns:
      the current row count

  - ### getColumnCount

    public int getColumnCount()
    Returns the number of configured columns.
    Returns:
      the current column count

  - ### getColumnName

    public String getColumnName(int columnIndex)
    Returns the header text for the supplied column.
    Specified by:
      `getColumnName` in interface `TableModel`
    Overrides:
      `getColumnName` in class `AbstractTableModel`
    Parameters:
      `columnIndex` - the column index
    Returns:
      the column header text, or `null` when unavailable

  - ### getColumnClass

    public Class getColumnClass(int columnIndex)
    Returns the declared value type for the supplied column.
    Specified by:
      `getColumnClass` in interface `TableModel`
    Overrides:
      `getColumnClass` in class `AbstractTableModel`
    Parameters:
      `columnIndex` - the column index
    Returns:
      the column value type

  - ### isCellEditable

    public boolean isCellEditable(int rowIndex, int columnIndex)
    Indicates whether the supplied cell can be edited through its column model.
    Specified by:
      `isCellEditable` in interface `TableModel`
    Overrides:
      `isCellEditable` in class `AbstractTableModel`
    Parameters:
      `rowIndex` - the row index
      `columnIndex` - the column index
    Returns:
      `true` when the column model is editable

  - ### getValueAt

    public Object getValueAt(int rowIndex, int columnIndex)
    Reads the value for the supplied row and column.
    Parameters:
      `rowIndex` - the row index
      `columnIndex` - the column index
    Returns:
      the cell value, or `null` when the coordinates are invalid

  - ### setValueAt

    public void setValueAt(Object value, int rowIndex, int columnIndex)
    Writes a value to the supplied row and column when both coordinates are valid.
    Specified by:
      `setValueAt` in interface `TableModel`
    Overrides:
      `setValueAt` in class `AbstractTableModel`
    Parameters:
      `value` - the new cell value
      `rowIndex` - the row index
      `columnIndex` - the column index

  - ### getColumnModel

    protected ValueModel getColumnModel(int columnIndex)
    Returns the value model used by the supplied column.
    Parameters:
      `columnIndex` - the column index
    Returns:
      the column value model

  - ### getRows

    protected List getRows()

  - ### getRowModel

    public ValueModel getRowModel()
    Returns the value model representing the current row object.
    Returns:
      the current row model

  - ### getRowsModel

    public ValueModel getRowsModel()
    Returns the model that supplies the backing row collection.
    Returns:
      the rows model