tableoperations
Class TableFilter

java.lang.Object
  extended byjavax.swing.table.AbstractTableModel
      extended bytableoperations.TableMap
          extended bytableoperations.TableFilter
All Implemented Interfaces:
EventListener, Serializable, TableModel, TableModelListener
Direct Known Subclasses:
TableParamsFilter

public abstract class TableFilter
extends TableMap

A filter for TableModels. The filter has a model (conforming to TableModel) and implements itself TableModel. TableFilter neither stores nor copies the data in the TableModel, instead it maintains an arraylist of integers which keeps the current rows that are not to be filtered. When the model changes it notifies the filter that something has changed (e.g. "rowsAdded") so that its internal array of integers can be reallocated. As requests are made of the filter (like getValueAt(row, col) it redirects them to its model via the mapping arraylist. In this way the TableFilter appears to hold another copy of the table with the filtered rows. The class TableFilter is abstract so it has to be subclassed in order to specify the filter function.

Author:
Etienne Fort
See Also:
TableSorter, Serialized Form

Field Summary
(package private)  ArrayList indexes
           
(package private)  int rowCount
           
 
Fields inherited from class tableoperations.TableMap
model
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
TableFilter()
          Creates a new empty TableFilter.
TableFilter(TableModel model)
          Creates a new TableFilter on the TableModel model.
 
Method Summary
 void checkModel()
           
abstract  boolean filterFunction(int row)
          Allows to filter the table.
 int getRowCount()
           
 Object getValueAt(int aRow, int aColumn)
           
 boolean isCellEditable(int row, int column)
           
 void reallocateIndexes()
          Computes the mapping arraylist of indexes.
 void setModel(TableModel model)
           
 void setValueAt(Object aValue, int aRow, int aColumn)
           
 void tableChanged(TableModelEvent e)
          Called when the model has changed.
 
Methods inherited from class tableoperations.TableMap
getColumnClass, getColumnCount, getColumnName, getModel, writeToFileAsCsv
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rowCount

int rowCount

indexes

ArrayList indexes
Constructor Detail

TableFilter

public TableFilter()
Creates a new empty TableFilter.


TableFilter

public TableFilter(TableModel model)
Creates a new TableFilter on the TableModel model.

Parameters:
model - the TableModel which is filtered.
Method Detail

setModel

public void setModel(TableModel model)
Overrides:
setModel in class TableMap

filterFunction

public abstract boolean filterFunction(int row)
Allows to filter the table. This function is supposed to return true if the line belongs to the table, false otherwise

Parameters:
row - index of the row to check.
Returns:
false if the line must be ignored, true otherwise

reallocateIndexes

public void reallocateIndexes()
Computes the mapping arraylist of indexes.


tableChanged

public void tableChanged(TableModelEvent e)
Called when the model has changed. Then recomputes the mapping arraylist and forwards the tablechanged event to the listeners of this TableFilter.

Specified by:
tableChanged in interface TableModelListener
Overrides:
tableChanged in class TableMap
See Also:
TableModelListener.tableChanged(javax.swing.event.TableModelEvent)

checkModel

public void checkModel()

getRowCount

public int getRowCount()
Specified by:
getRowCount in interface TableModel
Overrides:
getRowCount in class TableMap

isCellEditable

public boolean isCellEditable(int row,
                              int column)
Specified by:
isCellEditable in interface TableModel
Overrides:
isCellEditable in class TableMap
See Also:
TableModel.isCellEditable(int, int)

getValueAt

public Object getValueAt(int aRow,
                         int aColumn)
Specified by:
getValueAt in interface TableModel
Overrides:
getValueAt in class TableMap
See Also:
TableModel.getValueAt(int, int)

setValueAt

public void setValueAt(Object aValue,
                       int aRow,
                       int aColumn)
Specified by:
setValueAt in interface TableModel
Overrides:
setValueAt in class TableMap
See Also:
TableModel.setValueAt(java.lang.Object, int, int)