java.lang.Object
javax.swing.table.AbstractTableModel
org.gjt.sp.jedit.gui.FilteredTableModel<E>
- All Implemented Interfaces:
Serializable
,EventListener
,TableModelListener
,TableModel
public abstract class FilteredTableModel<E extends TableModel>
extends AbstractTableModel
implements TableModelListener
This TableModel delegates another model to add some filtering features to any
JTable.
To use it you must implement the abstract method passFilter().
This method is called for each row, and must return true if the row should be
visible, and false otherwise.
It is also possible to override the method prepareFilter() that allow you to
transform the filter String. Usually you can return it as lowercase
Here is an example of how to use it extracted from the InstallPanel
PluginTableModel tableModel = new PluginTableModel();
filteredTableModel = new FilteredTableModel<PluginTableModel>(tableModel)
{
public String prepareFilter(String filter)
{
return filter.toLowerCase();
}
public boolean passFilter(int row, String filter)
{
String pluginName = (String) delegated.getValueAt(row, 1);
return pluginName.toLowerCase().contains(filter);
}
};
table = new JTable(filteredTableModel);
filteredTableModel.setTable(table);
It is not mandatory but highly recommended to give the JTable instance to the
model in order to keep the selection after the filter has been updated
- Since:
- jEdit 4.3pre11
- Version:
- $Id: Buffer.java 8190 2006-12-07 07:58:34Z kpouer $
- Author:
- Shlomy Reinstein, Matthieu Casanova
- See Also:
-
Field Summary
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionClass<?>
getColumnClass
(int columnIndex) int
getColumnName
(int columnIndex) int
getInternal2ExternalRow
(int internalRowIndex) Converts a row index from the delegated table model into a row index of the JTable.int
int
getTrueRow
(int rowIndex) Converts a row index from the JTable to an internal row index from the delegated model.getValueAt
(int rowIndex, int columnIndex) boolean
isCellEditable
(int rowIndex, int columnIndex) abstract boolean
passFilter
(int row, String filter) This callback indicates if a row passes the filter.prepareFilter
(String filter) void
setDelegated
(E delegated) void
void
Set the JTable that uses this model.void
setValueAt
(Object aValue, int rowIndex, int columnIndex) void
This fine grain notification tells listeners the exact range of cells, rows, or columns that changed.Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
-
Field Details
-
delegated
The delegated table model.
-
-
Constructor Details
-
FilteredTableModel
-
FilteredTableModel
protected FilteredTableModel()
-
-
Method Details
-
setTable
Set the JTable that uses this model. It is used to restore the selection after the filter has been applied If it is null,- Parameters:
table
- the table that uses the model
-
getDelegated
-
setDelegated
-
setFilter
-
prepareFilter
-
passFilter
This callback indicates if a row passes the filter.- Parameters:
row
- the row number the delegate row countfilter
- the filter string- Returns:
- true if the row must be visible
-
getRowCount
public int getRowCount()- Specified by:
getRowCount
in interfaceTableModel
-
getColumnCount
public int getColumnCount()- Specified by:
getColumnCount
in interfaceTableModel
-
getColumnName
- Specified by:
getColumnName
in interfaceTableModel
- Overrides:
getColumnName
in classAbstractTableModel
-
getColumnClass
- Specified by:
getColumnClass
in interfaceTableModel
- Overrides:
getColumnClass
in classAbstractTableModel
-
isCellEditable
public boolean isCellEditable(int rowIndex, int columnIndex) - Specified by:
isCellEditable
in interfaceTableModel
- Overrides:
isCellEditable
in classAbstractTableModel
-
getValueAt
- Specified by:
getValueAt
in interfaceTableModel
-
setValueAt
- Specified by:
setValueAt
in interfaceTableModel
- Overrides:
setValueAt
in classAbstractTableModel
-
getTrueRow
public int getTrueRow(int rowIndex) Converts a row index from the JTable to an internal row index from the delegated model.- Parameters:
rowIndex
- the row index- Returns:
- the row index in the delegated model
-
getInternal2ExternalRow
public int getInternal2ExternalRow(int internalRowIndex) Converts a row index from the delegated table model into a row index of the JTable.- Parameters:
internalRowIndex
- the internal row index- Returns:
- the table row index or -1 if this row is not visible
-
tableChanged
This fine grain notification tells listeners the exact range of cells, rows, or columns that changed.- Specified by:
tableChanged
in interfaceTableModelListener
-