JIDE 3.5.15

com.jidesoft.grid
Class FilterableTreeTableModel<T extends Row>

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
                  extended by com.jidesoft.grid.FilterableTreeTableModel<T>
All Implemented Interfaces:
AutoFilterTableHeaderAdapter, AutoFilterTableModel, ColumnIdentifierTableModel, ContextSensitiveTableModel, EditorStyleTableModel, IFilterableTableModel, IndexChangeEventGenerator, IndexedRowTableModelWrapper, ITreeTableModel<T>, MultiTableModel, NavigableModel, RowTableModelWrapper, SpanModel, StyleModel, TableModelWrapper, Serializable, EventListener, TableModelListener, TableModel

public class FilterableTreeTableModel<T extends Row>
extends FilterableTableModel
implements ITreeTableModel<T>

A filterable TreeTableModel used by TreeTable. This is a subclass of FilterableTableModel.

Comparing to plain FilterableTableModel, FilterableTreeTableModel has only one default settings changed. In plain FilterableTableModel, FilterableTableModel.getFilterAlgorithm() by default returns FilterableTableModel.FILTER_ALGORITHM_BY_ROW, which means that the filtering is performed row by row. In FilterableTreeTableModel, FilterableTableModel.getFilterAlgorithm() by default returns FilterableTableModel.FILTER_ALGORITHM_BY_FILTER, which means that it will consider the relationship between rows on performing filter. If you want to change the filter algorithm of filtering, it requires you override shouldNotBeFiltered(ValueProvider, java.util.List, com.jidesoft.filter.Filter, int) instead of shouldBeFiltered(ValueProvider, int, java.util.List, java.util.List, java.util.List[]) in FilterableTableModel.

FilterableTreeTableModel adds two options, isKeepAllChildren() and isKeepParentNode(), which makes the behavior a little bit different with plain FilterableTableModel. By default, both options returns true. Please check out the javadoc of those two methods for details.

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
static int POSSIBLE_VALUES_ALL_ROWS
           
static int POSSIBLE_VALUES_COLLAPSED_ROWS
           
static int POSSIBLE_VALUES_FIRST_LEVEL
           
static int POSSIBLE_VALUES_LEAF_LEVEL
           
static int POSSIBLE_VALUES_NON_FIRST_NON_LEAF_LEVEL
           
 
Fields inherited from class com.jidesoft.grid.FilterableTableModel
_allColumnFilters, _anyColumnFilters, _columnIncluded, _eachColumnFilters, _filterItemSupport, _valueProvider, FILTER_ALGORITHM_BY_FILTER, FILTER_ALGORITHM_BY_ROW
 
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
FilterableTreeTableModel(TableModel model)
           
 
Method Summary
protected  void filter(boolean filterAllData)
          Applies filters and generates a new array of indices.
protected  boolean filtering(ValueProvider valueProvider, int rowIndex, List<Filter> allColumnFilters, List<Filter> anyColumnFilters, List<Filter>[] eachColumnFilters)
           
 int getDefaultPossibleValuesType()
          Gets the default possible values retrieval option.
 Object[] getPossibleValues(int columnIndex, Comparator comparator)
          Gets all possible values of the table model.
 int getPossibleValuesType(int column)
          Gets the sortable option for the specified column.
 Object getRoot()
          Gets the root expandable row which has the original rows as children.
 Row getRowAt(int rowIndex)
          Returns the row at row specified by row.
 int getRowIndex(T row)
          Gets the index of the row.
protected  Object getValueAt(Row row, int column)
          Gets the value at the column in the Row.
protected  void invalidateFilterCache()
           
protected  void invalidateFilterCache(Object parent)
          Deprecated.  
protected  void invalidateFilterCache(Object parent, boolean recursive)
          Deprecated.  
 boolean isKeepAllChildren()
          This is an option to keep all children rows if their parent row is not filtered away.
 boolean isKeepParentNode()
          This is an option to keep the row is one of its children rows is not filtered away.
 void setDefaultPossibleValuesType(int defaultPossibleValuesType)
          Sets the default possible values retrieval option.
 void setKeepAllChildren(boolean keepAllChildren)
          This is an option to keep all children rows if their parent row is not filtered away.
 void setKeepParentNode(boolean keepParentNode)
          This is an option to keep the row is one of its children rows is not filtered away.
 void setPossibleValuesType(int column, int possibleValuesType)
          Sets the possible values retrieval option for the specified column.
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 shouldBeFilteredCached(ValueProvider valueProvider, int rowIndex, List<Filter> allColumnFilters, List<Filter> anyColumnFilters, List<Filter>[] eachColumnFilters)
          This method will store the result of filtering in cache.
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 shouldRowBeIncluded(int columnIndex, Row row)
          Checks if the row be included into the possible values list.
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 tableRowsUpdated(int firstRow, int lastRow)
          Called each time one or more contiguous rows are updated in the underlying TableModel.
 
Methods inherited from class com.jidesoft.grid.FilterableTableModel
addDynamicTableFilter, addFilter, addFilter, addFilter, addFilterableTableModelListener, clearFilters, deleteIndexes, fireFilterAdded, fireFilterChanged, fireFilterRemoved, fireIndexChanged, fireIndexChanging, getDynamicTableFilters, getFilterableTableModelListeners, getFilterAlgorithm, getFilterIcon, getFilterItems, getFilters, getFilterTitleFormatter, getListCellRenderer, getNearestRow, getPopupMenuItems, getPossibleValuesAndConverters, getReservedRows, getTitleConverter, hasFilter, hasFilter, insertIndexes, isAdjusting, isAllowCustomFilter, isAllowMultipleValues, isAndMode, isClearFiltersOnStructureChanged, isColumnAutoFilterable, isColumnFilterable, isColumnVisible, isFilteringPaused, isFiltersApplied, isNeedFilterAllData, isSameConverterAt, isUseTableCellRenderer, isValuePredetermined, prepareFilters, refresh, removeAllFilters, removeAllFilters, removeDynamicTableFilter, removeFilter, removeFilter, removeFilter, removeFilterableTableModelListener, retrieveFilterApplyRecords, setAdjusting, setAndMode, setClearFiltersOnStructureChanged, setFilterAlgorithm, setFilteringPaused, setFiltersApplied, setNeedFilterAllData, shouldBeFiltered, shouldBeFiltered, shouldBeFiltered, shouldBeIgnored, shouldBeKept, shouldOptimize, shouldPossibleValueBeIncluded, tableDataChanged, tableDataChanged, tableRowsDeleted, tableRowsInserted, tableStructureChanged
 
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

POSSIBLE_VALUES_FIRST_LEVEL

public static final int POSSIBLE_VALUES_FIRST_LEVEL
See Also:
Constant Field Values

POSSIBLE_VALUES_LEAF_LEVEL

public static final int POSSIBLE_VALUES_LEAF_LEVEL
See Also:
Constant Field Values

POSSIBLE_VALUES_NON_FIRST_NON_LEAF_LEVEL

public static final int POSSIBLE_VALUES_NON_FIRST_NON_LEAF_LEVEL
See Also:
Constant Field Values

POSSIBLE_VALUES_COLLAPSED_ROWS

public static final int POSSIBLE_VALUES_COLLAPSED_ROWS
See Also:
Constant Field Values

POSSIBLE_VALUES_ALL_ROWS

public static final int POSSIBLE_VALUES_ALL_ROWS
See Also:
Constant Field Values
Constructor Detail

FilterableTreeTableModel

public FilterableTreeTableModel(TableModel model)
Method Detail

isKeepAllChildren

public boolean isKeepAllChildren()
This is an option to keep all children rows if their parent row is not filtered away. In the other word, if a parent row returns false in the Filter's isValueFiltered method, we will keep all it children even though the children don't satisfy the filter condition.

By default, the value is true to keep all children rows as long as their parent row is kept.

Returns:
true or false.

setKeepAllChildren

public void setKeepAllChildren(boolean keepAllChildren)
This is an option to keep all children rows if their parent row is not filtered away. In the other word, if a parent row returns false in the Filter's isValueFiltered method, we will keep all it children even though the children don't satisfy the filter condition.

Parameters:
keepAllChildren - true or false.

isKeepParentNode

public boolean isKeepParentNode()
This is an option to keep the row is one of its children rows is not filtered away. In TreeTableModel, if you want to keep the children, you have to keep the parent. So this option is true by default. The only case you want to set it to false is you want the parent row has complete control over its children.

Returns:
true or false.

setKeepParentNode

public void setKeepParentNode(boolean keepParentNode)
This is an option to keep the row is one of its children rows is not filtered away. In TreeTableModel, if you want to keep the children, you have to keep the parent. So this option is true by default. The only case you want to set it to false is you want the parent row has complete control over its children.

Parameters:
keepParentNode - true or false.

filter

protected void filter(boolean filterAllData)
Description copied from class: FilterableTableModel
Applies filters and generates a new array of indices.

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

invalidateFilterCache

protected void invalidateFilterCache()
Overrides:
invalidateFilterCache in class FilterableTableModel

invalidateFilterCache

@Deprecated
protected void invalidateFilterCache(Object parent)
Deprecated. 

Invalidates the filter cache for the node.

Parameters:
parent - the parent node

invalidateFilterCache

@Deprecated
protected void invalidateFilterCache(Object parent,
                                                boolean recursive)
Deprecated. 

Invalidates the filter cache for the node.

Parameters:
parent - the parent node
recursive - recursively removal or not

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 FilterableTableModel
Parameters:
firstRow - the index of the first row that was updated
lastRow - the index of the last row that was updated

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

getRowAt

public Row getRowAt(int rowIndex)
Returns the row at row specified by row.

Specified by:
getRowAt in interface ITreeTableModel<T extends Row>
Parameters:
rowIndex - the row whose row is to be queried
Returns:
the row at the specified row index

getRowIndex

public int getRowIndex(T row)
Gets the index of the row.

Specified by:
getRowIndex in interface ITreeTableModel<T extends Row>
Parameters:
row - row
Returns:
the index of the row. If the row is displayed in the table, it will return the index. Otherwise, it will return -1. So -1 could mean two things - the row is not displayed or the row is not in the tree hierarchy at all.

getRoot

public Object getRoot()
Description copied from interface: ITreeTableModel
Gets the root expandable row which has the original rows as children.

Specified by:
getRoot in interface ITreeTableModel<T extends Row>
Returns:
the root expandable row.

shouldNotBeFiltered

protected List<Integer> shouldNotBeFiltered(ValueProvider valueProvider,
                                            List<Integer> filteringRowList,
                                            Filter filter,
                                            int filteringColumn)
Description copied from class: FilterableTableModel
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 FilterableTableModel.shrinkRowsBeforeFilter(ValueProvider, java.util.List).

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

Overrides:
shouldNotBeFiltered in class FilterableTableModel
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.

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, by default, this method is not being invoked. Instead, shouldNotBeFiltered(ValueProvider, java.util.List, com.jidesoft.filter.Filter, int) is the method you may want to override instead.

Overrides:
shouldBeFiltered in class FilterableTableModel
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.

shouldBeFilteredCached

protected boolean shouldBeFilteredCached(ValueProvider valueProvider,
                                         int rowIndex,
                                         List<Filter> allColumnFilters,
                                         List<Filter> anyColumnFilters,
                                         List<Filter>[] eachColumnFilters)
This method will store the result of filtering in cache. This is helpful for the TreeTableModel because sometimes it has to check parents and children to figure out if a row is filtered. So caching it will be helpful to improve the performance.

Parameters:
valueProvider - the ValueProvider
rowIndex - 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 is filtered. Otherwise false.

filtering

protected boolean filtering(ValueProvider valueProvider,
                            int rowIndex,
                            List<Filter> allColumnFilters,
                            List<Filter> anyColumnFilters,
                            List<Filter>[] eachColumnFilters)

shouldRowBeIncluded

protected boolean shouldRowBeIncluded(int columnIndex,
                                      Row row)
Checks if the row be included into the possible values list.

Parameters:
columnIndex - the column index
row - the row
Returns:
true if the row should be included. Otherwise false.

getPossibleValues

public Object[] getPossibleValues(int columnIndex,
                                  Comparator comparator)
Description copied from class: FilterableTableModel
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 FilterableTableModel.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
Overrides:
getPossibleValues in class FilterableTableModel
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:
FilterableTableModel.shouldPossibleValueBeIncluded(Object, int)

getValueAt

protected Object getValueAt(Row row,
                            int column)
Gets the value at the column in the Row.

Parameters:
row - the row instance
column - the column index
Returns:
the value.
Since:
3.3.8

getDefaultPossibleValuesType

public int getDefaultPossibleValuesType()
Gets the default possible values retrieval option.

Returns:
the sortable option.
See Also:
setDefaultPossibleValuesType(int)

setDefaultPossibleValuesType

public void setDefaultPossibleValuesType(int defaultPossibleValuesType)
Sets the default possible values retrieval option. The valid retrieval options are POSSIBLE_VALUES_LEAF_LEVEL, POSSIBLE_VALUES_FIRST_LEVEL, POSSIBLE_VALUES_ALL_ROWS, POSSIBLE_VALUES_COLLAPSED_ROWS.

By default, the default possible values types is ~POSSIBLE_VALUES_COLLAPSED_ROWS to exclude collapsed rows.

Parameters:
defaultPossibleValuesType - retrieval option

getPossibleValuesType

public int getPossibleValuesType(int column)
Gets the sortable option for the specified column.

Parameters:
column - the column index in table model. It's not the visual index but the model index.
Returns:
the sortable option for the specified column.
See Also:
setPossibleValuesType(int, int)

setPossibleValuesType

public void setPossibleValuesType(int column,
                                  int possibleValuesType)
Sets the possible values retrieval option for the specified column.

Please note the option set using this method will be erased when table model's column count changes. So if you know the table model column count changes, you should have code to set the option again.

Parameters:
column - the column index in table model. It's not the visual index but the model index.
possibleValuesType - The valid retrieval options are POSSIBLE_VALUES_LEAF_LEVEL, POSSIBLE_VALUES_FIRST_LEVEL, POSSIBLE_VALUES_ALL_ROWS, POSSIBLE_VALUES_COLLAPSED_ROWS

JIDE 3.5.15