Class FilterRowComboBoxDataProvider<T>

  • Type Parameters:
    T - The type of the objects shown within the NatTable. Needed to access the data columnwise.
    All Implemented Interfaces:
    IComboBoxDataProvider, ILayerListener
    Direct Known Subclasses:
    GlazedListsFilterRowComboBoxDataProvider

    public class FilterRowComboBoxDataProvider<T>
    extends Object
    implements IComboBoxDataProvider, ILayerListener
    IComboBoxDataProvider that provides items for a combobox in the filter row. These items are calculated dynamically based on the content contained in the column it is connected to.

    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 Detail

      • lazyLoading

        protected final boolean lazyLoading
        Flag to indicate whether the combo box content should be loaded lazily.
        Since:
        1.4
      • cachingEnabled

        protected boolean cachingEnabled
        Flag for enabling/disabling caching of filter combo box values.
        Since:
        1.4
    • Constructor Detail

      • 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 - true to configure this FilterRowComboBoxDataProvider should load the combobox values lazily, false to pre-build the value cache.
        Since:
        1.4
    • Method Detail

      • getValues

        public List<?> getValues​(int columnIndex,
                                 int rowIndex)
        Description copied from interface: IComboBoxDataProvider
        Will determine the values for the cell at the specified position. It will return a list with canonical values. The registered IDisplayConverter will handle the conversion to display values when the ComboBoxCellEditor is filled with the selectable items. There is no need to convert within this method.
        Specified by:
        getValues in interface IComboBoxDataProvider
        Parameters:
        columnIndex - The column index of the cell whose ComboBoxCellEditor should be filled.
        rowIndex - The row index of the cell whose ComboBoxCellEditor should be filled.
        Returns:
        List of values that should be used to fill the values of the ComboBoxCellEditor
      • buildValueCache

        protected void buildValueCache()
        Builds the local value cache for all columns.
      • getCachedColumnIndexes

        public Collection<Integer> getCachedColumnIndexes()
        This method returns the column indexes of the columns for which values was cached. Usually it will return all column indexes that are available in the table.
        Returns:
        The column indexes of the columns for which values was cached.
      • collectValues

        protected List<?> collectValues​(int columnIndex)
        Iterates over all rows of the local body IDataProvider and collects the unique values for the given column index.
        Parameters:
        columnIndex - The column index for which the values should be collected
        Returns:
        List of all unique values that are contained in the body IDataProvider for the given column.
      • buildUpdateEvent

        protected FilterRowComboUpdateEvent buildUpdateEvent​(int columnIndex,
                                                             List<?> cacheBefore,
                                                             List<?> cacheAfter)
        Creates a FilterRowComboUpdateEvent for 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 null if nothing has changed.
      • fireCacheUpdateEvent

        protected void fireCacheUpdateEvent​(FilterRowComboUpdateEvent event)
        Fire the given event to all registered listeners.
        Parameters:
        event - The event to handle.
      • addCacheUpdateListener

        public void addCacheUpdateListener​(IFilterRowComboUpdateListener listener)
        Adds the given listener to the list of listeners for value cache updates.
        Parameters:
        listener - The listener to add.
      • removeCacheUpdateListener

        public void removeCacheUpdateListener​(IFilterRowComboUpdateListener listener)
        Removes the given listener from the list of listeners for value cache updates.
        Parameters:
        listener - The listener to remove.
        Since:
        1.6
      • getValueCache

        protected Map<Integer,​List<?>> 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:
        true if caching of filterrow combobox values is enabled, false if 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 - true to enable caching of filter row combobox values, false if 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:
        true if a FilterRowComboUpdateEvent is fired in case of filter value cache updates, false if not.
        Since:
        1.6
      • enableUpdateEvents

        public void enableUpdateEvents()
        Enable firing of FilterRowComboUpdateEvent if 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 of FilterRowComboUpdateEvent if 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