JIDE 3.5.15

com.jidesoft.lucene
Class LuceneFilterableTableModel

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.lucene.LuceneFilterableTableModel
All Implemented Interfaces:
AutoFilterTableHeaderAdapter, AutoFilterTableModel, ColumnIdentifierTableModel, ContextSensitiveTableModel, EditorStyleTableModel, IFilterableTableModel, IndexChangeEventGenerator, IndexedRowTableModelWrapper, MultiTableModel, NavigableModel, RowTableModelWrapper, SpanModel, StyleModel, TableModelWrapper, Serializable, EventListener, TableModelListener, TableModel

public class LuceneFilterableTableModel
extends FilterableTableModel

LuceneFilterableTableModel is a table model which wraps another table model, not including tree table model, so that user can apply filters on it, the filter is working on Lucene mode, which means we will use Lucene Jar to create indexing for the entire table data once you pass the table model in as a parameter or it receives table data change event.

Comparing with FilterableTableModel, LuceneFilterableTableModel has higher performance at filtering part and has more text search options based on Lucene syntax. So if you have a large table and you don't expect your customer to refresh the data of the table very frequently, you can consider using LuceneFilterableTableModel instead of FilterableTableModel. However, if you are expecting your customer refresh the data very frequently or you have a lot of columns with Number class, you probably better use FilterableTableModel.

Please be noted that LuceneFilterableTableModel does not support TreeTableModel.

It's not recommended to wrap two LuceneFilterableTableModel in one model wrapper chain. Because it will consumes twice memory than necessary.

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 FilterableTableModel.addFilter(com.jidesoft.filter.Filter). Or you can add filter to a particular column using FilterableTableModel.addFilter(int, com.jidesoft.filter.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
 
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
LuceneFilterableTableModel(TableModel model)
          Creates a LuceneFilterableTableModel from any table model.
 
Method Summary
protected  String convertFilterToLuceneQueryText(int columnIndex, Filter filter)
          Convert Filter to Query text.
protected  void filter(boolean filterAllData)
          Applies filters and generates a new array of indices.
 void fireFilterChanged(FilterableTableModelEvent e)
          Forwards the given notification event to all FilterableTableModelListeners that registered themselves as listeners for this table model.
 int getBooleanQueryMaxClauseCount()
          Get the max clause count configuration for BooleanQuery
 Document getDocument(int rowIndex)
          Get the document for the row.
 int getDocumentCount()
          Get the total number of available documents.
protected  String getFieldNameForColumn(int column)
          Convert the column name in the table to field in Lucene so that Lucene can handle the field better.
protected  Query getLuceneQuery()
          Get the Query instance used for Lucene filter.
 com.jidesoft.lucene.LuceneSupport getLuceneSupport()
           
protected  List<Integer> getReservedRows(int firstRow, int lastRow)
          Get reserved rows after applying filters on rows from firstRow to lastRow.
 boolean isAllowLeadingWildcard()
          Get if allow the customer input leading wildcard
 boolean isRangeQueryInclusive()
          Get if the boundary value should be included in RangeQuery
 void notifyIndexCreated()
          Notify indexing is finished in LuceneSupport so that it is able to do filtering.
 void setAllowLeadingWildcard(boolean allowLeadingWildcard)
          Set if allow the customer input leading wildcard
 void setBooleanQueryMaxClauseCount(int booleanQueryMaxClauseCount)
          Set the max clause count configuration for BooleanQuery
 void setLuceneSupport(com.jidesoft.lucene.LuceneSupport luceneSupport)
           
 void setRangeQueryInclusive(boolean rangeQueryInclusive)
          Set if the boundary value should be included in RangeQuery
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 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.FilterableTableModel
addDynamicTableFilter, addFilter, addFilter, addFilter, addFilterableTableModelListener, clearFilters, deleteIndexes, fireFilterAdded, fireFilterRemoved, fireIndexChanged, fireIndexChanging, getDynamicTableFilters, getFilterableTableModelListeners, getFilterAlgorithm, getFilterIcon, getFilterItems, getFilters, getFilterTitleFormatter, getListCellRenderer, getNearestRow, getPopupMenuItems, getPossibleValues, getPossibleValuesAndConverters, getTitleConverter, hasFilter, hasFilter, insertIndexes, invalidateFilterCache, 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, shouldBeFiltered, shouldBeIgnored, shouldBeKept, shouldNotBeFiltered, shouldOptimize, shouldPossibleValueBeIncluded, tableDataChanged
 
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
 

Constructor Detail

LuceneFilterableTableModel

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

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

getFieldNameForColumn

protected String getFieldNameForColumn(int column)
Convert the column name in the table to field in Lucene so that Lucene can handle the field better.

In default implementation, it will remove all the spaces and turn all letters to lower case. It may causes duplicated field for different column name. In this case, you would need override this method.

Parameters:
column - the column index
Returns:
the field name

getDocument

public Document getDocument(int rowIndex)
Get the document for the row.

This method will be invoked by LuceneSupport so that LuceneSupport have documents to indexing and searching. The document must be row(record) based so that LuceneSupport can return a row index(record number) while searching.

Parameters:
rowIndex - the row index (record number)
Returns:
the document to be indexed.

getDocumentCount

public int getDocumentCount()
Get the total number of available documents.

This method will be invoked by LuceneSupport so that LuceneSupport knows how many documents to be indexed and searched at.

Returns:
the number of the available documents.

notifyIndexCreated

public void notifyIndexCreated()
Notify indexing is finished in LuceneSupport so that it is able to do filtering.

This method will be invoked by LuceneSupport when it finishes indexing. You can put actions like filter() in this method so that it can do the first round lucene searching for you.


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 FilterableTableModel

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 FilterableTableModel

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

getReservedRows

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

Overrides:
getReservedRows in class FilterableTableModel
Parameters:
firstRow - the first row
lastRow - the last row
Returns:
reserved row list.

filter

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

Overrides:
filter in class FilterableTableModel
Parameters:
filterAllData - if this run of filter have to go through all the rows

getLuceneQuery

protected Query getLuceneQuery()
Get the Query instance used for Lucene filter.

Returns:
the Query instance. null if no filer applied.

convertFilterToLuceneQueryText

protected String convertFilterToLuceneQueryText(int columnIndex,
                                                Filter filter)
Convert Filter to Query text.

In AutoFilterTableHeader scenario, we will call this method to convert filter to query, if we can get a valid Query instance, we can gain the performance by using lucene mechanism. Otherwise we will go back to traditional FilterableTableModel.

So far we only converted SingleValueFilter and MultipleValuesFilter in eachColumnFilter to Query instances. You can convert your desired filter to query as you wish. If you think you cannot convert the filter you encounter, you'd better return null. Otherwise, you probably will lose some effect from the lost filter.

Please be notd that you don't have to add bracket in the outer most but you need add bracket inside this filter.

Parameters:
columnIndex - the index of the column the filter is going to apply
filter - the filter
Returns:
null if you think this filter is not able to converted to query text in some cases. "" if you want to ignore the filter. Otherwise return a valid string.

fireFilterChanged

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

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

getLuceneSupport

public com.jidesoft.lucene.LuceneSupport getLuceneSupport()

setLuceneSupport

public void setLuceneSupport(com.jidesoft.lucene.LuceneSupport luceneSupport)

getBooleanQueryMaxClauseCount

public int getBooleanQueryMaxClauseCount()
Get the max clause count configuration for BooleanQuery

Returns:
the value.

setBooleanQueryMaxClauseCount

public void setBooleanQueryMaxClauseCount(int booleanQueryMaxClauseCount)
Set the max clause count configuration for BooleanQuery

Parameters:
booleanQueryMaxClauseCount - the value

isRangeQueryInclusive

public boolean isRangeQueryInclusive()
Get if the boundary value should be included in RangeQuery

Returns:
true if inclusive. Otherwise false.

setRangeQueryInclusive

public void setRangeQueryInclusive(boolean rangeQueryInclusive)
Set if the boundary value should be included in RangeQuery

Parameters:
rangeQueryInclusive - true if inclusive. Otherwise false.

isAllowLeadingWildcard

public boolean isAllowLeadingWildcard()
Get if allow the customer input leading wildcard

Returns:
true if allow. Otherwise false.

setAllowLeadingWildcard

public void setAllowLeadingWildcard(boolean allowLeadingWildcard)
Set if allow the customer input leading wildcard

Parameters:
allowLeadingWildcard - true if allow. Otherwise false.

JIDE 3.5.15