com.sciapp.table
Class FilterTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by com.sciapp.table.ListTableMap
          extended by com.sciapp.table.FilterTableModel
All Implemented Interfaces:
ReorderListener, TableFilterListener, ListTableModel, ReorderModel, Serializable, EventListener, TableModelListener, TableModel

public class FilterTableModel
extends ListTableMap
implements TableFilterListener

FilterTableModel offers filtering capabilities to a table. This class needs a ListTableModel that holds the data of the table. FilterTableModel processes filtering requests and updates the data sent to the table accordingly.


Field Summary
 
Fields inherited from class com.sciapp.table.ListTableMap
tableModel
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
FilterTableModel(ListTableModel tableModel)
          Constructs a FilterTableModel having tableModel as the underlying ListTableModel holding the tabular data.
 
Method Summary
 void filter(TableFilter tf)
          Called whenever filtering of data has been requested.
 void fireTableChanged(TableModelEvent e)
          Forwards the given notification event to all TableModelListeners that registered themselves as listeners for this table model.
 int[] getFilteredIndexes()
          Returns an int array showing the relation between the original and the filtered data.
 int getRowCount()
          Returns tableModel.getRowCount
 List getRows()
          Returns tableModel.getRows
 Object getValueAt(int row, int column)
          Returns tableModel.getValueAt
 boolean isCellEditable(int rowIndex, int columnIndex)
          Returns tableModel.isCellEditable
 void removeFilter()
          Called whenever filtering of data has been cancelled.
 void removeRow(int row)
          Removes a row from the data model
 void removeRows(int[] deletedRows)
          Removes a few rows from the data model
 void rowsReordered(ReorderEvent e)
          Does nothing.
 void setValueAt(Object aValue, int rowIndex, int columnIndex)
          This empty implementation is provided so users don't have to implement this method if their data model is not editable.
 
Methods inherited from class com.sciapp.table.ListTableMap
addReorderListener, addRow, addRows, clear, fireRowsReordered, getCellValue, getColumnClass, getColumnCount, getColumnName, getModel, removeReorderListener, setModel, tableChanged
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, 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
 
Methods inherited from interface com.sciapp.table.ListTableModel
fireTableCellUpdated, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged
 
Methods inherited from interface javax.swing.table.TableModel
addTableModelListener, removeTableModelListener
 

Constructor Detail

FilterTableModel

public FilterTableModel(ListTableModel tableModel)
Constructs a FilterTableModel having tableModel as the underlying ListTableModel holding the tabular data.

Parameters:
tableModel - the underlying ListTableModel
Method Detail

filter

public void filter(TableFilter tf)
Called whenever filtering of data has been requested.

Specified by:
filter in interface TableFilterListener
Parameters:
tf - the TableFilter used to filter the data

fireTableChanged

public void fireTableChanged(TableModelEvent e)
Forwards the given notification event to all TableModelListeners that registered themselves as listeners for this table model.

Specified by:
fireTableChanged in interface ListTableModel
Overrides:
fireTableChanged in class AbstractTableModel
Parameters:
e - the event to be forwarded
See Also:
AbstractTableModel.addTableModelListener(javax.swing.event.TableModelListener), TableModelEvent, EventListenerList

getFilteredIndexes

public int[] getFilteredIndexes()
Returns an int array showing the relation between the original and the filtered data. More specifically, the integers in the array correspond to the position of objects in the original data. e.g. if this method returns {1, 4}, the first row now corresponds to the data at row 1, and the second row to the data at row 4.

Returns:
an int array showing the relation between the original and the filtered data.

getRowCount

public int getRowCount()
Returns tableModel.getRowCount

Specified by:
getRowCount in interface TableModel
Overrides:
getRowCount in class ListTableMap
Returns:
the number of rows in the model
See Also:
TableModel.getColumnCount()

getRows

public List getRows()
Returns tableModel.getRows

Specified by:
getRows in interface ListTableModel
Overrides:
getRows in class ListTableMap
Returns:
the rows of the datamodel as a java.util.List

getValueAt

public Object getValueAt(int row,
                         int column)
Returns tableModel.getValueAt

Specified by:
getValueAt in interface TableModel
Overrides:
getValueAt in class ListTableMap
Parameters:
row - the row whose value is to be queried
column - the column whose value is to be queried
Returns:
the value Object at the specified cell

isCellEditable

public boolean isCellEditable(int rowIndex,
                              int columnIndex)
Returns tableModel.isCellEditable

Specified by:
isCellEditable in interface TableModel
Overrides:
isCellEditable in class ListTableMap
Parameters:
rowIndex - the row being queried
columnIndex - the column being queried
Returns:
false
See Also:
TableModel.setValueAt(java.lang.Object, int, int)

removeFilter

public void removeFilter()
Called whenever filtering of data has been cancelled.

Specified by:
removeFilter in interface TableFilterListener

removeRow

public void removeRow(int row)
Removes a row from the data model

Specified by:
removeRow in interface ListTableModel
Overrides:
removeRow in class ListTableMap
Parameters:
row - the index of the row being removed

removeRows

public void removeRows(int[] deletedRows)
Removes a few rows from the data model

Specified by:
removeRows in interface ListTableModel
Overrides:
removeRows in class ListTableMap
Parameters:
deletedRows - an integer array that contains indexes of the rows being deleted

rowsReordered

public void rowsReordered(ReorderEvent e)
Does nothing. Called whenever the rows of a JTable have been restructured.

Specified by:
rowsReordered in interface ReorderListener
Overrides:
rowsReordered in class ListTableMap
Parameters:
e - the ReorderEvent object

setValueAt

public void setValueAt(Object aValue,
                       int rowIndex,
                       int columnIndex)
This empty implementation is provided so users don't have to implement this method if their data model is not editable.

Specified by:
setValueAt in interface TableModel
Overrides:
setValueAt in class ListTableMap
Parameters:
aValue - value to assign to cell
rowIndex - row of cell
columnIndex - column of cell
See Also:
TableModel.getValueAt(int, int), TableModel.isCellEditable(int, int)