Class KeyValueTableModel<T>

java.lang.Object
javax.swing.table.AbstractTableModel
xal.extension.widgets.swing.KeyValueTableModel<T>
All Implemented Interfaces:
Serializable, TableModel
Direct Known Subclasses:
KeyValueFilteredTableModel

public class KeyValueTableModel<T> extends AbstractTableModel
Table Model whose records are arbitrary objects and whose values are obtained through the Key-Value adaptor
See Also:
  • Field Details

    • keyValueAdaptor

      protected final KeyValueAdaptor keyValueAdaptor
      key value adaptor to get the value from a record (row) for the specified key path (column property)
  • Constructor Details

    • KeyValueTableModel

      public KeyValueTableModel(List<T> records, String... keyPaths)
      Primary Constructor
      Parameters:
      records - the list of objects (one record for each table row)
      keyPaths - specifies the array of key paths to get the data to display (one key path for each column)
    • KeyValueTableModel

      public KeyValueTableModel()
      Empty Constructor
  • Method Details

    • addKeyValueRecordListener

      public void addKeyValueRecordListener(KeyValueRecordListener<? extends KeyValueTableModel<T>,T> listener)
      Add the specified listener as a receiver of record modification events from this instance.
      Parameters:
      listener - object to receive events
    • removeKeyValueRecordListener

      public void removeKeyValueRecordListener(KeyValueRecordListener<KeyValueTableModel<T>,T> listener)
      Remove the specified listener from receiving record modification events from this instance.
      Parameters:
      listener - object to be removed from receiving events
    • setDataSource

      public void setDataSource(List<T> records, String... keyPaths)
      Set the records (row) and key paths (column accessors)
      Parameters:
      records - the list of objects (one record for each table row)
      keyPaths - specifies the array of key paths to get the data to display (one key path for each column)
    • getRecordAtRow

      public T getRecordAtRow(int row)
      Get the record at the specified row index
    • getRowRecords

      public List<T> getRowRecords()
      Get the records indexed by row
    • setRecords

      public void setRecords(List<T> records)
      Set the records (row)
      Parameters:
      records - the list of objects (one record for each table row)
    • getKeyPathForColumn

      public String getKeyPathForColumn(int column)
      Get the key path for the specified model column
      Parameters:
      column - model column for which to get the key path
      Returns:
      key path for the specified model column or null if the column is out of bounds
    • getColumnForKeyPath

      public int getColumnForKeyPath(String keyPath)
      Get the model column for the specified key path
      Parameters:
      keyPath - key path to the specified column
      Returns:
      model column index for the specified key path or -1 if no match
    • setKeyPaths

      public void setKeyPaths(String... keyPaths)
      Set the key paths (column accessors)
      Parameters:
      keyPaths - specifies the array of key paths to get the data to display (one key path for each column)
    • setColumnName

      public void setColumnName(String keyPath, String name)
      Set the name of the specified column
      Parameters:
      keyPath - key path for which to assign the name
      name - the new name to assign the column
    • getColumnName

      public String getColumnName(int column)
      Get the name of the specified column
      Specified by:
      getColumnName in interface TableModel
      Overrides:
      getColumnName in class AbstractTableModel
    • setColumnClass

      public void setColumnClass(String keyPath, Class<?> columnClass)
      Set the column class for the specified column
      Parameters:
      keyPath - key path for which to assign the class
      columnClass - the new class to assign the column
    • setColumnClassForKeyPaths

      public void setColumnClassForKeyPaths(Class<?> columnClass, String... keyPaths)
      Set the column class for the columns specified by the key paths
      Parameters:
      columnClass - the new class to assign the column
      keyPaths - key paths for which to assign the class
    • getColumnClass

      public Class<?> getColumnClass(int column)
      Get the data class for the specified column
      Specified by:
      getColumnClass in interface TableModel
      Overrides:
      getColumnClass in class AbstractTableModel
    • getRowCount

      public int getRowCount()
      Get the number of rows to display
    • getColumnCount

      public int getColumnCount()
      Get the number of columns to display
    • setColumnEditable

      public void setColumnEditable(String keyPath, boolean allowsEdit)
      Set whether the column associated with the specified key path is editable
    • setColumnEditKeyPath

      public void setColumnEditKeyPath(String columnKeyPath, String editKeyPath)
      Set whether a cell associated with the specified column key path is editable based on the cell's record value corresponding to the specified edit key path
      Parameters:
      columnKeyPath - key path of the column for which the edit rule applies
      editKeyPath - key path (applied to the row's record) whose corresponding value determines whether the cell (of the row's record) is editable
    • setColumnEditKeyPath

      public void setColumnEditKeyPath(String columnKeyPath, String editKeyPath, boolean negation)
      Set whether a cell associated with the specified column key path is editable based on the cell's record value corresponding to the specified edit key path
      Parameters:
      columnKeyPath - key path of the column for which the edit rule applies
      editKeyPath - key path (applied to the row's record) whose corresponding value determines whether the cell (of the row's record) is editable
      negation - indicates whether to reverse the boolean indication of the edit column
    • isCellEditable

      public boolean isCellEditable(int row, int column)
      Determine whether the cell is editable
      Specified by:
      isCellEditable in interface TableModel
      Overrides:
      isCellEditable in class AbstractTableModel
    • getValueAt

      public Object getValueAt(int row, int column)
      get the value for the specified cell
    • setValueAt

      public void setValueAt(Object value, int row, int column)
      Set the value of the specified cell
      Specified by:
      setValueAt in interface TableModel
      Overrides:
      setValueAt in class AbstractTableModel