Class ListTableModel

java.lang.Object
javax.swing.table.AbstractTableModel
com.portal.browse.ListTableModel
All Implemented Interfaces:
Serializable, TableModel
Direct Known Subclasses:
ListTableSorter

public class ListTableModel extends AbstractTableModel
A table model the uses the List object from the collections api. The data is stored in a list of lists. By default, this model will use ArrayList if one is not provided in the constructor
Version:
%version%
Author:
Monica Gaines
See Also:
  • Field Details

    • dataList

      protected List dataList
    • headerList

      protected List headerList
  • Constructor Details

    • ListTableModel

      public ListTableModel()
      Constructs a table model with zero rows and columns.
    • ListTableModel

      public ListTableModel(List data)
      Constructs a table model and initializes the data to the given data list.
      Parameters:
      data - the data for the model
    • ListTableModel

      public ListTableModel(List data, List headers)
      Constructs a table model and initializes the data to the given data list and the headers to the given header list.
      Parameters:
      data - the data for the model
      headers - the column headers for the model
  • Method Details

    • isCellEditable

      public boolean isCellEditable(int row, int col)
      Specified by:
      isCellEditable in interface TableModel
      Overrides:
      isCellEditable in class AbstractTableModel
    • getRowCount

      public int getRowCount()
      Returns the number of rows in the model.
      Returns:
      the number of rows in the model
    • getColumnCount

      public int getColumnCount()
      Returns the number of columns in the model.
      Returns:
      the number of columns in the model
    • getColumnName

      public String getColumnName(int col)
      Returns the column name from the given column.
      Specified by:
      getColumnName in interface TableModel
      Overrides:
      getColumnName in class AbstractTableModel
      Parameters:
      col - the column whose name is to be looked up
      Returns:
      the string value for this column.
    • getValueAt

      public Object getValueAt(int row, int col)
      Returns a value for the cell at the given row and column.
      Parameters:
      row - the row whose value is to be looked up
      col - the column whose value is to be looked up
      Returns:
      the value of the object at the given cell
    • getDataAt

      public List getDataAt(int row)
      Returns a list of data at the given row.
      Parameters:
      row - the row whose dat is to be looked up
      Returns:
      the list of data at the given row
    • getDataList

      public List getDataList()
      Returns a List of Lists that contains the data for the table. The outer list corresponds to a single row of data.
      Returns:
      the table data
    • setValueAt

      public void setValueAt(Object val, int row, int col)
      Sets the value for the cell at the given row and column. This method will generate a tableChanged notification.
      Specified by:
      setValueAt in interface TableModel
      Overrides:
      setValueAt in class AbstractTableModel
      Parameters:
      val - the new value for the given cell
      row - the row whose value is to be changed
      col - the column whose value is to be changed
    • getColumnClass

      public Class getColumnClass(int col)
      Used to determine the default renderer/editor for each cell.
      Specified by:
      getColumnClass in interface TableModel
      Overrides:
      getColumnClass in class AbstractTableModel
    • setDataList

      public void setDataList(List data)
      Replace the current data list with the given list. This method will generate a tableChanged notification.
      Parameters:
      data - the new data list
    • setHeaderList

      public void setHeaderList(List headers)
      Replace the current header list with the given list. This method will generate a table structure changed notification.
      Parameters:
      headers - the new header list
    • addColumn

      public void addColumn(Object newCol)
      Add a column to the model. This method will generate a table structure change notification.
    • addRow

      public void addRow(List rowData)
      Add the given row to the end of the model. This method will generate a tableChanged notification.
      Parameters:
      rowData - the row being added
    • addRow

      public void addRow(int row, List rowData)
      Insert the given row to at the specified location in the model. This method will generate a tableChaned notification.
      Parameters:
      row - the index where the row is to be inserted
      rowData - the row being added
    • addRowBatch

      public void addRowBatch(List rowData)
      Add the given batch of rows to the end of the model. This method will generate a tableChaned notification.
      Parameters:
      rowData - mutliple rows of data
    • removeRow

      public void removeRow(int row)
      Remove the given row from the model. This method will generate a table rows deleted notification.
      Parameters:
      row - the index of the row to be removed