org.gjt.sp.jedit.gui

## Class FilteredListModel<E extends javax.swing.ListModel>

- java.lang.Object
- - javax.swing.AbstractListModel
  - - org.gjt.sp.jedit.gui.FilteredListModel<E>

All Implemented Interfaces:
  java.io.Serializable, java.util.EventListener, javax.swing.event.ListDataListener, javax.swing.ListModel

    public abstract class FilteredListModel<E extends javax.swing.ListModel>
    extends javax.swing.AbstractListModel
    implements javax.swing.event.ListDataListener

This ListModel delegates another model to add some filtering features to any JList. 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 It is not mandatory but highly recommended to give the JList instance to the model in order to keep the selection after the filter has been updated

Since:
  jEdit 4.3pre11
See Also:
  Serialized Form

### Field Summary

Fields
`protected E` `delegated` The delegated table model.

### Fields inherited from class javax.swing.AbstractListModel

`listenerList`

### Constructor Summary

Constructors
`protected` `FilteredListModel(E delegated)`

### Method Summary

Methods
`void` `contentsChanged(javax.swing.event.ListDataEvent e)`
`E` `getDelegated()`
`java.lang.Object` `getElementAt(int index)`
`int` `getInternal2ExternalRow(int internalRowIndex)` Converts a row index from the delegated table model into a row index of the JTable.
`int` `getSize()`
`int` `getTrueRow(int rowIndex)` Converts a row index from the JTable to an internal row index from the delegated model.
`void` `intervalAdded(javax.swing.event.ListDataEvent e)`
`void` `intervalRemoved(javax.swing.event.ListDataEvent e)`
`abstract boolean` `passFilter(int row, java.lang.String filter)` This callback indicates if a row passes the filter.
`java.lang.String` `prepareFilter(java.lang.String filter)`
`protected void` `restoreSelection(java.util.Set<java.lang.Integer> selectedIndices)`
`protected java.util.Set<java.lang.Integer>` `saveSelection()`
`void` `setDelegated(E delegated)`
`void` `setFilter(java.lang.String filter)`
`void` `setList(javax.swing.JList list)` Set the JList that uses this model.

### Methods inherited from class javax.swing.AbstractListModel

`addListDataListener, fireContentsChanged, fireIntervalAdded, fireIntervalRemoved, getListDataListeners, getListeners, removeListDataListener`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### delegated

    protected E extends javax.swing.ListModel delegated

The delegated table model.

### Constructor Detail

#### FilteredListModel

    protected FilteredListModel(E delegated)

### Method Detail

#### setList

    public void setList(javax.swing.JList list)

Set the JList that uses this model. It is used to restore the selection after the filter has been applied If it is null,

Parameters:
  `list` - the list that uses the model

#### getDelegated

    public E getDelegated()

#### setDelegated

    public void setDelegated(E delegated)

#### setFilter

    public void setFilter(java.lang.String filter)

#### prepareFilter

    public java.lang.String prepareFilter(java.lang.String filter)

#### passFilter

    public abstract boolean passFilter(int row,
                     java.lang.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

#### saveSelection

    protected java.util.Set<java.lang.Integer> saveSelection()

#### restoreSelection

    protected void restoreSelection(java.util.Set<java.lang.Integer> selectedIndices)

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

#### getElementAt

    public java.lang.Object getElementAt(int index)

Specified by:
  `getElementAt` in interface `javax.swing.ListModel`

#### getSize

    public int getSize()

Specified by:
  `getSize` in interface `javax.swing.ListModel`

#### contentsChanged

    public void contentsChanged(javax.swing.event.ListDataEvent e)

Specified by:
  `contentsChanged` in interface `javax.swing.event.ListDataListener`

#### intervalAdded

    public void intervalAdded(javax.swing.event.ListDataEvent e)

Specified by:
  `intervalAdded` in interface `javax.swing.event.ListDataListener`

#### intervalRemoved

    public void intervalRemoved(javax.swing.event.ListDataEvent e)

Specified by:
  `intervalRemoved` in interface `javax.swing.event.ListDataListener`