Copyright © 2005 Scientific Applications. All Rights Reserved.

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:
FilterModelListener, ReorderListener, FilterListModel, ListTableModel, ReorderModel, Serializable, EventListener, TableModelListener, TableModel

public class FilterTableModel
extends ListTableMap
implements FilterListModel

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.

See Also:
Serialized Form

Field Summary
protected  boolean allowFilter
          a boolean flag that determines whether the model will perform the filtering if the underlying model changes (via updates, deletes or additions).
protected  boolean clearOnDataChanged
          a boolean flag that determines whether the model will assume that all data have changed when a fireTableDataChanged TableModelEvent has been issued.
protected  TableFilter tableFilter
          the currently installed table filter
 
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 applyFilter(FilterModelEvent e)
          Called whenever filtering of data has been requested.
 int convertRowIndexToModel(int viewRowIndex)
          Determines the index of the row in the underlying model in terms of the row index in this map.
 int convertRowIndexToView(int modelRowIndex)
          Determines the index of the row in this map in terms of the row index in the underlying model.
protected  int[] filterData()
          Filters the data of the table.
 boolean getAllowFilter()
          Determines whether the model will perform the filtering if the underlying model changes (via updates, deletes or additions).
 boolean getClearOnDataChanged()
          Determines whether the model will assume that all data have changed when a fireTableDataChanged TableModelEvent has been issued.
 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
 TableFilter getTableFilter()
          Returns the current TableFilter of this FilterTableModel.
 TableModel getUnfilteredTableModel()
          Returns a tableModel that holds the unfiltered data.
 Object getValueAt(int row, int column)
          Returns tableModel.getValueAt
 boolean isCellEditable(int rowIndex, int columnIndex)
          Returns tableModel.isCellEditable
 void reIndex()
          Reindexes the filter indexes.
 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)
          Called whenever the rows of a JTable have been restructured.
 void setAllowFilter(boolean allowFilter)
          Determines whether the model will perform the filtering if the underlying model changes (via updates, deletes or additions).
 void setClearOnDataChanged(boolean clearOnDataChanged)
          Determines whether the model will assume that all data have changed when a fireTableDataChanged TableModelEvent has been issued.
 void setFilteredIndexes(int[] indexes)
          Assigns the filter indexes.
 void setModel(ListTableModel newModel)
          Sets the underlying ListTableModel to newModel.
 void setTableFilter(TableFilter tableFilter)
          Assigns a new table filter.
 void setValueAt(Object aValue, int rowIndex, int columnIndex)
          Returns tableModel.setValueAt
 void tableChanged(TableModelEvent e)
          This fine grain notification tells listeners the exact range of cells, rows, or columns that changed.
 
Methods inherited from class com.sciapp.table.ListTableMap
addReorderListener, addRow, addRows, clear, fireRowsMapped, fireRowsReordered, getCellValue, getColumnClass, getColumnCount, getColumnName, getInnerModel, getModel, removeReorderListener
 
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
 
Methods inherited from interface javax.swing.table.TableModel
addTableModelListener, getColumnClass, getColumnCount, getColumnName, removeTableModelListener
 
Methods inherited from interface com.sciapp.table.ListTableModel
fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged
 

Field Detail

clearOnDataChanged

protected boolean clearOnDataChanged
a boolean flag that determines whether the model will assume that all data have changed when a fireTableDataChanged TableModelEvent has been issued.


allowFilter

protected boolean allowFilter
a boolean flag that determines whether the model will perform the filtering if the underlying model changes (via updates, deletes or additions).


tableFilter

protected TableFilter tableFilter
the currently installed table filter

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

applyFilter

public void applyFilter(FilterModelEvent e)
Called whenever filtering of data has been requested.

FilterModelListeners can get the TableFilter set by calling e.getTableFilter(). If the returned value is null, the FilterModelListener should remove the filter of the table.

Specified by:
applyFilter in interface FilterModelListener
Parameters:
e - the FilterModelEvent object

filterData

protected int[] filterData()
Filters the data of the table. Returns an int array that shows how the row indexes have changed after the filtering. See ReorderEvent.

Returns:
a representation of how the row indexes of the table have changed.

getAllowFilter

public boolean getAllowFilter()
Determines whether the model will perform the filtering if the underlying model changes (via updates, deletes or additions). The default is true.

Note that this setting has no effect when a filter is applied to the model via the setTableFilter or applyFilter methods. The filtering will always be performed in this case.

Returns:
true if the model will perform filtering when the underlying data changes, false otherwise.

getClearOnDataChanged

public boolean getClearOnDataChanged()
Determines whether the model will assume that all data have changed when a fireTableDataChanged TableModelEvent has been issued. The default value is false.

Returns:
true if all data have changed on a data changed event, false otherwise

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

getTableFilter

public TableFilter getTableFilter()
Returns the current TableFilter of this FilterTableModel.

Returns:
the assigned TableFilter.

getUnfilteredTableModel

public TableModel getUnfilteredTableModel()
Returns a tableModel that holds the unfiltered data.

Specified by:
getUnfilteredTableModel in interface FilterListModel
Returns:
the unfiltered tableModel

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)

reIndex

public void reIndex()
Reindexes the filter indexes.


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)
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

setAllowFilter

public void setAllowFilter(boolean allowFilter)
Determines whether the model will perform the filtering if the underlying model changes (via updates, deletes or additions). The default is true.

Note that this setting has no effect when a filter is applied to the model via the setTableFilter or applyFilter methods. The filtering will always be performed in this case.

Parameters:
allowFilter - true if the model will perform filtering when the underlying data changes, false otherwise.

setClearOnDataChanged

public void setClearOnDataChanged(boolean clearOnDataChanged)
Determines whether the model will assume that all data have changed when a fireTableDataChanged TableModelEvent has been issued. The default value is false.

Parameters:
clearOnDataChanged - true if all data have changed on a data changed event, false otherwise

setFilteredIndexes

public void setFilteredIndexes(int[] indexes)
Assigns the filter indexes.

Parameters:
indexes - the indexes to assign.

setTableFilter

public void setTableFilter(TableFilter tableFilter)
Assigns a new table filter. Same as applyFilter(com.sciapp.event.FilterModelEvent).

Parameters:
tableFilter - the TableFilter to assign.

setValueAt

public void setValueAt(Object aValue,
                       int rowIndex,
                       int columnIndex)
Returns tableModel.setValueAt

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)

tableChanged

public void tableChanged(TableModelEvent e)
This fine grain notification tells listeners the exact range of cells, rows, or columns that changed.

Specified by:
tableChanged in interface TableModelListener
Overrides:
tableChanged in class ListTableMap

setModel

public void setModel(ListTableModel newModel)
Sets the underlying ListTableModel to newModel.

Overrides:
setModel in class ListTableMap
Parameters:
newModel - the new ListTableModel to set

convertRowIndexToModel

public int convertRowIndexToModel(int viewRowIndex)
Determines the index of the row in the underlying model in terms of the row index in this map.

Overrides:
convertRowIndexToModel in class ListTableMap
Parameters:
viewRowIndex - the index of the row in this map
Returns:
the index of the corresponding row in the underlying model

convertRowIndexToView

public int convertRowIndexToView(int modelRowIndex)
Determines the index of the row in this map in terms of the row index in the underlying model. If the row is not viewable in the map (such as filtered out), -1 is returned.

Overrides:
convertRowIndexToView in class ListTableMap
Parameters:
modelRowIndex - the index of the row in the underlying model
Returns:
the index of the corresponding row in this map

Copyright © 2005 Scientific Applications. All Rights Reserved.