Package uk.ac.starlink.topcat

## Class ViewerTableModel

- java.lang.Object
- - javax.swing.table.AbstractTableModel
  - - uk.ac.starlink.topcat.ViewerTableModel

- All Implemented Interfaces:
    `java.io.Serializable`, `javax.swing.table.TableModel`

      public class ViewerTableModel
      extends javax.swing.table.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:
    Serialized Form

- - ### Field Summary

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

      `listenerList`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `ViewerTableModel​(PlasticStarTable startable)` | Constructs a `ViewerTableModel` from a `StarTable`.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `long` | `getBaseRow​(int irow)` | Returns the index of the data model row corresponding to a given row in this view model.
    `int` | `getColumnCount()` |
    `int` | `getRowCount()` |
    `int[]` | `getRowMap()` | Returns the mapping from row index visible in this model to row index in the base table.
    `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.
    `uk.ac.starlink.table.StarTable` | `getSnapshot()` | Returns a new StarTable whose data corresponds to the current state of this ViewerTableModel.
    `RowSubset` | `getSubset()` | Returns the RowSubset currently used by the viewer model.
    `java.lang.Object` | `getValueAt​(int irow, int icol)` |
    `int` | `getViewRow​(long lrow)` | Returns the index at which a given table row appears in this view model.
    `boolean` | `isCellEditable​(int irow, int icol)` |
    `void` | `setOrder​(int[] order)` | Configures this view to view the rows of the base model in a given order.
    `void` | `setRowMap​(int[] rowMap)` | Sets the mapping from row index visible in this model to row index in the base table.
    `void` | `setSubset​(RowSubset rset)` | Configures this view to view only a subset of the rows of the base model.
    `void` | `setValueAt​(java.lang.Object val, int irow, int icol)` |

    - ### Methods inherited from class javax.swing.table.AbstractTableModel

      `addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getColumnClass, getColumnName, getListeners, getTableModelListeners, removeTableModelListener`

    - ### Methods inherited from class java.lang.Object

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

- - ### Constructor Detail

    - #### ViewerTableModel

          public ViewerTableModel​(PlasticStarTable startable)

      Constructs a `ViewerTableModel` from a `StarTable`. The supplied `StarTable` must provide random access.
      Parameters:
        `startable` - the `StarTable` object
      Throws:
        `java.lang.IllegalArgumentException` - if `startable.isRandom` returns `false`

  - ### Method Detail

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

    - #### 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 java.lang.Object getValueAt​(int irow,
                                             int icol)

    - #### isCellEditable

          public boolean isCellEditable​(int irow,
                                        int icol)

      Specified by:
        `isCellEditable` in interface `javax.swing.table.TableModel`
      Overrides:
        `isCellEditable` in class `javax.swing.table.AbstractTableModel`

    - #### setValueAt

          public void setValueAt​(java.lang.Object val,
                                 int irow,
                                 int icol)

      Specified by:
        `setValueAt` in interface `javax.swing.table.TableModel`
      Overrides:
        `setValueAt` in class `javax.swing.table.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`

Copyright © 2003-2018 CCLRC: Council for the Central Laboratory of the Research Councils. All Rights Reserved.