Module jEdit

Class FilteredTableModel<E extends TableModel>

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 Details

    • delegated

      protected E extends TableModel delegated
      The delegated table model.
  • Constructor Details

    • FilteredTableModel

      protected FilteredTableModel(E delegated)
    • FilteredTableModel

      protected FilteredTableModel()
  • Method Details

    • setTable

      public void setTable(JTable table)
      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

      public E getDelegated()
    • setDelegated

      public void setDelegated(E delegated)
    • setFilter

      public void setFilter(String filter)
    • prepareFilter

      public String prepareFilter(String filter)
    • passFilter

      public abstract boolean passFilter(int row, String filter)
      This callback indicates if a row passes the filter.
      Parameters:
      row - the row number the delegate row count
      filter - the filter string
      Returns:
      true if the row must be visible
    • getRowCount

      public int getRowCount()
      Specified by:
      getRowCount in interface TableModel
    • getColumnCount

      public int getColumnCount()
      Specified by:
      getColumnCount in interface TableModel
    • getColumnName

      public String getColumnName(int columnIndex)
      Specified by:
      getColumnName in interface TableModel
      Overrides:
      getColumnName in class AbstractTableModel
    • getColumnClass

      public Class<?> getColumnClass(int columnIndex)
      Specified by:
      getColumnClass in interface TableModel
      Overrides:
      getColumnClass in class AbstractTableModel
    • isCellEditable

      public boolean isCellEditable(int rowIndex, int columnIndex)
      Specified by:
      isCellEditable in interface TableModel
      Overrides:
      isCellEditable in class AbstractTableModel
    • getValueAt

      public Object getValueAt(int rowIndex, int columnIndex)
      Specified by:
      getValueAt in interface TableModel
    • setValueAt

      public void setValueAt(Object aValue, int rowIndex, int columnIndex)
      Specified by:
      setValueAt in interface TableModel
      Overrides:
      setValueAt in class AbstractTableModel
    • 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

      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