Class ViewerTableModel

java.lang.Object
javax.swing.table.AbstractTableModel
uk.ac.starlink.topcat.ViewerTableModel
All Implemented Interfaces:
Serializable, TableModel

public class ViewerTableModel extends AbstractTableModel
A TableModel which is based on a StarTable but also provides methods for ordering rows and selecting which rows will be visible. This class is used as the TableModel for the TableViewer widget.
Author:
Mark Taylor (Starlink)
See Also:
  • Constructor Details

    • ViewerTableModel

      public ViewerTableModel(PlasticStarTable startable)
      Constructs a ViewerTableModel from a StarTable. The supplied StarTable must provide random access.
      Parameters:
      startable - the StarTable object
      Throws:
      IllegalArgumentException - if startable.isRandom returns false
  • Method Details

    • setOrder

      public void setOrder(int[] order)
      Configures this view to view the rows of the base model in a given order. The supplied order array should be a 1:1 mapping of rows in the base table to the order in which they will be viewed. This method triggers a suitable TableModelEvent to listeners.
      Parameters:
      order - mapping of rows in the table view, or null to indicate natural ordering
    • setSubset

      public void setSubset(RowSubset rset)
      Configures this view to view only a subset of the rows of the base model. This method triggers a suitable TableModelEvent to listeners.
      Parameters:
      rset - RowSubset object indicating inclusion in subset of rows to be viewed
    • getSubset

      public RowSubset getSubset()
      Returns the RowSubset currently used by the viewer model.
      Returns:
      the row subset
    • getRowMap

      public int[] getRowMap()
      Returns the mapping from row index visible in this model to row index in the base table.
      Returns:
      row mapping; may be null to indicate a unit map
    • getRowIndexIterator

      public Iterator<Long> getRowIndexIterator()
      Returns an iterator over the base table row indices represented by this view. This is an iteration over the values in the rowMap if it is non-null, or an iterator over all the rows if it is null. The number of elements iterated over is given by getRowCount().
      Returns:
      row index iterator
    • setRowMap

      public void setRowMap(int[] rowMap)
      Sets the mapping from row index visible in this model to row index in the base table.
      Parameters:
      rowMap - row mapping; may be null to indicate a unit map
    • getColumnCount

      public int getColumnCount()
    • getRowCount

      public int getRowCount()
    • getBaseRow

      public long getBaseRow(int irow)
      Returns the index of the data model row corresponding to a given row in this view model.
      Parameters:
      irow - index of the row in this view model
      Returns:
      index of the row in the base table
    • getViewRow

      public int getViewRow(long lrow)
      Returns the index at which a given table row appears in this view model. If the given table row doesn't appear in the view model (it's not included in the current subset) then -1 is returned.
      Parameters:
      lrow - index of the row in the base table
      Returns:
      index of the row in this view model, or -1
    • getValueAt

      public Object getValueAt(int irow, int icol)
    • isCellEditable

      public boolean isCellEditable(int irow, int icol)
      Specified by:
      isCellEditable in interface TableModel
      Overrides:
      isCellEditable in class AbstractTableModel
    • setValueAt

      public void setValueAt(Object val, int irow, int icol)
      Specified by:
      setValueAt in interface TableModel
      Overrides:
      setValueAt in class AbstractTableModel
    • getSnapshot

      public uk.ac.starlink.table.StarTable getSnapshot()
      Returns a new StarTable whose data corresponds to the current state of this ViewerTableModel. It has the same row ordering and subset, but subsequent changes to this model will not affect the data viewed from the resulting object.
      Returns:
      StarTable view of a snapshot of the data available from this model
    • getRowPermutedView

      public uk.ac.starlink.table.StarTable getRowPermutedView(uk.ac.starlink.table.StarTable table)
      Returns a view of a given table whose rows are permuted in the same way as the current view is permuted with respect to the basic table. The submitted table may be returned if no permutation is in force.
      Parameters:
      table - table to be permuted
      Returns:
      a table which is a possibly permuted view of table