Package uk.ac.starlink.topcat

## Class ColumnDataComboBoxModel

- java.lang.Object
- - javax.swing.AbstractListModel<uk.ac.starlink.table.ColumnData>
  - - uk.ac.starlink.topcat.ColumnDataComboBoxModel

- All Implemented Interfaces:
    `java.io.Serializable`, `java.util.EventListener`, `javax.swing.ComboBoxModel<uk.ac.starlink.table.ColumnData>`, `javax.swing.event.TableColumnModelListener`, `javax.swing.ListModel<uk.ac.starlink.table.ColumnData>`

      public class ColumnDataComboBoxModel
      extends javax.swing.AbstractListModel<uk.ac.starlink.table.ColumnData>
      implements javax.swing.event.TableColumnModelListener, javax.swing.ComboBoxModel<uk.ac.starlink.table.ColumnData>

  ComboBoxModel for holding table per-row expressions. These may represent either actual columns or JEL expressions evaluated against columns. Elements of the model which contain usable data are instances of `ColumnData`. The selected item may be of some other type (currently String), and this should be ignored (treated as null) for the purposes of data access.

  The `ColumnDataComboBox` class should generally be used as a suitable host for instances of this class.

  Since:
    23 Jan 2005
  Author:
    Mark Taylor
  See Also:
    Serialized Form

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `static interface` | `ColumnDataComboBoxModel.Filter` | Determines what columns are acceptable for this model.

  - ### Field Summary

    - ### Fields inherited from class javax.swing.AbstractListModel

      `listenerList`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `ColumnDataComboBoxModel​(TopcatModel tcModel, java.lang.Class<?> dataClazz, boolean hasNone)` | Constructs a model for a given content class, optionally with a blank entry.
    `ColumnDataComboBoxModel​(TopcatModel tcModel, java.lang.Class<?> dataClazz, boolean hasNone, boolean hasIndex)` | Constructs a model for a given content class, optionally with a blank entry and an entry for the magic 'index' column.
    `ColumnDataComboBoxModel​(TopcatModel tcModel, ColumnDataComboBoxModel.Filter filter, boolean hasNone, boolean hasIndex)` | Constructs a model with a specified column metadata filter.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `columnAdded​(javax.swing.event.TableColumnModelEvent evt)` |
    `void` | `columnMarginChanged​(javax.swing.event.ChangeEvent evt)` |
    `void` | `columnMoved​(javax.swing.event.TableColumnModelEvent evt)` |
    `void` | `columnRemoved​(javax.swing.event.TableColumnModelEvent evt)` |
    `void` | `columnSelectionChanged​(javax.swing.event.ListSelectionEvent evt)` |
    `static uk.ac.starlink.table.ColumnData` | `createSimpleColumnData​(TopcatModel tcModel, uk.ac.starlink.table.gui.StarTableColumn tcol)` | Creates a ColumnData object simply representing a single column of a table.
    `uk.ac.starlink.table.ColumnData` | `getBestMatchColumnData​(uk.ac.starlink.table.ValueInfo info)` | Attempts to locate and return a member of this model which matches the given `info`.
    `uk.ac.starlink.table.ColumnData` | `getColumnDataAt​(int index)` | Returns the element at a given index as a typed object.
    `uk.ac.starlink.table.ColumnData` | `getElementAt​(int index)` |
    `java.lang.Object` | `getSelectedItem()` |
    `int` | `getSize()` |
    `uk.ac.starlink.table.ColumnData` | `getUniqueMatchColumnData​(uk.ac.starlink.table.ValueInfo info)` | Attempts to locate and return a member of this model which is the only match for a given `info`.
    `void` | `setSelectedItem​(java.lang.Object item)` |
    `uk.ac.starlink.table.ColumnData` | `stringToColumnData​(java.lang.String txt)` | Converts a string value to a ColumnData value suitable for selection by this model.

    - ### Methods inherited from class javax.swing.AbstractListModel

      `addListDataListener, fireContentsChanged, fireIntervalAdded, fireIntervalRemoved, getListDataListeners, getListeners, removeListDataListener`

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

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

    - ### Methods inherited from interface javax.swing.ListModel

      `addListDataListener, removeListDataListener`

- - ### Constructor Detail

    - #### ColumnDataComboBoxModel

          public ColumnDataComboBoxModel​(TopcatModel tcModel,
                                         ColumnDataComboBoxModel.Filter filter,
                                         boolean hasNone,
                                         boolean hasIndex)

      Constructs a model with a specified column metadata filter.
      Parameters:
        `tcModel` - table model containing columns
        `filter` - determines which columns are permitted
        `hasNone` - true iff you want a null entry in the selector model
        `hasIndex` - true iff you want an index column entry in the selector model

    - #### ColumnDataComboBoxModel

          public ColumnDataComboBoxModel​(TopcatModel tcModel,
                                         java.lang.Class<?> dataClazz,
                                         boolean hasNone,
                                         boolean hasIndex)

      Constructs a model for a given content class, optionally with a blank entry and an entry for the magic 'index' column.
      Parameters:
        `tcModel` - table model containing columns
        `dataClazz` - content class of permitted columns
        `hasNone` - true iff you want a null entry in the selector model
        `hasIndex` - true iff you want an index column entry in the selector model

    - #### ColumnDataComboBoxModel

          public ColumnDataComboBoxModel​(TopcatModel tcModel,
                                         java.lang.Class<?> dataClazz,
                                         boolean hasNone)

      Constructs a model for a given content class, optionally with a blank entry.
      Parameters:
        `tcModel` - table model containing columns
        `hasNone` - true iff you want a null entry in the selector model

  - ### Method Detail

    - #### getElementAt

          public uk.ac.starlink.table.ColumnData getElementAt​(int index)

      Specified by:
        `getElementAt` in interface `javax.swing.ListModel<uk.ac.starlink.table.ColumnData>`

    - #### getColumnDataAt

          public uk.ac.starlink.table.ColumnData getColumnDataAt​(int index)

      Returns the element at a given index as a typed object.
      Parameters:
        `index` - requested index
      Returns:
        value at index as a ColumnData, or null

    - #### getSize

          public int getSize()

      Specified by:
        `getSize` in interface `javax.swing.ListModel<uk.ac.starlink.table.ColumnData>`

    - #### getSelectedItem

          public java.lang.Object getSelectedItem()

      Specified by:
        `getSelectedItem` in interface `javax.swing.ComboBoxModel<uk.ac.starlink.table.ColumnData>`

    - #### stringToColumnData

          public uk.ac.starlink.table.ColumnData stringToColumnData​(java.lang.String txt)
                                                             throws gnu.jel.CompilationException

      Converts a string value to a ColumnData value suitable for selection by this model. If it cannot be done, a CompilationException is thrown.
      Parameters:
        `txt` - string expression (or column name) for data
      Returns:
        corresponding ColumnData object
      Throws:
        `gnu.jel.CompilationException` - if `txt` is not valid

    - #### setSelectedItem

          public void setSelectedItem​(java.lang.Object item)

      Specified by:
        `setSelectedItem` in interface `javax.swing.ComboBoxModel<uk.ac.starlink.table.ColumnData>`

    - #### getBestMatchColumnData

          public uk.ac.starlink.table.ColumnData getBestMatchColumnData​(uk.ac.starlink.table.ValueInfo info)

      Attempts to locate and return a member of this model which matches the given `info`. Exactly how the matching is done is not defined - presumably grubbing about with UCDs or column names etc.
      Parameters:
        `info` - metadata item to match
      Returns:
        object suitable for selection in this model which matches `info`, or null if nothing suitable can be found

    - #### getUniqueMatchColumnData

          public uk.ac.starlink.table.ColumnData getUniqueMatchColumnData​(uk.ac.starlink.table.ValueInfo info)

      Attempts to locate and return a member of this model which is the only match for a given `info`. If no good match can be found, or if multiple equally good matches are found, null is returned. Exactly how the matching is done is not defined - presumably grubbing about with UCDs or column names etc.
      Parameters:
        `info` - metadata item to match
      Returns:
        object suitable for selection in this model which matches `info`, or null if nothing suitable can be found

    - #### columnAdded

          public void columnAdded​(javax.swing.event.TableColumnModelEvent evt)

      Specified by:
        `columnAdded` in interface `javax.swing.event.TableColumnModelListener`

    - #### columnRemoved

          public void columnRemoved​(javax.swing.event.TableColumnModelEvent evt)

      Specified by:
        `columnRemoved` in interface `javax.swing.event.TableColumnModelListener`

    - #### columnMoved

          public void columnMoved​(javax.swing.event.TableColumnModelEvent evt)

      Specified by:
        `columnMoved` in interface `javax.swing.event.TableColumnModelListener`

    - #### columnMarginChanged

          public void columnMarginChanged​(javax.swing.event.ChangeEvent evt)

      Specified by:
        `columnMarginChanged` in interface `javax.swing.event.TableColumnModelListener`

    - #### columnSelectionChanged

          public void columnSelectionChanged​(javax.swing.event.ListSelectionEvent evt)

      Specified by:
        `columnSelectionChanged` in interface `javax.swing.event.TableColumnModelListener`

    - #### createSimpleColumnData

          public static uk.ac.starlink.table.ColumnData createSimpleColumnData​(TopcatModel tcModel,
                                                                               uk.ac.starlink.table.gui.StarTableColumn tcol)

      Creates a ColumnData object simply representing a single column of a table. Behaviour is undefined if tcol is not associated with the model.
      Parameters:
        `tcModel` - topcat model
        `tcol` - column in model
      Returns:
        column data object