Class FilterRowComboBoxDataProvider<T>
- Type Parameters:
T- The type of the objects shown within the NatTable. Needed to access the data columnwise.
- All Implemented Interfaces:
ILayerCommandHandler<UpdateDataCommand>,IComboBoxDataProvider,ILayerListener
- Direct Known Subclasses:
GlazedListsFilterRowComboBoxDataProvider
On creating this IComboBoxDataProvider, the possible values for all columns will be calculated taking the whole data provided by the body IDataProvider into account. Therefore you shouldn't use this one if you show huge datasets at once.
As the values are cached in here, this IComboBoxDataProvider registers itself as ILayerListener to the body DataLayer. If values are updated or rows get added/deleted, it will update the cache accordingly.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanFlag for enabling/disabling caching of filter combo box values.protected final booleanFlag to indicate whether the combo box content should be loaded lazily. -
Constructor Summary
ConstructorsConstructorDescriptionFilterRowComboBoxDataProvider(ILayer bodyLayer, Collection<T> baseCollection, IColumnAccessor<T> columnAccessor) FilterRowComboBoxDataProvider(ILayer bodyLayer, Collection<T> baseCollection, IColumnAccessor<T> columnAccessor, boolean lazy) -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds the given listener to the list of listeners for value cache updates.protected FilterRowComboUpdateEventbuildUpdateEvent(int columnIndex, List<?> cacheBefore, List<?> cacheAfter) Creates a newFilterRowComboUpdateEventfor the given column index.protected FilterRowComboUpdateEventbuildUpdateEvent(FilterRowComboUpdateEvent event, int columnIndex, List<?> cacheBefore, List<?> cacheAfter) Creates a newFilterRowComboUpdateEventor updates the givenFilterRowComboUpdateEventfor the given column index.protected voidBuilds the local value cache for all columns.protected voidclearCache(boolean updateEventsFromAll) Clear the cache.protected voidclearCache(Map<Integer, List<?>> cache, ReadWriteLock cacheLock, boolean fireUpdateEvents) Clear the cache.protected List<?>collectValues(int columnIndex) Iterates over all rows of the base collection and collects the distinct values for the given column index.protected List<?>collectValues(Collection<T> collection, int columnIndex) Iterates over all rows of the given collection and collects the distinct values for the given column index.protected List<?>collectValuesForColumn(int columnIndex) Collects the distinct values for the given column index.voidconfigureComparator(ILayer columnHeaderDataLayer, IConfigRegistry configRegistry) Set theIConfigRegistrythat should be used to retrieve the comparator to sort the filter collection.voidDisable firing ofFilterRowComboUpdateEventif the filter value cache is updated.voiddispose()Cleanup acquired resources.booleandoCommand(ILayer targetLayer, UpdateDataCommand command) voidEnable firing ofFilterRowComboUpdateEventif the filter value cache is updated.protected voidFire the given event to all registered listeners.List<?>getAllValues(int columnIndex) Returns the collection of all distinct values for the given column.This method returns the column indexes of the columns for which values were cached.protected Comparator<?>getColumnComparator(int columnIndex) Return theComparatorthat should be used to sort the filter collection of the given column.List<?>getValues(int columnIndex, int rowIndex) Will determine the values for the cell at the specified position.protected List<?>getValues(Collection<T> collection, int columnIndex, Map<Integer, List<?>> cache, ReadWriteLock cacheLock) voidhandleLayerEvent(ILayerEvent event) Handle an event notification from anILayerbooleanbooleanprotected booleanisEventFromBodyLayer(ILayerEvent event) Checks if the givenILayerEventwas fired from the body layer.protected booleanSimplified check if a filter is applied by comparing the size of the base collection with the size of the filter collection.protected booleanisFilterChanged(int columnIndex, Object oldValue, Object newValue) Checks if a filter was changed.booleanvoidRemoves the given listener from the list of listeners for value cache updates.voidsetCachingEnabled(boolean cachingEnabled) Enable/disable the caching of filterrow combobox values.voidsetContentFilter(Predicate<T> predicate) voidsetDistinctNullAndEmpty(boolean distinctNullAndEmpty) Setting this value effects on hownulland empty values are handled on collecting the values.voidsetFilterCollection(Collection<T> filterCollection, ILayer columnHeaderLayer) By setting a filter collection it is possible to only show the distinct values for the current available items in the table.protected voidsetLastFilter(int columnIndex, Collection<T> collection) Remember the column and the previous collection state to be able to restore the filter combobox state of the last used combobox filter.protected voidupdateCache(int columnIndex) Update the cache for the given column index.protected voidupdateCache(int columnIndex, Map<Integer, List<?>> cache, ReadWriteLock cacheLock) Update the cache for the given column index.
-
Field Details
-
lazyLoading
protected final boolean lazyLoadingFlag to indicate whether the combo box content should be loaded lazily.- Since:
- 1.4
-
cachingEnabled
protected boolean cachingEnabledFlag for enabling/disabling caching of filter combo box values.- Since:
- 1.4
-
-
Constructor Details
-
FilterRowComboBoxDataProvider
public FilterRowComboBoxDataProvider(ILayer bodyLayer, Collection<T> baseCollection, IColumnAccessor<T> columnAccessor) - Parameters:
bodyLayer- A layer in the body region. Usually the DataLayer or a layer that is responsible for list event handling. Needed to register ourself as listener for data changes.baseCollection- The base collection used to collect the unique values from. This need to be a collection that is not filtered, otherwise after modifications the content of the filter row combo boxes will only contain the current visible (not filtered) elements.columnAccessor- The IColumnAccessor to be able to read the values out of the base collection objects.
-
FilterRowComboBoxDataProvider
public FilterRowComboBoxDataProvider(ILayer bodyLayer, Collection<T> baseCollection, IColumnAccessor<T> columnAccessor, boolean lazy) - Parameters:
bodyLayer- A layer in the body region. Usually the DataLayer or a layer that is responsible for list event handling. Needed to register ourself as listener for data changes.baseCollection- The base collection used to collect the unique values from. This need to be a collection that is not filtered, otherwise after modifications the content of the filter row combo boxes will only contain the current visible (not filtered) elements.columnAccessor- The IColumnAccessor to be able to read the values out of the base collection objects.lazy-trueto configure thisFilterRowComboBoxDataProvidershould load the combobox values lazily,falseto pre-build the value cache.- Since:
- 1.4
-
-
Method Details
-
getValues
Description copied from interface:IComboBoxDataProviderWill determine the values for the cell at the specified position. It will return a list with canonical values. The registeredIDisplayConverterwill handle the conversion to display values when theComboBoxCellEditoris filled with the selectable items. There is no need to convert within this method.- Specified by:
getValuesin interfaceIComboBoxDataProvider- Parameters:
columnIndex- The column index of the cell whoseComboBoxCellEditorshould be filled.rowIndex- The row index of the cell whoseComboBoxCellEditorshould be filled.- Returns:
- List of values that should be used to fill the values of the
ComboBoxCellEditor
-
getAllValues
Returns the collection of all distinct values for the given column. Will use the non-filtered base collection, so it returns always all values, even if they are not visible.- Parameters:
columnIndex- The column index for which the values are requested.- Returns:
- List of all distinct values for the given column.
- Since:
- 2.1
-
getValues
protected List<?> getValues(Collection<T> collection, int columnIndex, Map<Integer, List<?>> cache, ReadWriteLock cacheLock) - Parameters:
collection- The collection out of which the distinct values should be collected.columnIndex- The column index for which the values are requested.- Returns:
- List of all distinct values that are contained in the given collection for the given column.
- Since:
- 2.1
-
buildValueCache
protected void buildValueCache()Builds the local value cache for all columns. -
getCachedColumnIndexes
This method returns the column indexes of the columns for which values were cached. Usually it will return all column indexes that are available in the table.- Returns:
- The column indexes of the columns for which values were cached.
-
collectValues
Iterates over all rows of the base collection and collects the distinct values for the given column index.- Parameters:
columnIndex- The column index for which the values should be collected.- Returns:
- List of all distinct values that are contained in the base collection for the given column.
-
collectValuesForColumn
Collects the distinct values for the given column index. Determines the collection to iterate over based on the information whether a filter list is configured and a filter is applied.- Parameters:
columnIndex- The column index for which the values should be collected.- Returns:
- List of all distinct values that are contained in the determined collection for the given column.
- Since:
- 2.1
-
collectValues
Iterates over all rows of the given collection and collects the distinct values for the given column index.- Parameters:
collection- The collection out of which the distinct values should be collected.columnIndex- The column index for which the values should be collected- Returns:
- List of all distinct values that are contained in the given collection for the given column.
- Since:
- 2.1
-
handleLayerEvent
Description copied from interface:ILayerListenerHandle an event notification from anILayer- Specified by:
handleLayerEventin interfaceILayerListener- Parameters:
event- the event
-
updateCache
protected void updateCache(int columnIndex) Update the cache for the given column index.- Parameters:
columnIndex- The column index for which the cache should be updated.- Since:
- 2.1
-
updateCache
Update the cache for the given column index.- Parameters:
columnIndex- The column index for which the cache should be updated.cache- The cache to update (cache for current values or cache for all values).cacheLock- The lock that matches the given cache.- Since:
- 2.1
-
clearCache
protected void clearCache(boolean updateEventsFromAll) Clear the cache.- Parameters:
updateEventsFromAll-trueif the filter update events should be fired for the all value cache,falseif the events should be fired for the value cache.- Since:
- 2.1
-
clearCache
protected void clearCache(Map<Integer, List<?>> cache, ReadWriteLock cacheLock, boolean fireUpdateEvents) Clear the cache.- Parameters:
cache- The cache to clear (cache for current values or cache for all values).cacheLock- The lock that matches the given cache.fireUpdateEvents-trueifFilterRowComboUpdateEvents should be fired,falseif not.- Since:
- 2.1
-
isEventFromBodyLayer
Checks if the givenILayerEventwas fired from the body layer.- Parameters:
event- The event to check.- Returns:
trueif the event was fired from the body layer,falseif not.- Since:
- 2.1
-
isFilterChanged
Checks if a filter was changed. Also handlesEditConstants.SELECT_ALL_ITEMS_VALUEand a collection of values on testing.- Parameters:
columnIndex- The column index to check.oldValue- The old value.newValue- The new value.- Returns:
trueif a value was changed,falseif not.- Since:
- 2.1
-
buildUpdateEvent
protected FilterRowComboUpdateEvent buildUpdateEvent(int columnIndex, List<?> cacheBefore, List<?> cacheAfter) Creates a newFilterRowComboUpdateEventfor the given column index. Calculates the diffs of the value cache for that column based on the given lists.- Parameters:
columnIndex- The column index for which the value cache was updated.cacheBefore- The value cache for the column before the change. Needed to determine which values where removed by the update.cacheAfter- The value cache for the column after the change. Needed to determine which values where added by the update.- Returns:
- Event to tell about value cache updates for the given column or
nullif nothing has changed.
-
buildUpdateEvent
protected FilterRowComboUpdateEvent buildUpdateEvent(FilterRowComboUpdateEvent event, int columnIndex, List<?> cacheBefore, List<?> cacheAfter) Creates a newFilterRowComboUpdateEventor updates the givenFilterRowComboUpdateEventfor the given column index. Calculates the diffs of the value cache for that column based on the given lists.- Parameters:
event- theFilterRowComboUpdateEventto update, ornullif a new instance should be created.columnIndex- The column index for which the value cache was updated.cacheBefore- The value cache for the column before the change. Needed to determine which values where removed by the update.cacheAfter- The value cache for the column after the change. Needed to determine which values where added by the update.- Returns:
- Event to tell about value cache updates for the given column or
nullif nothing has changed. - Since:
- 2.1
-
fireCacheUpdateEvent
Fire the given event to all registered listeners.- Parameters:
event- The event to handle.
-
addCacheUpdateListener
Adds the given listener to the list of listeners for value cache updates.- Parameters:
listener- The listener to add.
-
removeCacheUpdateListener
Removes the given listener from the list of listeners for value cache updates.- Parameters:
listener- The listener to remove.- Since:
- 1.6
-
getValueCache
- Returns:
- The local cache for the values to show in the filter row combobox. This is needed because otherwise the calculation of the necessary values would happen everytime the combobox is opened and if a filter is applied using GlazedLists for example, the combobox would only contain the value which is currently used for filtering.
-
isCachingEnabled
public boolean isCachingEnabled()- Returns:
trueif caching of filterrow combobox values is enabled,falseif the combobox values should be calculated on request.- Since:
- 1.4
-
setCachingEnabled
public void setCachingEnabled(boolean cachingEnabled) Enable/disable the caching of filterrow combobox values. By default the caching is enabled.You should disable caching if the base collection that is used to determine the filterrow combobox values changes its contents dynamically, e.g. if the base collection is a GlazedLists FilterList that returns only the current non-filtered items.
- Parameters:
cachingEnabled-trueto enable caching of filter row combobox values,falseif the combobox values should be calculated on request.- Since:
- 1.4
-
dispose
public void dispose()Cleanup acquired resources.- Since:
- 1.5
-
isUpdateEventsEnabled
public boolean isUpdateEventsEnabled()- Returns:
trueif aFilterRowComboUpdateEventis fired in case of filter value cache updates,falseif not.- Since:
- 1.6
-
enableUpdateEvents
public void enableUpdateEvents()Enable firing ofFilterRowComboUpdateEventif the filter value cache is updated.By default it should be enabled to automatically update applied filters in case new values are added, otherwise the row containing the new value will be filtered directly.
Note: It is important to disable firing the events in use cases where the cache is not build up yet and the filter is restored from properties, e.g. on opening a table with stored properties.
- Since:
- 1.6
-
disableUpdateEvents
public void disableUpdateEvents()Disable firing ofFilterRowComboUpdateEventif the filter value cache is updated.By default it should be enabled to automatically update applied filters in case new values are added, otherwise the row containing the new value will be filtered directly.
Note: It is important to disable firing the events in use cases where the cache is not build up yet and the filter is restored from properties, e.g. on opening a table with stored properties.
- Since:
- 1.6
-
getValueCacheLock
- Returns:
- The
ReadWriteLockthat should be used for locking on accessing thevalueCache. - Since:
- 1.6
-
isDistinctNullAndEmpty
public boolean isDistinctNullAndEmpty()- Returns:
trueifnulland empty values are distinct to a single "empty" value,falseif they are treated as separate values.- Since:
- 2.1
-
setDistinctNullAndEmpty
public void setDistinctNullAndEmpty(boolean distinctNullAndEmpty) Setting this value effects on hownulland empty values are handled on collecting the values.falsemeansnulland empty are collected as two separate values,truewill distinct them into a single "empty" value.- Parameters:
distinctNullAndEmpty-trueifnulland empty values are distinct to a single "empty" value,falseif they are treated as separate values.- Since:
- 2.1
-
getFilterCollection
- Returns:
- The collection that contains filtered body data. Can be
null. - Since:
- 2.1
-
setFilterCollection
By setting a filter collection it is possible to only show the distinct values for the current available items in the table.- Parameters:
filterCollection- The collection that contains filtered body data. Can benull.columnHeaderLayer- A layer in the column header region in which the filter row is included. Needed to handle theFilterAppliedEvent.- Throws:
IllegalArgumentException- if one of the parameters isnullwhile the other isn't- Since:
- 2.1
-
setLastFilter
Remember the column and the previous collection state to be able to restore the filter combobox state of the last used combobox filter.- Parameters:
columnIndex- The column index of the column that was used for filtering.collection- The previous collection state to be able to restore the combobox contents.- Since:
- 2.1
-
doCommand
- Specified by:
doCommandin interfaceILayerCommandHandler<T>- Parameters:
targetLayer- The targetILayer.command- TheUpdateDataCommandto process.- Returns:
falseas thisILayerCommandHandlerdoes not consume the command, it only modifies the command to avoid incorrect processing.- Since:
- 2.1
-
isFilterApplied
protected boolean isFilterApplied()Simplified check if a filter is applied by comparing the size of the base collection with the size of the filter collection.- Returns:
trueif a filter collection is set and the size is less than the size of the base collection,falseif no filter collection is set or the size is equal.- Since:
- 2.2
-
configureComparator
Set theIConfigRegistrythat should be used to retrieve the comparator to sort the filter collection. If one of the parameters isnullthe filter collection will always be sorted viaComparator.naturalOrder().- Parameters:
columnHeaderDataLayer- The DataLayer of the column header region. Needed to be able to get the cell which is needed to get the comparator that should be used to sort the filter collection.configRegistry- TheIConfigRegistryof the underlying NatTable.- Since:
- 2.3
-
getColumnComparator
Return theComparatorthat should be used to sort the filter collection of the given column.- Parameters:
columnIndex- The column for which theComparatorshould be returned.- Returns:
- The
Comparatorthat should be used to sort the filter collection of the given column. The default isComparator.naturalOrder(). - Since:
- 2.3
-
setContentFilter
- Parameters:
predicate- ThePredicateto define which values should not be added to the filter combobox. Settingnullwill result in no filtering, which is the default.- Since:
- 2.3
-
getCommandClass
- Specified by:
getCommandClassin interfaceILayerCommandHandler<T>- Returns:
- The class that is handled by this
ILayerCommandHandler - Since:
- 2.1
-