Class TableModelWrapper<ROW_OBJECT>

  • Type Parameters:
    ROW_OBJECT - the row object type
    All Implemented Interfaces:
    RowObjectFilterModel<ROW_OBJECT>, RowObjectTableModel<ROW_OBJECT>, SelectionStorage<ROW_OBJECT>, javax.swing.table.TableModel

    public class TableModelWrapper<ROW_OBJECT>
    extends java.lang.Object
    implements RowObjectFilterModel<ROW_OBJECT>, SelectionStorage<ROW_OBJECT>
    A wrapper that will take a table model and decorate it with filtering capability. This is only needed when the given model does not have filtering.
    • Field Detail

      • filteredIndexList

        protected java.util.List<java.lang.Integer> filteredIndexList
    • Method Detail

      • wrappedModelChangedFromTableChangedEvent

        public void wrappedModelChangedFromTableChangedEvent()
      • fireTableDataChanged

        public void fireTableDataChanged​(javax.swing.event.TableModelEvent event)
      • addTableModelListener

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

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

        public java.lang.Class<?> getColumnClass​(int columnIndex)
        Specified by:
        getColumnClass in interface javax.swing.table.TableModel
      • getColumnCount

        public int getColumnCount()
        Specified by:
        getColumnCount in interface javax.swing.table.TableModel
      • getColumnName

        public java.lang.String getColumnName​(int columnIndex)
        Specified by:
        getColumnName in interface javax.swing.table.TableModel
      • getRowCount

        public int getRowCount()
        Specified by:
        getRowCount in interface javax.swing.table.TableModel
      • getModelData

        public java.util.List<ROW_OBJECT> getModelData()
        Description copied from interface: RowObjectTableModel
        Implementors should return the current data of the model. For models that support filtering, this will be the filtered version of the data. Furthermore, the data should be the underlying data and not a copy, as this method will potentially sort the given data.

        For those subclasses using an array, you may use the Arrays class to create a list backed by the array (Arrays.asList(Object...)).

        Specified by:
        getModelData in interface RowObjectTableModel<ROW_OBJECT>
        Returns:
        the model data.
      • getModelIndex

        public int getModelIndex​(ROW_OBJECT t)
        Description copied from interface: RowObjectFilterModel
        Returns the model index of the given item. When filtered, this is the index is the larger, set of data; when unfiltered, this index is the same as that returned by RowObjectFilterModel.getModelIndex(Object).

        This operation will be O(n) unless the implementation is sorted, in which case the operation is O(log n), as it uses a binary search.

        Specified by:
        getModelIndex in interface RowObjectFilterModel<ROW_OBJECT>
        Parameters:
        t - the item
        Returns:
        the model index
      • getViewIndex

        public int getViewIndex​(ROW_OBJECT t)
        Description copied from interface: RowObjectFilterModel
        Returns the view index of the given item. When filtered, this is the index is the smaller, visible set of data; when unfiltered, this index is the same as that returned by RowObjectFilterModel.getModelIndex(Object).

        This operation will be O(n) unless the implementation is sorted, in which case the operation is O(log n), as it uses a binary search.

        Specified by:
        getViewIndex in interface RowObjectFilterModel<ROW_OBJECT>
        Parameters:
        t - the item
        Returns:
        the view index
      • getRowIndex

        public int getRowIndex​(ROW_OBJECT t)
        Description copied from interface: RowObjectTableModel
        Returns the row number for the given object.

        Note: the index returned is always the 'view' index. For non-filtering table models, the 'view' and the 'model' index are the same. However, for filtering table models, the 'view' may be a subset of the 'model' index. Thus, it is possible, if this model is a filtering model, that the given t may not have a row value for the current state of the model (i.e., when the model is filtered in the view. If you really need to get the model index in such a situation, see RowObjectFilterModel.

        Specified by:
        getRowIndex in interface RowObjectTableModel<ROW_OBJECT>
        Parameters:
        t - the object
        Returns:
        the row number
      • getRowObject

        public ROW_OBJECT getRowObject​(int viewRow)
        Description copied from interface: RowObjectTableModel
        Returns the row object for the given row. This is the row in the UI. For models that know how to filter, the model row value will not match the view row value. For non-filtering models the view and model rows will always be the same.
        Specified by:
        getRowObject in interface RowObjectTableModel<ROW_OBJECT>
        Parameters:
        viewRow - the row for which to return a row object.
        Returns:
        the row object
      • getColumnValueForRow

        public java.lang.Object getColumnValueForRow​(ROW_OBJECT t,
                                                     int columnIndex)
        Description copied from interface: RowObjectTableModel
        Implementors are expected to return a value at the given column index for the specified row object. This is essentially a more specific version of the TableModel.getValueAt(int, int) that allows this class's comparator objects to work.
        Specified by:
        getColumnValueForRow in interface RowObjectTableModel<ROW_OBJECT>
        Parameters:
        t - The object that represents a given row.
        columnIndex - The column index for which a value is requested.
        Returns:
        a value at the given column index for the specified row object.
      • getValueAt

        public java.lang.Object getValueAt​(int rowIndex,
                                           int columnIndex)
        Specified by:
        getValueAt in interface javax.swing.table.TableModel
      • isCellEditable

        public boolean isCellEditable​(int rowIndex,
                                      int columnIndex)
        Specified by:
        isCellEditable in interface javax.swing.table.TableModel
      • setValueAt

        public void setValueAt​(java.lang.Object value,
                               int rowIndex,
                               int columnIndex)
        Specified by:
        setValueAt in interface javax.swing.table.TableModel
      • getWrappedModel

        public javax.swing.table.TableModel getWrappedModel()