Class IdTableModel<T,​E>

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

    public class IdTableModel<T,​E>
    extends javax.swing.table.DefaultTableModel
    Table model for list of objects.
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.lang.Class<?>[] coltypes
      The column types.
      protected java.lang.String[] columns
      The column names.
      protected java.util.Map<T,​E> obs
      The known (id->ob).
      protected javax.swing.ListSelectionModel selmodel
      The selection model.
      protected java.util.List<E> sels
      The selected elems.
      protected javax.swing.JTable table
      The table.
      • Fields inherited from class javax.swing.table.DefaultTableModel

        columnIdentifiers, dataVector
      • Fields inherited from class javax.swing.table.AbstractTableModel

        listenerList
    • Constructor Summary

      Constructors 
      Constructor Description
      IdTableModel​(java.lang.String[] columns, java.lang.Class<?>[] coltypes, javax.swing.JTable table)
      Create a new table model.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addObject​(T id, E obj)
      Add a new object.
      void addTableModelListener​(javax.swing.event.TableModelListener l)  
      java.lang.Class<?> getColumnClass​(int i)
      Get the column class.
      int getColumnCount()
      Get the column count.
      java.lang.String getColumnName​(int i)
      Get the column name.
      E getObject​(java.lang.String id)
      Get an object for an id.
      java.util.Collection<E> getObjects()
      Get the objects.
      int getRowCount()
      Get the row count.
      java.lang.Object getValueAt​(int row, int column)
      Get the value at each row.
      java.lang.Object getValueAt​(E obj, int column)
      Get the cell value.
      java.util.List<E> getValues()
      Get the obs.
      boolean isCellEditable​(int row, int column)
      Test if cell is editable (default is false).
      void refresh()  
      void removeAll()
      Remove all objects.
      void removeObject​(T id)
      Remove an object.
      void removeTableModelListener​(javax.swing.event.TableModelListener l)  
      protected void restoreUserSelection()
      Restore the current user selection.
      protected void saveUserSelection()
      Save the current user selection
      void setObs​(java.util.Map<T,​E> obs)
      Set the obs.
      void setValueAt​(java.lang.Object val, int row, int column)  
      • Methods inherited from class javax.swing.table.DefaultTableModel

        addColumn, addColumn, addColumn, addRow, addRow, convertToVector, convertToVector, getDataVector, insertRow, insertRow, moveRow, newDataAvailable, newRowsAdded, removeRow, rowsRemoved, setColumnCount, setColumnIdentifiers, setColumnIdentifiers, setDataVector, setDataVector, setNumRows, setRowCount
      • Methods inherited from class javax.swing.table.AbstractTableModel

        findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • obs

        protected java.util.Map<T,​E> obs
        The known (id->ob).
      • columns

        protected java.lang.String[] columns
        The column names.
      • coltypes

        protected java.lang.Class<?>[] coltypes
        The column types.
      • sels

        protected java.util.List<E> sels
        The selected elems.
      • selmodel

        protected javax.swing.ListSelectionModel selmodel
        The selection model.
      • table

        protected javax.swing.JTable table
        The table.
    • Constructor Detail

      • IdTableModel

        public IdTableModel​(java.lang.String[] columns,
                            java.lang.Class<?>[] coltypes,
                            javax.swing.JTable table)
        Create a new table model.
    • Method Detail

      • getColumnCount

        public int getColumnCount()
        Get the column count.
        Specified by:
        getColumnCount in interface javax.swing.table.TableModel
        Overrides:
        getColumnCount in class javax.swing.table.DefaultTableModel
        Returns:
        The number of columns.
      • getColumnName

        public java.lang.String getColumnName​(int i)
        Get the column name.
        Specified by:
        getColumnName in interface javax.swing.table.TableModel
        Overrides:
        getColumnName in class javax.swing.table.DefaultTableModel
        Parameters:
        i - The index.
      • getColumnClass

        public java.lang.Class<?> getColumnClass​(int i)
        Get the column class.
        Specified by:
        getColumnClass in interface javax.swing.table.TableModel
        Overrides:
        getColumnClass in class javax.swing.table.AbstractTableModel
        Returns:
        The column class.
      • getRowCount

        public int getRowCount()
        Get the row count.
        Specified by:
        getRowCount in interface javax.swing.table.TableModel
        Overrides:
        getRowCount in class javax.swing.table.DefaultTableModel
        Returns:
        The row count.
      • getValueAt

        public java.lang.Object getValueAt​(int row,
                                           int column)
        Get the value at each row.
        Specified by:
        getValueAt in interface javax.swing.table.TableModel
        Overrides:
        getValueAt in class javax.swing.table.DefaultTableModel
      • getValueAt

        public java.lang.Object getValueAt​(E obj,
                                           int column)
        Get the cell value. Override to get specific value out of the object.
      • getValues

        public java.util.List<E> getValues()
        Get the obs.
        Returns:
        The obs.
      • setObs

        public void setObs​(java.util.Map<T,​E> obs)
        Set the obs.
        Parameters:
        obs - The obs to set.
      • isCellEditable

        public boolean isCellEditable​(int row,
                                      int column)
        Test if cell is editable (default is false).
        Specified by:
        isCellEditable in interface javax.swing.table.TableModel
        Overrides:
        isCellEditable in class javax.swing.table.DefaultTableModel
      • getObject

        public E getObject​(java.lang.String id)
        Get an object for an id.
        Parameters:
        id - The id.
        Returns:
        The object.
      • getObjects

        public java.util.Collection<E> getObjects()
        Get the objects.
      • addObject

        public void addObject​(T id,
                              E obj)
        Add a new object.
        Parameters:
        id - The id.
        obj - The object.
      • removeObject

        public void removeObject​(T id)
        Remove an object.
        Parameters:
        id - The id.
      • removeAll

        public void removeAll()
        Remove all objects.
      • setValueAt

        public void setValueAt​(java.lang.Object val,
                               int row,
                               int column)
        Specified by:
        setValueAt in interface javax.swing.table.TableModel
        Overrides:
        setValueAt in class javax.swing.table.DefaultTableModel
      • addTableModelListener

        public void addTableModelListener​(javax.swing.event.TableModelListener l)
        Specified by:
        addTableModelListener in interface javax.swing.table.TableModel
        Overrides:
        addTableModelListener in class javax.swing.table.AbstractTableModel
      • removeTableModelListener

        public void removeTableModelListener​(javax.swing.event.TableModelListener l)
        Specified by:
        removeTableModelListener in interface javax.swing.table.TableModel
        Overrides:
        removeTableModelListener in class javax.swing.table.AbstractTableModel
      • saveUserSelection

        protected void saveUserSelection()
        Save the current user selection
      • restoreUserSelection

        protected void restoreUserSelection()
        Restore the current user selection.
      • refresh

        public void refresh()