JIDE 3.5.15

com.jidesoft.grid
Class FilterableTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by com.jidesoft.grid.TableModelWrapperImpl
          extended by com.jidesoft.grid.DefaultTableModelWrapper
              extended by com.jidesoft.grid.FilterableTableModel
All Implemented Interfaces:
AutoFilterTableHeaderAdapter, AutoFilterTableModel, ColumnIdentifierTableModel, ContextSensitiveTableModel, EditorStyleTableModel, IFilterableTableModel, IndexChangeEventGenerator, IndexedRowTableModelWrapper, MultiTableModel, NavigableModel, RowTableModelWrapper, SpanModel, StyleModel, TableModelWrapper, Serializable, EventListener, TableModelListener, TableModel
Direct Known Subclasses:
FilterableAggregateTableModel, FilterableTreeTableModel, LuceneFilterableTableModel

public class FilterableTableModel
extends DefaultTableModelWrapper
implements IFilterableTableModel

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.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.jidesoft.grid.IFilterableTableModel
IFilterableTableModel.FilterItem
 
Nested classes/interfaces inherited from interface com.jidesoft.grid.AutoFilterTableHeaderAdapter
AutoFilterTableHeaderAdapter.FilterTitleFormatter
 
Field Summary
protected  List<Filter> _allColumnFilters
           
protected  List<Filter> _anyColumnFilters
           
protected  boolean[] _columnIncluded
           
protected  List<Filter>[] _eachColumnFilters
           
protected  FilterItemSupport _filterItemSupport
           
protected  ValueProvider _valueProvider
           
static int FILTER_ALGORITHM_BY_FILTER
          This is one of the filter algorithms.
static int FILTER_ALGORITHM_BY_ROW
          This is one of the filter algorithms.
 
Fields inherited from class com.jidesoft.grid.DefaultTableModelWrapper
_indexes
 
Fields inherited from class com.jidesoft.grid.TableModelWrapperImpl
_model
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Fields inherited from interface com.jidesoft.grid.IFilterableTableModel
ALL_COLUMNS, ANY_COLUMNS, IDENTIFIER_ALL_COLUMNS, IDENTIFIER_ANY_COLUMNS
 
Fields inherited from interface com.jidesoft.grid.MultiTableModel
FOOTER_COLUMN, HEADER_COLUMN, REGULAR_COLUMN
 
Fields inherited from interface com.jidesoft.grid.EditorStyleTableModel
EDITOR_STYLE_EDITABLE, EDITOR_STYLE_NORMAL, EDITOR_STYLE_READ_ONLY, EDITOR_STYLE_SELECT_ONLY
 
Constructor Summary
FilterableTableModel(TableModel model)
          Creates a FilterableTableModel from any table model.
 
Method Summary
 void addDynamicTableFilter(int modelIndex, DynamicTableFilter filter)
          Add a DynamicTableFilter.
 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.
 void addFilterableTableModelListener(FilterableTableModelListener l)
          Adds a listener to the list that's notified each time a change to the filter occurs.
 void clearFilters()
          Removes all filters from all columns.
protected static int[] deleteIndexes(int[] indexes, int firstRowActual, int lastRowActual, int firstRowVisual, int lastRowVisual)
          Delete a continuous set of rows
protected  void filter(boolean filterAllData)
          Applies filters and generates a new array of indices.
 void fireFilterAdded(int column, Filter filter)
           
 void fireFilterChanged(FilterableTableModelEvent e)
          Forwards the given notification event to all FilterableTableModelListeners that registered themselves as listeners for this table model.
 void fireFilterRemoved(int column, Filter filter)
           
protected  void fireIndexChanged(int eventSerialNumber)
          Tells the TableModeWrapper that indexes is changed.
protected  int fireIndexChanging()
          Tells the TableModeWrapper that indexes is going to be changed.
 DynamicTableFilter[] getDynamicTableFilters(int modelIndex)
          Gets all the DynamicTableFilters.
 FilterableTableModelListener[] getFilterableTableModelListeners()
          Returns an array of all the FilterableTableModel listeners registered on this filter.
 int getFilterAlgorithm()
          Get current filter algorithm.
 Icon getFilterIcon(int column)
          Gets the filter icon for a particular column.
 List<IFilterableTableModel.FilterItem> getFilterItems()
          Gets all the FilterItems added to this FilterableTableModel.
 Filter[] getFilters(int column)
          Gets the filters for the specified column.
 AutoFilterTableHeaderAdapter.FilterTitleFormatter getFilterTitleFormatter(int column)
          Gets the formatter that will format the title for the AutoFilterTableHeader.
 ListCellRenderer getListCellRenderer(int column)
          Gets the list cell renderer for the drop down filter list.
protected static int getNearestRow(int[] indexes, int indexActual, boolean exists)
           
 JMenuItem[] getPopupMenuItems(int column)
          Gets a list of menu items for the specified column.
 Object[] getPossibleValues(int columnIndex, Comparator comparator)
          Gets all possible values of the table model.
 Object[] getPossibleValuesAndConverters(int columnIndex, Comparator comparator)
           
protected  List<Integer> getReservedRows(int firstRow, int lastRow)
          Get reserved rows after applying filters on rows from firstRow to lastRow.
 StringConverter getTitleConverter(int column)
          Gets the title converter to convert the column name.
 boolean hasFilter()
          Checks if the FilterableTableModel has any filters.
 boolean hasFilter(int columnIndex)
          Checks if the FilterableTableModel has any filters on the specified column.
protected static int[] insertIndexes(int[] indices, int rowCount, int firstRow, int lastRow, boolean exists)
          Insert a continuous set of rows View Actual 0 0 1 10 2 20 3 30 4 40 5 50 Pick view row 3 Insert into Base Model @ row 30 Add +1 to all rows >= 30
protected  void invalidateFilterCache()
           
 boolean isAdjusting()
          Checks if the FilterableTableModel is adjusting.
 boolean isAllowCustomFilter(int column)
          Checks if the AutoFilterTableHeader allows custom filter.
 boolean isAllowMultipleValues(int column)
          Checks if the AutoFilterTableHeader allows multiple values as the filter for the column index.
 boolean isAndMode()
          Sets the logic of filters on the same column.
 boolean isClearFiltersOnStructureChanged()
          Gets the flag indicating that if the existing filter should be cleared if table structure changed event is received.
 boolean isColumnAutoFilterable(int column)
          Checks if the column is auto-filterable.
 boolean isColumnFilterable(int column)
          Checks if the column is filterable for the filters that are added to IFilterableTableModel.ALL_COLUMNS.
 boolean isColumnVisible(int column)
          Checks if the column is visible.
 boolean isFilteringPaused()
          Checks if the filtering is paused.
 boolean isFiltersApplied()
          Checks if the filters are in effect.
protected  boolean isNeedFilterAllData()
          Get the flag if we need filter all datum in the table while applying new filter comparing to the old filter.
 boolean isSameConverterAt(int columnIndex)
          Check if each converter in this column for each row is the same.
 boolean isUseTableCellRenderer(int column)
          Checks if the table cell renderer will be used for the list.
 boolean isValuePredetermined(int column)
          Checks if the column is type-filterable.
protected  void prepareFilters()
          Prepares the filters.
 void refresh()
          Reapply all filters after they are changed.
 void removeAllFilters()
          Removes all filters that are added using addFilter(Filter).
 void removeAllFilters(int column)
          Removes all filters from the specified column.
 void removeDynamicTableFilter(int modelIndex, DynamicTableFilter filter)
          Removes a DynamicTableFilter which was added earlier.
 void removeFilter(Filter filter)
          Removes the filter from all columns.
 void removeFilter(IFilterableTableModel.FilterItem filterItem)
          Removes the filter item.
 void removeFilter(int column, Filter filter)
          Removes the filter from the specified column.
 void removeFilterableTableModelListener(FilterableTableModelListener l)
          Removes a listener from the list that's notified each time a change to the filter occurs.
 int retrieveFilterApplyRecords()
          Deprecated. not an accurate data from customer point of view. Please use FilterableTableModel#getActualModel()#getRowCount() instead.
 void setAdjusting(boolean adjusting)
          Sets the FilterableTableModel to adjusting mode.
 void setAndMode(boolean andMode)
          Sets the logic among the filters.
 void setClearFiltersOnStructureChanged(boolean clearFiltersOnStructureChanged)
          Sets the flag indicating that if the existing filter should be cleared if table structure changed event is received.
 void setFilterAlgorithm(int filterAlgorithm)
          Sets the filter algorithm.
 void setFilteringPaused(boolean pause)
          If filtering is paused, keep rows in same relative positions Inserts/Deletes shift rows without re-ordering
 void setFiltersApplied(boolean apply)
          Applies or unapplies the filters.
protected  void setNeedFilterAllData(boolean needFilterAllData)
          Set the flag if we need filter all datum in the table while applying new filter comparing to the old filter.
protected  boolean shouldBeFiltered(int rowIndex)
          Checks if the row should be filtered.
protected  boolean shouldBeFiltered(int row, List<Filter> allColumnFilters, List<Filter> anyColumnFilters, List<Filter>[] eachColumnFilters)
          The method contains the algorithm to filter the specified row.
protected  boolean shouldBeFiltered(ValueProvider valueProvider, int rowIndex)
          Checks if the row should be filtered.
protected  boolean shouldBeFiltered(ValueProvider valueProvider, int row, List<Filter> allColumnFilters, List<Filter> anyColumnFilters, List<Filter>[] eachColumnFilters)
          The method contains the algorithm to filter the specified row.
protected  boolean shouldBeIgnored(ValueProvider valueProvider, int rowIndex)
          The method is for you to override if you want certain rows to be ignored the filtering process.
protected  boolean shouldBeKept(ValueProvider valueProvider, int rowIndex, List<Integer> remainingRows)
          The method is for you to decide if the rowIndex should be kept based on the rows remained in the remainingRows.
protected  List<Integer> shouldNotBeFiltered(ValueProvider valueProvider, List<Integer> filteringRowList, Filter filter, int filteringColumn)
          The method contains the algorithm to filter the specified row list with specified filter.
protected  boolean shouldOptimize(int firstRow, int lastRow)
          Should we optimize the filtering by doing incremental filtering.
protected  boolean shouldPossibleValueBeIncluded(Object value, int columnIndex)
          Checks if a value should be included in the possible value array.
protected  void tableCellsUpdated(int column, int firstRow, int lastRow)
          Called each time the cells in column in the range [firstRow, lastRow] are updated.
protected  void tableDataChanged()
          Called each time all of the data (i.e.
protected  void tableDataChanged(CompoundTableModelEvent event)
          Called if it receives a table data changed event however the event is an instance of CompoundTableModelEvent.
protected  void tableRowsDeleted(int firstRow, int lastRow)
          Called each time one or more contiguous rows are deleted from the underlying TableModel.
protected  void tableRowsInserted(int firstRow, int lastRow)
          Called each time one or more contiguous rows are inserted into the underlying TableModel.
protected  void tableRowsUpdated(int firstRow, int lastRow)
          Called each time one or more contiguous rows are updated in the underlying TableModel.
protected  void tableStructureChanged()
          Called each time the structure (TableColumns, etc) of the underlying TableModel changes.
 
Methods inherited from class com.jidesoft.grid.DefaultTableModelWrapper
getActualRowAt, getCellClassAt, getCellSpanAt, getConverterContextAt, getEditorContextAt, getEditorStyleAt, getIndexes, getRowCount, getValueAt, getVisualRowAt, isCacheEnabled, isCellEditable, isRowCountChanged, reallocateIndexes, setCacheEnabled, setIndexes, setValueAt
 
Methods inherited from class com.jidesoft.grid.TableModelWrapperImpl
addIndexChangeListener, createCompoundTableModelEvent, fireTableCellsUpdated, fireTableChanged, getActualModel, getCellStyleAt, getColumnClass, getColumnCount, getColumnIdentifier, getColumnName, getColumnType, getIndexChangeListeners, getTableIndex, isCellSpanOn, isCellStyleOn, isNavigableAt, isNavigationOn, removeIndexChangeListener, tableChanged
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.swing.table.TableModel
addTableModelListener, getColumnClass, getColumnCount, getColumnName, getRowCount, getValueAt, isCellEditable, removeTableModelListener, setValueAt
 
Methods inherited from interface com.jidesoft.grid.TableModelWrapper
getActualModel
 

Field Detail

_filterItemSupport

protected FilterItemSupport _filterItemSupport

_valueProvider

protected ValueProvider _valueProvider

_allColumnFilters

protected transient List<Filter> _allColumnFilters

_anyColumnFilters

protected transient List<Filter> _anyColumnFilters

_eachColumnFilters

protected transient List<Filter>[] _eachColumnFilters

_columnIncluded

protected transient boolean[] _columnIncluded

FILTER_ALGORITHM_BY_ROW

public static final int FILTER_ALGORITHM_BY_ROW
This is one of the filter algorithms. This algorithm will loop through rows one by one through all the filters and determine if the row should be filtered away. This is the default filtering algorithm for a regular TableModel.

See Also:
shouldBeFiltered(int), shouldBeFiltered(ValueProvider, int), shouldBeFiltered(int, java.util.List, java.util.List, java.util.List[]), shouldBeFiltered(ValueProvider, int, java.util.List, java.util.List, java.util.List[]), Constant Field Values

FILTER_ALGORITHM_BY_FILTER

public static final int FILTER_ALGORITHM_BY_FILTER
This is one of the filter algorithms. This algorithm will loop through all the filters one by one on all the rows and determine if the row should be filtered. You are encouraged to use this algorithm if you want to control the filter more tightly, in this algorithm we provide three API to control the behavior of the filter in different stage.

This is the default filtering algorithm for a TreeModel in order to keep the parent/children logic correctly.

See Also:
shrinkRowsBeforeFilter(ValueProvider, java.util.List), shouldBeIgnored(ValueProvider, int), shouldBeKept(ValueProvider, int, java.util.List), Constant Field Values
Constructor Detail

FilterableTableModel

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

Parameters:
model - the table model that has the data before filtering.
Method Detail

tableDataChanged

protected void tableDataChanged(CompoundTableModelEvent event)
Description copied from class: TableModelWrapperImpl
Called if it receives a table data changed event however the event is an instance of CompoundTableModelEvent.

Overrides:
tableDataChanged in class DefaultTableModelWrapper
Parameters:
event - the received CompoundTableModelEvent

tableDataChanged

protected void tableDataChanged()
Description copied from class: DefaultTableModelWrapper
Called each time all of the data (i.e. all rows) is changed in the underlyingTableModel. This default implementation simply fires a corresponding TableModelEvent to the listeners on this model.

Overrides:
tableDataChanged in class DefaultTableModelWrapper

tableStructureChanged

protected void tableStructureChanged()
Description copied from class: DefaultTableModelWrapper
Called each time the structure (TableColumns, etc) of the underlying TableModel changes. This default implementation simply fires a corresponding TableModelEvent to the listeners on this model.

Overrides:
tableStructureChanged in class DefaultTableModelWrapper

getNearestRow

protected static int getNearestRow(int[] indexes,
                                   int indexActual,
                                   boolean exists)

insertIndexes

protected static int[] insertIndexes(int[] indices,
                                     int rowCount,
                                     int firstRow,
                                     int lastRow,
                                     boolean exists)
Insert a continuous set of rows View Actual 0 0 1 10 2 20 3 30 4 40 5 50 Pick view row 3 Insert into Base Model @ row 30 Add +1 to all rows >= 30

Parameters:
indices - the indices
rowCount - the row count
firstRow - the first row
lastRow - the last row.
exists - true means the inserted rows exist in the VIEW index (so, find exact nearest row); false means the inserted rows may not exist, so find the first row greater than firstRow
Returns:
indexes containing newly-inserted rows

deleteIndexes

protected static int[] deleteIndexes(int[] indexes,
                                     int firstRowActual,
                                     int lastRowActual,
                                     int firstRowVisual,
                                     int lastRowVisual)
Delete a continuous set of rows

Parameters:
indexes - Array of indexes
firstRowActual - Actual Index of First Row
lastRowActual - Actual Index of Last Row
firstRowVisual - Visual Index of First Row
lastRowVisual - Visual Index of Last Row
Returns:
indexes containing newly-inserted rows

tableRowsInserted

protected void tableRowsInserted(int firstRow,
                                 int lastRow)
Description copied from class: DefaultTableModelWrapper
Called each time one or more contiguous rows are inserted into the underlying TableModel. This default implementation simply fires a corresponding TableModelEvent to the listeners on this model.

Overrides:
tableRowsInserted in class DefaultTableModelWrapper
Parameters:
firstRow - the index of the first row that was inserted
lastRow - the index of the last row that was inserted

tableRowsDeleted

protected void tableRowsDeleted(int firstRow,
                                int lastRow)
Description copied from class: DefaultTableModelWrapper
Called each time one or more contiguous rows are deleted from the underlying TableModel. This default implementation simply fires a corresponding TableModelEvent to the listeners on this model.

Overrides:
tableRowsDeleted in class DefaultTableModelWrapper
Parameters:
firstRow - the index of the first row that was deleted
lastRow - the index of the last row that was deleted

tableRowsUpdated

protected void tableRowsUpdated(int firstRow,
                                int lastRow)
Description copied from class: DefaultTableModelWrapper
Called each time one or more contiguous rows are updated in the underlying TableModel. simply fires a corresponding TableModelEvent to the listeners on this model.

Overrides:
tableRowsUpdated in class DefaultTableModelWrapper
Parameters:
firstRow - the index of the first row that was updated
lastRow - the index of the last row that was updated

shouldOptimize

protected boolean shouldOptimize(int firstRow,
                                 int lastRow)
Should we optimize the filtering by doing incremental filtering. By default, this method returns true if the lastRow - firstRow is less than the 1/10 of the total row count.

Parameters:
firstRow - the first row which is updated.
lastRow - the last row which is updated
Returns:
true or false. If it returns false, we will simply call refresh to apply the filter to all the rows. If true, we will look at each other rows and apply filters on those rows. Obviously it is a trade-off. If there are many rows that are updated, it could be faster to filter the whole table instead of adding/removing the remain row indices on fly.

getReservedRows

protected List<Integer> getReservedRows(int firstRow,
                                        int lastRow)
Get reserved rows after applying filters on rows from firstRow to lastRow.

Parameters:
firstRow - the first row
lastRow - the last row
Returns:
reserved row list.

tableCellsUpdated

protected void tableCellsUpdated(int column,
                                 int firstRow,
                                 int lastRow)
Description copied from class: DefaultTableModelWrapper
Called each time the cells in column in the range [firstRow, lastRow] are updated. This default implementation simply fires a corresponding TableModelEvent to the listeners on this model.

Overrides:
tableCellsUpdated in class DefaultTableModelWrapper
Parameters:
column - the index of the column that was updated
firstRow - the index of the first row in the above column that was updated
lastRow - the index of the last row in the above column that was updated

refresh

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

Specified by:
refresh in interface IFilterableTableModel

fireIndexChanged

protected void fireIndexChanged(int eventSerialNumber)
Tells the TableModeWrapper that indexes is changed. It will basically invalidate the cache when cache is enabled.

Overrides:
fireIndexChanged in class DefaultTableModelWrapper
Parameters:
eventSerialNumber - the event serial number

fireIndexChanging

protected int fireIndexChanging()
Tells the TableModeWrapper that indexes is going to be changed. It will basically fire an INDEX_CHANGING_EVENT event.

Overrides:
fireIndexChanging in class DefaultTableModelWrapper
Returns:
the event serial number for this call, to be used in its partner fireIndexChanged

shouldBeFiltered

protected boolean shouldBeFiltered(int rowIndex)
Checks if the row should be filtered. Make sure you call prepareFilters() once before you call this method one or multiple times. For example, you want to check if several rows should be filtered. Here is what you should do.

Please be noted that if getFilterAlgorithm() returns FILTER_ALGORITHM_BY_FILTER, this method will not take effect. So if you want to override this method, please make sure your filter algorithm is FILTER_ALGORITHM_BY_ROW

 prepareFilters();
 for (int row = firstRow; row <= lastRow; row++) {
     boolean filtered = shouldBeFiltered(row);
     if (!filtered) {
         // do something
     }
 }
 

Parameters:
rowIndex - the row index in the table model.
Returns:
true if the row should be filtered away. Otherwise false.

shouldBeFiltered

protected boolean shouldBeFiltered(ValueProvider valueProvider,
                                   int rowIndex)
Checks if the row should be filtered. Different from shouldBeFiltered(int), this one takes a ValueProvider as parameter in case the value of the row is not in the table model. For example, in the case of TreeTableModel, the value could be in the Row object which may or may not be visible.

Please be noted that if getFilterAlgorithm() returns FILTER_ALGORITHM_BY_FILTER, this method will not take effect. So if you want to override this method, please make sure your filter algorithm is FILTER_ALGORITHM_BY_ROW

Parameters:
valueProvider - an interface where we can retrieve value.
rowIndex - the row index
Returns:
true if the row should be filtered away. Otherwise false.

prepareFilters

protected void prepareFilters()
Prepares the filters. You should always call this method once before you call shouldBeFiltered(int) or shouldBeFiltered(ValueProvider, int).


invalidateFilterCache

protected void invalidateFilterCache()

filter

protected void filter(boolean filterAllData)
Applies filters and generates a new array of indices.

Parameters:
filterAllData - the flag that if we have to filter on all data or we could just filter the current data

isColumnVisible

public boolean isColumnVisible(int column)
Checks if the column is visible. Since column visible information is on the JTable, FilterableTableModel has no idea whether a column is visible. So we added this protected method to give user a chance to tell FilterableTableModel whether a column is visible. If it is not visible, it will not be considered when filtering.

Specified by:
isColumnVisible in interface IFilterableTableModel
Parameters:
column - the column index.
Returns:
true if the column is visible. Otherwise false.

isColumnFilterable

public boolean isColumnFilterable(int column)
Checks if the column is filterable for the filters that are added to IFilterableTableModel.ALL_COLUMNS. The column will be excluded if it returns false (same as isColumnVisible(int) in this case. There is also isColumnAutoFilterable(int) which is used for AutoFilterHeader to control if the filter button is visible.

Specified by:
isColumnFilterable in interface IFilterableTableModel
Parameters:
column - the column index.
Returns:
true if the column can be filtered.

isColumnAutoFilterable

public boolean isColumnAutoFilterable(int column)
Checks if the column is auto-filterable. Please note, this is used in AutoFilterHeader. If it returns false, we will not show the filter button on the header for that column.

Specified by:
isColumnAutoFilterable in interface AutoFilterTableHeaderAdapter
Parameters:
column - the column index.
Returns:
true if the column can be filtered.

isValuePredetermined

public boolean isValuePredetermined(int column)
Checks if the column is type-filterable. Please note, this is used in AutoFilterHeader on multi-line mode. If it returns false, we will not show the filter field on the header for that column.

Specified by:
isValuePredetermined in interface AutoFilterTableHeaderAdapter
Parameters:
column - the column index.
Returns:
true if the column can be filtered.

shouldBeFiltered

protected boolean shouldBeFiltered(int row,
                                   List<Filter> allColumnFilters,
                                   List<Filter> anyColumnFilters,
                                   List<Filter>[] eachColumnFilters)
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. In the method, if you need to consider each column filters or all column filters. Use getFilters(int col) to get filter list for a particular column. Use getFilters(ALL_COLUMNS) to get the filter for all columns. 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.

Please be noted that if getFilterAlgorithm() returns FILTER_ALGORITHM_BY_FILTER, this method will not take effect. So if you want to override this method, please make sure your filter algorithm is FILTER_ALGORITHM_BY_ROW

Parameters:
row - the row index
allColumnFilters - The list of filters on ALL_COLUMN
anyColumnFilters - The list of filters on ANY_COLUMN
eachColumnFilters - The array of list of filters on each column
Returns:
true if the row should be filtered. Otherwise, false.

shouldBeFiltered

protected boolean shouldBeFiltered(ValueProvider valueProvider,
                                   int row,
                                   List<Filter> allColumnFilters,
                                   List<Filter> anyColumnFilters,
                                   List<Filter>[] eachColumnFilters)
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. In the method, if you need to consider each column filters or all column filters. Use getFilters(int col) to get filter list for a particular column. Use getFilters(ALL_COLUMNS) to get the filter for all columns. 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.

Please be noted that if getFilterAlgorithm() returns FILTER_ALGORITHM_BY_FILTER, this method will not take effect. So if you want to override this method, please make sure your filter algorithm is FILTER_ALGORITHM_BY_ROW

Parameters:
valueProvider - an interface where we can retrieve value.
row - the row index
allColumnFilters - The list of filters on ALL_COLUMN
anyColumnFilters - The list of filters on ANY_COLUMN
eachColumnFilters - The array of list of filters on each column
Returns:
true if the row should be filtered. Otherwise, false.

shouldBeIgnored

protected boolean shouldBeIgnored(ValueProvider valueProvider,
                                  int rowIndex)
The method is for you to override if you want certain rows to be ignored the filtering process. In some cases, you can also improve the filter performance significantly based on the characteristics of your data. In this implementation, we just return true.

The following sample code is going to make the filter only apply on the nodes which are not leaf nodes.

 TreeTableModel treeTableModel = (TreeTableModel) TableModelWrapperUtils.getActualTableModel(this,
 TreeTableModel.class);
 Row row = valueProvider instanceof RowValueProvider ? ((RowValueProvider) valueProvider).getRow() :
 treeTableModel.getRowAt(TableModelWrapperUtils.getActualRowAt(_model, rowIndex, treeTableModel));
 return row == null || !(row instanceof Expandable) || !((Expandable) row).hasChildren();
 

Please be noted that this method will take effect only if getFilterAlgorithm() returns FILTER_ALGORITHM_BY_FILTER. So if you try to override this method, please make sure your filter algorithm is FILTER_ALGORITHM_BY_FILTER

Parameters:
valueProvider - An interface where we can retrieve value
rowIndex - The row index to be decided
Returns:
True if you do NOT want the row in the filter process. Otherwise false.

shouldNotBeFiltered

protected List<Integer> shouldNotBeFiltered(ValueProvider valueProvider,
                                            List<Integer> filteringRowList,
                                            Filter filter,
                                            int filteringColumn)
The method contains the algorithm to filter the specified row list with specified filter. This method expect to have a filteringRowList as an input then return a subset of the input list by applying the input filter and filteringColumn. Subclass can override this method to do a different way. You should always check for isFiltersApplied(). If it's false, always return the original row list. You should also check if the filter is enabled (filter.isEnabled()). If enabled return false, you should skip the filter and return the original row list.

This method will be called maximum (filter numbers) * (filtering column numbers). If the filters work in AND mode, the returned row list will be the input filteringRowList of next call. If the filters work in OR mode, the input filteringRowList will be the return by shrinkRowsBeforeFilter(ValueProvider, java.util.List).

Please be noted that this method will take effect only if getFilterAlgorithm() returns FILTER_ALGORITHM_BY_FILTER. So if you try to override this method, please make sure your filter algorithm is FILTER_ALGORITHM_BY_FILTER

Parameters:
valueProvider - An interface where we can retrieve value
filteringRowList - The row index list to be checked
filter - Current filter
filteringColumn - Current filtering column, its value could be either a real column index or IFilterableTableModel.ANY_COLUMNS
Returns:
The row index list that should NOT be filtered.

shouldBeKept

protected boolean shouldBeKept(ValueProvider valueProvider,
                               int rowIndex,
                               List<Integer> remainingRows)
The method is for you to decide if the rowIndex should be kept based on the rows remained in the remainingRows. The method is invoked row by row after the filtering process. In this implementation, we just return if the remainingRows contains the rowIndex.

For example, in FilterableTreeTableModel, even the rowIndex is not in the remainingRows, we will still check if one of its ancestors is in the remainingRows when ifKeepAllChildren() flag is true.

Please be noted that the method will take effect only if getFilterAlgorithm() returns FILTER_ALGORITHM_BY_FILTER. So if you try to override this method, please make sure your filter algorithm is FILTER_ALGORITHM_BY_FILTER

Parameters:
valueProvider - An interface where we can retrieve value
rowIndex - The row index to be decided
remainingRows - The rows remained after major filter process
Returns:
True if the rowIndex should be kept given the rows in remainingRows are kept. Otherwise false.

addFilter

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

Specified by:
addFilter in interface IFilterableTableModel
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.

Specified by:
addFilter in interface IFilterableTableModel
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.

Specified by:
addFilter in interface IFilterableTableModel
Parameters:
filter - the filter to be added.

removeFilter

public void 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.

Specified by:
removeFilter in interface IFilterableTableModel
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.

removeFilter

public void 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.

Specified by:
removeFilter in interface IFilterableTableModel
Parameters:
filterItem - the FilterItem to be removed.

removeFilter

public void 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.

Specified by:
removeFilter in interface IFilterableTableModel
Parameters:
filter - the filter to be removed.

removeAllFilters

public void 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.

Specified by:
removeAllFilters in interface IFilterableTableModel
Parameters:
column - the column index where all filters for that column should be 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.

Specified by:
removeAllFilters in interface IFilterableTableModel

clearFilters

public void 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.

Specified by:
clearFilters in interface IFilterableTableModel

getFilters

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

Specified by:
getFilters in interface IFilterableTableModel
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.

Specified by:
getFilterItems in interface IFilterableTableModel
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.

Specified by:
setFiltersApplied in interface IFilterableTableModel
Parameters:
apply - true to apply the filters.

isFiltersApplied

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

Specified by:
isFiltersApplied in interface IFilterableTableModel
Returns:
true if filters are in effect.

hasFilter

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

Specified by:
hasFilter in interface IFilterableTableModel
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.

Specified by:
hasFilter in interface IFilterableTableModel
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.

getPopupMenuItems

public JMenuItem[] getPopupMenuItems(int column)
Gets a list of menu items for the specified column. It will return an empty array if there is no filters added to that column. If there are filters on that column, it will return several menu items which can enable each filter or disable all of them.

Parameters:
column - the column
Returns:
the list of menu items

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.

Specified by:
isAndMode in interface IFilterableTableModel
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 FilterableTableModel. 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.

Specified by:
setAndMode in interface IFilterableTableModel
Parameters:
andMode - true or false.

getFilterAlgorithm

public int getFilterAlgorithm()
Get current filter algorithm.

Returns:
current filter algorithm.
See Also:
setFilterAlgorithm(int)

setFilterAlgorithm

public void setFilterAlgorithm(int filterAlgorithm)
Sets the filter algorithm. Normally you don't have to invoke this method explicitly. It is automatically set to FILTER_ALGORITHM_BY_ROW by default for performance consideration. In FilterableTreeTableModel, it is automatically set to FILTER_ALGORITHM_BY_FILTER.

Parameters:
filterAlgorithm - the filter algorithm

isAdjusting

public boolean isAdjusting()
Checks if the FilterableTableModel is adjusting. If it is adjusting, FilterableTableModel will not apply filter when the actual list model changes.

Specified by:
isAdjusting in interface IFilterableTableModel
Returns:
true if adjusting. Otherwise false.

setAdjusting

public void setAdjusting(boolean adjusting)
Sets the FilterableTableModel to adjusting mode. If it is adjusting, FilterableTableModel will not apply filter when the actual table model changes. After you set adjusting to false, FilterableListModel will re-apply the filter.

Specified by:
setAdjusting in interface IFilterableTableModel
Parameters:
adjusting - true or false.

shouldPossibleValueBeIncluded

protected boolean shouldPossibleValueBeIncluded(Object value,
                                                int columnIndex)
Checks if a value should be included in the possible value array.

Parameters:
value - the value in the table model.
columnIndex - the column index where the value is from.
Returns:
true or false. True to include the value, false to exclude.
See Also:
getPossibleValues(int, java.util.Comparator)

getPossibleValues

public Object[] getPossibleValues(int columnIndex,
                                  Comparator comparator)
Gets all possible values of the table model. If there is filter on this column, the possible values are collected from the actual table model. If there is no filter on this column, the possible values are collected from this filterable table model. After we collected all the values, we will use Arrays.sort method to sort the values.

You can use shouldPossibleValueBeIncluded(Object, int) method to decide if you want a particular value appears in the possible value array.

The possible values are used by AutoFilterTableHeader to populate the drop down filter list.

Specified by:
getPossibleValues in interface IFilterableTableModel
Parameters:
columnIndex - the column index.
comparator - the comparator. It is used to sort the values.
Returns:
an array of all possible values of certain column in the table model.
See Also:
shouldPossibleValueBeIncluded(Object, int)

getPossibleValuesAndConverters

public Object[] getPossibleValuesAndConverters(int columnIndex,
                                               Comparator comparator)
Specified by:
getPossibleValuesAndConverters in interface IFilterableTableModel

setFilteringPaused

public void setFilteringPaused(boolean pause)
If filtering is paused, keep rows in same relative positions Inserts/Deletes shift rows without re-ordering

Specified by:
setFilteringPaused in interface IFilterableTableModel
Parameters:
pause - TRUE = Filtering is Paused; FALSE = Filtering is Active

isFilteringPaused

public boolean isFilteringPaused()
Checks if the filtering is paused.

Specified by:
isFilteringPaused in interface IFilterableTableModel
Returns:
true if paused. Otherwise false.

addFilterableTableModelListener

public void addFilterableTableModelListener(FilterableTableModelListener l)
Adds a listener to the list that's notified each time a change to the filter occurs.

Specified by:
addFilterableTableModelListener in interface IFilterableTableModel
Parameters:
l - the FilterableTableModelListener

removeFilterableTableModelListener

public void removeFilterableTableModelListener(FilterableTableModelListener l)
Removes a listener from the list that's notified each time a change to the filter occurs.

Specified by:
removeFilterableTableModelListener in interface IFilterableTableModel
Parameters:
l - the FilterableTableModelListener

getFilterableTableModelListeners

public FilterableTableModelListener[] getFilterableTableModelListeners()
Returns an array of all the FilterableTableModel listeners registered on this filter.

Specified by:
getFilterableTableModelListeners in interface IFilterableTableModel
Returns:
all of this filter's FilterableTableModelListeners or an empty array if no filter listeners are currently registered
See Also:
addFilterableTableModelListener(com.jidesoft.grid.FilterableTableModelListener), removeFilterableTableModelListener(com.jidesoft.grid.FilterableTableModelListener)

fireFilterChanged

public void fireFilterChanged(FilterableTableModelEvent e)
Forwards the given notification event to all FilterableTableModelListeners that registered themselves as listeners for this table model.

Parameters:
e - the event to be forwarded
See Also:
addFilterableTableModelListener(com.jidesoft.grid.FilterableTableModelListener), FilterableTableModelEvent, EventListenerList

fireFilterAdded

public void fireFilterAdded(int column,
                            Filter filter)

fireFilterRemoved

public void fireFilterRemoved(int column,
                              Filter filter)

getFilterIcon

public Icon getFilterIcon(int column)
Gets the filter icon for a particular column.

Specified by:
getFilterIcon in interface IFilterableTableModel
Parameters:
column - the column index.
Returns:
the icon.

isNeedFilterAllData

protected boolean isNeedFilterAllData()
Get the flag if we need filter all datum in the table while applying new filter comparing to the old filter.

Normally you don't have to set the flag. If you think it not safety to filter in partial data, you can override this method to just return TRUE so you will always filter on all datum. Of course the performance will be reduced.

Returns:
the flag

setNeedFilterAllData

protected void setNeedFilterAllData(boolean needFilterAllData)
Set the flag if we need filter all datum in the table while applying new filter comparing to the old filter.

Normally you don't have to set the flag. If you think it not safety to filter in partial data, you can override this method to just return TRUE so you will always filter on all datum. Of course the performance will be reduced.

Parameters:
needFilterAllData - the flag

retrieveFilterApplyRecords

@Deprecated
public int retrieveFilterApplyRecords()
Deprecated. not an accurate data from customer point of view. Please use FilterableTableModel#getActualModel()#getRowCount() instead.

Retrieve the number of records last filter apply on.

This is a method for debug purpose and is not supposed to be used in an official release. That's why we didn't use get as its name.

Returns:
the number of records last filter apply on.

isSameConverterAt

public boolean isSameConverterAt(int columnIndex)
Check if each converter in this column for each row is the same. By default, we will return true to improve the performance since it's most likely happened. You could override this method to return false for designated column if needed.

Specified by:
isSameConverterAt in interface IFilterableTableModel
Parameters:
columnIndex - the column index
Returns:
true by default.

addDynamicTableFilter

public void addDynamicTableFilter(int modelIndex,
                                  DynamicTableFilter filter)
Add a DynamicTableFilter.

DynamicTableFilter allows to add your own customize filter to the drop down filter list. Any DynamicTableFilter will become an entry in the list. If user clicks on that entry, the filter will be used to filter the column. What's special about DynamicTableFilter is it allows to to create a filter on fly. For example, in initializeFilter method of DynamicTableFilter, you can pop up a dialog to allow user to select certain information and you return a filter based on user selection. If returning null, no filter will be added. If not null, the filter you just created will be added to the IFilterableTableModel.

Parameters:
modelIndex - the column in the model to add the DynamicTableFilter
filter - a DynamicTableFilter.
Since:
3.1.0

removeDynamicTableFilter

public void removeDynamicTableFilter(int modelIndex,
                                     DynamicTableFilter filter)
Removes a DynamicTableFilter which was added earlier.

Parameters:
modelIndex - the column in the model to remove the DynamicTableFilter
filter - a DynamicTableFilter.
Since:
3.1.0

getDynamicTableFilters

public DynamicTableFilter[] getDynamicTableFilters(int modelIndex)
Gets all the DynamicTableFilters.

Specified by:
getDynamicTableFilters in interface AutoFilterTableHeaderAdapter
Parameters:
modelIndex - the column in the model to add the DynamicTableFilter
Returns:
an array of DynamicTableFilters.
Since:
3.1.0

isAllowMultipleValues

public boolean isAllowMultipleValues(int column)
Description copied from interface: AutoFilterTableHeaderAdapter
Checks if the AutoFilterTableHeader allows multiple values as the filter for the column index. The difference will be to use a CheckBoxList or a regular JList as the popup panel when clicking on the filter button.

Specified by:
isAllowMultipleValues in interface AutoFilterTableHeaderAdapter
Parameters:
column - the column index.
Returns:
true or false.

getTitleConverter

public StringConverter getTitleConverter(int column)
Description copied from interface: AutoFilterTableHeaderAdapter
Gets the title converter to convert the column name. The converter will be used when isShowFilterName() returns true.

Specified by:
getTitleConverter in interface AutoFilterTableHeaderAdapter
Parameters:
column - the column index
Returns:
the title converter. null if no converter is needed.

getFilterTitleFormatter

public AutoFilterTableHeaderAdapter.FilterTitleFormatter getFilterTitleFormatter(int column)
Description copied from interface: AutoFilterTableHeaderAdapter
Gets the formatter that will format the title for the AutoFilterTableHeader. This formatter will be used, when isShowFilterName() returns true, to format the title including column name and filter names.

Specified by:
getFilterTitleFormatter in interface AutoFilterTableHeaderAdapter
Parameters:
column - the column index
Returns:
the title converter. null if no converter is needed.

getListCellRenderer

public ListCellRenderer getListCellRenderer(int column)
Description copied from interface: AutoFilterTableHeaderAdapter
Gets the list cell renderer for the drop down filter list.

Specified by:
getListCellRenderer in interface AutoFilterTableHeaderAdapter
Parameters:
column - the column in the model to add the DynamicTableFilter
Returns:
an array of DynamicTableFilters.

isUseTableCellRenderer

public boolean isUseTableCellRenderer(int column)
Description copied from interface: AutoFilterTableHeaderAdapter
Checks if the table cell renderer will be used for the list.

Specified by:
isUseTableCellRenderer in interface AutoFilterTableHeaderAdapter
Parameters:
column - the column index.
Returns:
true or false.

isAllowCustomFilter

public boolean isAllowCustomFilter(int column)
Description copied from interface: AutoFilterTableHeaderAdapter
Checks if the AutoFilterTableHeader allows custom filter. The difference is there will be a (Custom...) item in the drop down list.when clicking on the filter button. The value is only considered when AutoFilterTableHeader.isAllowMultipleValues() returns false.

Specified by:
isAllowCustomFilter in interface AutoFilterTableHeaderAdapter
Parameters:
column - the column index.
Returns:
true or false.

isClearFiltersOnStructureChanged

public boolean isClearFiltersOnStructureChanged()
Gets the flag indicating that if the existing filter should be cleared if table structure changed event is received.

Returns:
true if filer to be cleared. Otherwise false.
Since:
3.2.2
See Also:
setClearFiltersOnStructureChanged(boolean)

setClearFiltersOnStructureChanged

public void setClearFiltersOnStructureChanged(boolean clearFiltersOnStructureChanged)
Sets the flag indicating that if the existing filter should be cleared if table structure changed event is received.

By default, the flag is false to keep previous behavior. You could set it to true if you don't want the filter to continue taking effective.

Parameters:
clearFiltersOnStructureChanged - the flag
Since:
3.2.2

JIDE 3.5.15