Class DefaultTableModel

java.lang.Object
com.globalmentor.beans.BoundPropertyObject
All Implemented Interfaces:
com.globalmentor.beans.PropertyBindable, com.globalmentor.beans.PropertyConstrainable, Model, TableModel

public class DefaultTableModel extends AbstractTableModel
The default implementation of a table model. The model is thread-safe, synchronized on itself. Any iteration over values should include synchronization on the instance of this class.
Author:
Garret Wilson
  • Nested Class Summary

    Nested classes/interfaces inherited from interface io.guise.framework.model.TableModel

    TableModel.Cell<C>
  • Field Summary

    Fields inherited from class com.globalmentor.beans.BoundPropertyObject

    NO_PROPERTY_CHANGE_LISTENERS, NO_VETOABLE_CHANGE_LISTENERS
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a default table model indicating the type of values it can hold along with column definitions.
    DefaultTableModel(Class<C> valueClass, C[][] rowValues, String... columnNames)
    Constructs a default table model indicating the type of values it can hold and column names.
    DefaultTableModel(Class<C> valueClass, String... columnNames)
    Constructs a default table model indicating the type of values it can hold, using default column models.
    DefaultTableModel(Object[][] rowValues, TableColumnModel<?>... columns)
    Constructs a default table model indicating the type of values it can hold.
  • Method Summary

    Modifier and Type
    Method
    Description
    static <C> TableColumnModel<C>[]
    createDefaultColumns(Class<C> valueClass, String... columnNames)
    Creates default columns with the given column names.
    <C> C
    getCellValue(int rowIndex, TableColumnModel<C> column)
    Returns the cell value at the given row and column.
    int
     
    <C> void
    setCellValue(int rowIndex, TableColumnModel<C> column, C newCellValue)
    Sets the cell value at the given row and column.

    Methods inherited from class io.guise.framework.model.AbstractTableModel

    addColumn, clearColumns, getCellValue, getColumnCount, getColumnIndex, getColumns, setCellValue

    Methods inherited from class io.guise.framework.model.AbstractModel

    getEventListenerManager, getPlainText

    Methods inherited from class com.globalmentor.beans.BoundPropertyObject

    addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, addVetoableChangeListener, createPostponedPropertyChangeEvent, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, getForwardPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyChangeSupport, getRepeatPropertyChangeListener, getRepeatVetoableChangeListener, getVetoableChangeListeners, getVetoableChangeListeners, getVetoableChangeSupport, hasPropertyChangeListeners, hasVetoableChangeListeners, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, removeVetoableChangeListener

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.globalmentor.beans.PropertyBindable

    addPropertyChangeListener, addPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, hasPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener

    Methods inherited from interface com.globalmentor.beans.PropertyConstrainable

    addVetoableChangeListener, addVetoableChangeListener, getVetoableChangeListeners, getVetoableChangeListeners, hasVetoableChangeListeners, removeVetoableChangeListener, removeVetoableChangeListener
  • Constructor Details

    • DefaultTableModel

      public DefaultTableModel(Class<C> valueClass, String... columnNames)
      Constructs a default table model indicating the type of values it can hold, using default column models.
      Type Parameters:
      C - The type of values in all the cells in the table.
      Parameters:
      valueClass - The class indicating the type of values held in the model.
      columnNames - The names to serve as label headers for the columns.
      Throws:
      NullPointerException - if the given class object is null.
    • DefaultTableModel

      public DefaultTableModel(TableColumnModel<?>... columns)
      Constructs a default table model indicating the type of values it can hold along with column definitions.
      Parameters:
      columns - The models representing the table columns.
      Throws:
      NullPointerException - if the given class object is null.
    • DefaultTableModel

      public DefaultTableModel(Class<C> valueClass, C[][] rowValues, String... columnNames)
      Constructs a default table model indicating the type of values it can hold and column names.
      Type Parameters:
      C - The type of values in all the cells in the table.
      Parameters:
      valueClass - The class indicating the type of values held in the model.
      rowValues - The two-dimensional list of values, where the first index represents the row and the second represents the column, or null if no default values should be given.
      columnNames - The names to serve as label headers for the columns.
      Throws:
      NullPointerException - if the given class object is null.
      IllegalArgumentException - if the given number of columns does not equal the number of columns in any given data row.
    • DefaultTableModel

      public DefaultTableModel(Object[][] rowValues, TableColumnModel<?>... columns)
      Constructs a default table model indicating the type of values it can hold.
      Parameters:
      rowValues - The two-dimensional list of values, where the first index represents the row and the second represents the column, or null if no default values should be given.
      columns - The models representing the table columns.
      Throws:
      IllegalArgumentException - if the given number of columns does not equal the number of columns in any given data row.
      ClassCastException - if one of the values in a row is not compatible with the type of its column.
  • Method Details

    • getRowCount

      public int getRowCount()
      Returns:
      The number of rows in this table.
    • createDefaultColumns

      public static <C> TableColumnModel<C>[] createDefaultColumns(Class<C> valueClass, String... columnNames)
      Creates default columns with the given column names.
      Type Parameters:
      C - The type of values contained in the columns.
      Parameters:
      valueClass - The class representing the values contained in the columns.
      columnNames - The names to serve as label headers for the columns.
      Returns:
      An array of default columns.
    • getCellValue

      public <C> C getCellValue(int rowIndex, TableColumnModel<C> column)
      Description copied from interface: TableModel
      Returns the cell value at the given row and column.
      Type Parameters:
      C - The type of cell values in the given column.
      Parameters:
      rowIndex - The zero-based row index.
      column - The column for which a value should be returned.
      Returns:
      The value in the cell at the given row and column, or null if there is no value in that cell.
    • setCellValue

      public <C> void setCellValue(int rowIndex, TableColumnModel<C> column, C newCellValue)
      Description copied from interface: TableModel
      Sets the cell value at the given row and column.
      Type Parameters:
      C - The type of cell values in the given column.
      Parameters:
      rowIndex - The zero-based row index.
      column - The column for which a value should be returned.
      newCellValue - The value to place in the cell at the given row and column, or null if there should be no value in that cell.