JIDE 3.5.15

com.jidesoft.grid
Class FilterItemSupport

java.lang.Object
  extended by com.jidesoft.grid.FilterItemSupport

public class FilterItemSupport
extends Object

FilterableTableModel is a table model which wraps another table model so that user can apply filters on it.

There are two ways to add a filter. One is to add a filter to apply to all the values in the table model using addFilter(Filter). Or you can add filter to a particular column using addFilter(int, Filter).

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(int) will control all the filters. Each filter has its own enabled flag which will control each individual filter.


Field Summary
protected  List<IFilterableTableModel.FilterItem> _allFilters
          A list containing all the FilterItems.
protected  boolean _filtersApplied
          A flag to turn on/off filters.
 
Constructor Summary
FilterItemSupport()
          Creates a FilterableTableModel from any table model.
 
Method Summary
 void addFilter(Filter filter)
          Adds a filter to all columns.
 void addFilter(IFilterableTableModel.FilterItem filterItem)
          Adds a FilterItem.
 void addFilter(int column, Filter filter)
          Adds a filter to the specified column.
 boolean clearFilters()
          Removes all filters from all columns.
 List<IFilterableTableModel.FilterItem> getFilterItems()
          Gets all the FilterItems added to this FilterableTableModel.
 Filter[] getFilters(int column)
          Gets the filters for the specified column.
 boolean hasFilter()
          Checks if the FilterableTableModel has any filters.
 boolean hasFilter(int columnIndex)
          Checks if the FilterableTableModel has any filters on the specified column.
 boolean isAndMode()
          Sets the logic of filters on the same column.
 boolean isFiltersApplied()
          Checks if the filters are in effect.
 void removeAllFilters()
          Removes all filters that are added using addFilter(Filter).
 boolean removeAllFilters(int column)
          Removes all filters from the specified column.
 boolean removeFilter(Filter filter)
          Removes the filter from all columns.
 boolean removeFilter(IFilterableTableModel.FilterItem filterItem)
          Removes the filter item.
 boolean removeFilter(int column, Filter filter)
          Removes the filter from the specified column.
 void setAndMode(boolean andMode)
          Sets the logic among the filters.
 void setFiltersApplied(boolean apply)
          Applies or unapplies the filters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_allFilters

protected List<IFilterableTableModel.FilterItem> _allFilters
A list containing all the FilterItems.


_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

FilterItemSupport

public FilterItemSupport()
Creates a FilterableTableModel from any table model.

Method Detail

addFilter

public void addFilter(int column,
                      Filter filter)
Adds a filter to the specified column.

Parameters:
column - the column index. It could also be two special values - IFilterableTableModel.ALL_COLUMNS or IFilterableTableModel.ANY_COLUMNS. If the value is IFilterableTableModel.ANY_COLUMNS, this method will be the same as addFilter(Filter).
filter - the filter to be added.

addFilter

public void addFilter(IFilterableTableModel.FilterItem filterItem)
Adds a FilterItem.

Parameters:
filterItem - the FilterItem

addFilter

public void addFilter(Filter filter)
Adds a filter to all columns. if one of the columns matches the filter, the row will be not be filtered.

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

Please note, addFilter will not change the FilterableTableModel data right away. You still need to call setFiltersApplied(true) to apply the filter. The reason is to give developers a chance to add/remove multiple filters and only updates the data once at the end.

Parameters:
filter - the filter to be added.

removeFilter

public boolean removeFilter(int column,
                            Filter filter)
Removes the filter from the specified column. The filter must be added using addFilter(int, Filter).

Please note, removeFilter will not change the FilterableTableModel data right away. You still need to call setFiltersApplied(true) to apply the filter. The reason is to give developers a chance to add/remove multiple filters and only updates the data once at the end.

Parameters:
column - the column index. It could also be two special values - IFilterableTableModel.ALL_COLUMNS or IFilterableTableModel.ANY_COLUMNS. If the value is IFilterableTableModel.ANY_COLUMNS, this method will be the same as removeFilter(Filter).
filter - the filter to be removed.
Returns:
true if there are some filters that are removed. False if no filter is removed.

removeFilter

public boolean removeFilter(IFilterableTableModel.FilterItem filterItem)
Removes the filter item.

Please note, removeFilter will not change the FilterableTableModel data right away. You still need to call setFiltersApplied(true) to apply the filter. The reason is to give developers a chance to add/remove multiple filters and only updates the data once at the end.

Parameters:
filterItem - the FilterItem to be removed.
Returns:
true if there are some filters that are removed. False if no filter is removed.

removeFilter

public boolean removeFilter(Filter filter)
Removes the filter from all columns. The filter must be added using addFilter(Filter).

Please note, removeFilter will not change the FilterableTableModel data right away. You still need to call setFiltersApplied(true) to apply the filter. The reason is to give developers a chance to add/remove multiple filters and only updates the data once at the end.

Parameters:
filter - the filter to be removed.
Returns:
true if there are some filters that are removed. False if no filter is removed.

removeAllFilters

public boolean removeAllFilters(int column)
Removes all filters from the specified column. Those filters are added using addFilter(int, Filter).

Please note, removeAllFilters will not change the FilterableTableModel data right away. You still need to call setFiltersApplied(true) to apply the filter. The reason is to give developers a chance to add/remove multiple filters and only updates the data once at the end.

Parameters:
column - the column index where all filters for that column should be removed.
Returns:
true if there are some filters that are removed. False if no filter is removed.

removeAllFilters

public void removeAllFilters()
Removes all filters that are added using addFilter(Filter). If you want to remove all filters that either added using addFilter(int, Filter) or addFilter(Filter), you should use clearFilters().

Please note, removeAllFilters will not change the FilterableTableModel data right away. You still need to call setFiltersApplied(true) to apply the filter. The reason is to give developers a chance to add/remove multiple filters and only updates the data once at the end.


clearFilters

public boolean clearFilters()
Removes all filters from all columns.

Please note, clearFilters will not change the FilterableTableModel data right away. You still need to call setFiltersApplied(true) to apply the filter. The reason is to give developers a chance to add/remove multiple filters and only updates the data once at the end.

Returns:
true if there are some filters that are removed. False if no filter is removed.

getFilters

public Filter[] getFilters(int column)
Gets the filters for the specified column.

Parameters:
column - the column index.
Returns:
the filters for the specified column.

getFilterItems

public List<IFilterableTableModel.FilterItem> getFilterItems()
Gets all the FilterItems added to this FilterableTableModel.

Returns:
all the FilterItems added to this FilterableTableModel.

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.

hasFilter

public boolean hasFilter()
Checks if the FilterableTableModel has any filters.

Returns:
true if there are any filters. Otherwise false.

hasFilter

public boolean hasFilter(int columnIndex)
Checks if the FilterableTableModel has any filters on the specified column.

Parameters:
columnIndex - the column index to check if there is a filter on it.
Returns:
true if there are any filters on the specified column. Otherwise false.

isAndMode

public boolean isAndMode()
Sets the logic of filters on the same column. 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.

The mode only has effect on the filters of the same columns which includes each column of the table model as well as the two special column value IFilterableTableModel.ALL_COLUMNS and IFilterableTableModel.ANY_COLUMNS.

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

setAndMode

public void setAndMode(boolean andMode)
Sets the logic among the filters. If AND is true, Please note, this logic mode will apply for all filters, no matter it's for a column or any column or all columns. You won't be able to do complex expression such as AND some filters and OR some other filters using one FitlerableTableModel. In order to do more complex expression, you would need multiple FilterableTableModel, one wraps the other. You make filters in each FilterableTableModel to be OR logic, then the logic among the pipe of FilterableTableModels will always be AND logic.

Parameters:
andMode - true or false.

JIDE 3.5.15