JIDE 3.5.15

com.jidesoft.combobox
Class FilterableComboBoxModel

java.lang.Object
  extended by javax.swing.AbstractListModel
      extended by com.jidesoft.combobox.DefaultComboBoxModelWrapper
          extended by com.jidesoft.combobox.FilterableComboBoxModel
All Implemented Interfaces:
ComboBoxModelWrapper, Serializable, EventListener, ComboBoxModel, ListDataListener, ListModel

public class FilterableComboBoxModel
extends DefaultComboBoxModelWrapper

FilterableComboBoxModel is a list model which wraps another list model so that user can apply filters on it.

You can use addFilter(Filter) to a filter to the ComboBoxModel. By default, filters won't take effect immediately. You need to call setFiltersApplied(true) to apply those filters. If filtersApplied flag is true already, you just need to call refresh(). We don't refresh automatically because you might have several filters to add. You can add all of them, then only call refresh once. setFiltersApplied(boolean) controls all the filters. Each filter has its own enabled flag which will control each individual filter.

By default, if you have more than one filters, all filters will be used in AND mode. You can see javadoc of setAndMode(boolean) to find more information.

See Also:
Serialized Form

Field Summary
protected  List<Filter> _filters
          The data structure contains all the filters.
protected  boolean _filtersApplied
          A flag to turn on/off filters.
 
Fields inherited from class com.jidesoft.combobox.DefaultComboBoxModelWrapper
_indexes, _model
 
Fields inherited from class javax.swing.AbstractListModel
listenerList
 
Constructor Summary
FilterableComboBoxModel()
           
FilterableComboBoxModel(ComboBoxModel model)
          Creates a FilterableComboBoxModel from any table model.
 
Method Summary
 void addFilter(Filter filter)
          Adds a filter to the list model.
 void addFilters(List<Filter> filters)
          Adds a list of filters to the list model.
 void clearFilters()
          Removes all filters of this list model.
 void contentsChanged(ListDataEvent e)
          The event handler when items are updated in the underlying combo box model.
 Filter[] getFilters()
          Gets all filters.
 void intervalAdded(ListDataEvent e)
          The event handler when new items are added in the underlying combo box model.
 void intervalRemoved(ListDataEvent e)
          The event handler when items are removed in the underlying combo box model.
 boolean isAndMode()
          Sets the logic of filters on the list model.
 boolean isFiltersApplied()
          Checks if the filters are in effect.
 boolean isReselectItemOnFiltering()
          Gets the flag indicating if FilterableComboBoxModel will try to reselect item if the current selected item is filtered away after filtering.
 void refresh()
          Reapply all filters after they are changed.
 void removeFilter(Filter filter)
          Removes the filter from the list model.
 void setActualModel(ComboBoxModel model)
          Sets the actual list model.
 void setAndMode(boolean andMode)
          Sets the logic of the filters on the same column.
 void setFiltersApplied(boolean apply)
          Applies or unapplies the filters.
 void setReselectItemOnFiltering(boolean reselectItemOnFiltering)
          Sets the flag indicating if FilterableComboBoxModel will try to reselect item if the current selected item is filtered away after filtering.
protected  boolean shouldBeFiltered(int row, List<Filter> filters)
          The method contains the algorithm to filter the specified row.
 
Methods inherited from class com.jidesoft.combobox.DefaultComboBoxModelWrapper
getActualIndexAt, getActualModel, getElementAt, getIndexAt, getIndexes, getSelectedItem, getSize, reallocateIndexes, setIndexes, setSelectedItem
 
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
 
Methods inherited from interface javax.swing.ListModel
addListDataListener, removeListDataListener
 

Field Detail

_filters

protected List<Filter> _filters
The data structure contains all the filters.


_filtersApplied

protected boolean _filtersApplied
A flag to turn on/off filters. setFiltersApplied(boolean) with true will turn it on and setFiltersApplied(boolean) with false will turn it off.

Constructor Detail

FilterableComboBoxModel

public FilterableComboBoxModel()

FilterableComboBoxModel

public FilterableComboBoxModel(ComboBoxModel model)
Creates a FilterableComboBoxModel from any table model.

Parameters:
model - the combobox model.
Method Detail

setActualModel

public void setActualModel(ComboBoxModel model)
Description copied from class: DefaultComboBoxModelWrapper
Sets the actual list model.

Specified by:
setActualModel in interface ComboBoxModelWrapper
Overrides:
setActualModel in class DefaultComboBoxModelWrapper
Parameters:
model - the list model.

intervalAdded

public void intervalAdded(ListDataEvent e)
Description copied from class: DefaultComboBoxModelWrapper
The event handler when new items are added in the underlying combo box model.

Specified by:
intervalAdded in interface ListDataListener
Overrides:
intervalAdded in class DefaultComboBoxModelWrapper
Parameters:
e - the event

intervalRemoved

public void intervalRemoved(ListDataEvent e)
Description copied from class: DefaultComboBoxModelWrapper
The event handler when items are removed in the underlying combo box model.

Specified by:
intervalRemoved in interface ListDataListener
Overrides:
intervalRemoved in class DefaultComboBoxModelWrapper
Parameters:
e - the event

contentsChanged

public void contentsChanged(ListDataEvent e)
Description copied from class: DefaultComboBoxModelWrapper
The event handler when items are updated in the underlying combo box model.

Specified by:
contentsChanged in interface ListDataListener
Overrides:
contentsChanged in class DefaultComboBoxModelWrapper
Parameters:
e - the event

refresh

public void refresh()
Reapply all filters after they are changed.


shouldBeFiltered

protected boolean shouldBeFiltered(int row,
                                   List<Filter> filters)
The method contains the algorithm to filter the specified row. If you want to filter the row, return true. Otherwise, return false. The default algorithm will filter the row whose if any of columns filters return true. Subclass can override this method to do a different way. Use getFilters(int col) to get filters. You should always check for isFiltersApplied(). If it's false, always return false. You should also check for each filter to see if it's enabled (filter.isEnabled()). If enabled return false, you should skip the filter.

Parameters:
row - the row index
filters - The list of filters
Returns:
true if the row should be filtered. Otherwise, false.

addFilters

public void addFilters(List<Filter> filters)
Adds a list of filters to the list model.

Parameters:
filters - the list of Filters.

addFilter

public void addFilter(Filter filter)
Adds a filter to the list model.

You can use AbstractFilter to create new filter. If you need the row index in order to decide if the value should be filtered, you can use AbstractListFilter and use getRowIndex() to find out current row index.

Parameters:
filter - the Filter to be added.

removeFilter

public void removeFilter(Filter filter)
Removes the filter from the list model.

Parameters:
filter - the Filter to be removed.

clearFilters

public void clearFilters()
Removes all filters of this list model.


getFilters

public Filter[] getFilters()
Gets all filters.

Returns:
the filters.

setFiltersApplied

public void setFiltersApplied(boolean apply)
Applies or unapplies the filters. By default, the filters are not applied. So after user adds several filters, this method should be called to make filters taking effect. When new filter is added or existing is removed, this method should be called as well.

Parameters:
apply - true to apply the filters.

isFiltersApplied

public boolean isFiltersApplied()
Checks if the filters are in effect.

Returns:
true if filters are in effect.

isAndMode

public boolean isAndMode()
Sets the logic of filters on the list model. If true, filters are in AND mode, meaning if one of the filters return true in isValueFiltered method, the value will be filtered. If false, filters are in OR mode, meaning if one of the filters return false, the value will NOT be filtered.

Returns:
the AND/OR mode. Default is true which means AND mode.

setAndMode

public void setAndMode(boolean andMode)
Sets the logic of the filters on the same column.

Parameters:
andMode - true or false.

isReselectItemOnFiltering

public boolean isReselectItemOnFiltering()
Gets the flag indicating if FilterableComboBoxModel will try to reselect item if the current selected item is filtered away after filtering.

Returns:
true if it tries to reselect item. Otherwise false.
Since:
3.2.3
See Also:
setReselectItemOnFiltering(boolean)

setReselectItemOnFiltering

public void setReselectItemOnFiltering(boolean reselectItemOnFiltering)
Sets the flag indicating if FilterableComboBoxModel will try to reselect item if the current selected item is filtered away after filtering.

By default, the flag is true to be more intuitive in UI. You could set this flag to false if you don't like the default behavior.

Parameters:
reselectItemOnFiltering - the flag
Since:
3.2.3

JIDE 3.5.15