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
FieldsFields inherited from class javax.swing.table.AbstractTableModel
listenerList -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionClass<?> getColumnClass(int columnIndex) intgetColumnName(int columnIndex) intgetInternal2ExternalRow(int internalRowIndex) Converts a row index from the delegated table model into a row index of the JTable.intintgetTrueRow(int rowIndex) Converts a row index from the JTable to an internal row index from the delegated model.getValueAt(int rowIndex, int columnIndex) booleanisCellEditable(int rowIndex, int columnIndex) abstract booleanpassFilter(int row, String filter) This callback indicates if a row passes the filter.prepareFilter(String filter) voidsetDelegated(E delegated) voidvoidSet the JTable that uses this model.voidsetValueAt(Object aValue, int rowIndex, int columnIndex) voidThis 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:
getRowCountin interfaceTableModel
-
getColumnCount
public int getColumnCount()- Specified by:
getColumnCountin interfaceTableModel
-
getColumnName
- Specified by:
getColumnNamein interfaceTableModel- Overrides:
getColumnNamein classAbstractTableModel
-
getColumnClass
- Specified by:
getColumnClassin interfaceTableModel- Overrides:
getColumnClassin classAbstractTableModel
-
isCellEditable
public boolean isCellEditable(int rowIndex, int columnIndex) - Specified by:
isCellEditablein interfaceTableModel- Overrides:
isCellEditablein classAbstractTableModel
-
getValueAt
- Specified by:
getValueAtin interfaceTableModel
-
setValueAt
- Specified by:
setValueAtin interfaceTableModel- Overrides:
setValueAtin 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:
tableChangedin interfaceTableModelListener
-