Class GenericFilter

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.Composite<JmixDetails>
io.jmix.flowui.component.genericfilter.GenericFilter
All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.HasTheme, com.vaadin.flow.component.shared.HasTooltip, SupportsResponsiveSteps, HasActions, Serializable, org.springframework.beans.factory.Aware, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware

public class GenericFilter extends com.vaadin.flow.component.Composite<JmixDetails> implements SupportsResponsiveSteps, HasActions, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.HasTheme, com.vaadin.flow.component.shared.HasTooltip, org.springframework.context.ApplicationContextAware, org.springframework.beans.factory.InitializingBean
A versatile tool for filtering the data it is bound to. The component enables quick data filtering by arbitrary conditions, as well as creating configurations for repeated use.
See Also:
  • Field Details

    • CONDITION_REMOVE_BUTTON_ID_SUFFIX

      protected static final String CONDITION_REMOVE_BUTTON_ID_SUFFIX
      See Also:
    • FILTER_CLASS_NAME

      protected static final String FILTER_CLASS_NAME
      See Also:
    • FILTER_CONTENT_WRAPPER_CLASS_NAME

      protected static final String FILTER_CONTENT_WRAPPER_CLASS_NAME
      See Also:
    • FILTER_CONTROLS_LAYOUT_CLASS_NAME

      protected static final String FILTER_CONTROLS_LAYOUT_CLASS_NAME
      See Also:
    • GLOBAL_CONFIGURATION_NAME_POSTFIX

      protected static final String GLOBAL_CONFIGURATION_NAME_POSTFIX
      See Also:
    • applicationContext

      protected org.springframework.context.ApplicationContext applicationContext
    • currentAuthentication

      protected CurrentAuthentication currentAuthentication
    • uiComponents

      protected UiComponents uiComponents
    • actions

      protected Actions actions
    • messages

      protected Messages messages
    • metadata

      protected Metadata metadata
    • dialogWindows

      protected DialogWindows dialogWindows
    • genericFilterSupport

      protected GenericFilterSupport genericFilterSupport
    • groupFilterSupport

      protected GroupFilterSupport groupFilterSupport
    • autoApply

      protected boolean autoApply
    • applyShortcut

      protected String applyShortcut
    • propertyHierarchyDepth

      protected int propertyHierarchyDepth
    • dataLoader

      protected DataLoader dataLoader
    • initialDataLoaderCondition

      protected Condition initialDataLoaderCondition
    • propertyFiltersPredicate

      protected Predicate<MetaPropertyPath> propertyFiltersPredicate
    • contentWrapper

      protected com.vaadin.flow.component.orderedlayout.VerticalLayout contentWrapper
    • controlsLayout

      protected com.vaadin.flow.component.orderedlayout.HorizontalLayout controlsLayout
    • applyButton

      protected ComboButton applyButton
    • addConditionButton

      protected JmixButton addConditionButton
    • settingsButton

      protected DropdownButton settingsButton
    • responsiveSteps

      protected List<SupportsResponsiveSteps.ResponsiveStep> responsiveSteps
    • openedChangeRegistration

      protected com.vaadin.flow.shared.Registration openedChangeRegistration
    • rootLogicalFilterComponent

      protected LogicalFilterComponent<?> rootLogicalFilterComponent
    • emptyConfiguration

      protected Configuration emptyConfiguration
    • currentConfiguration

      protected Configuration currentConfiguration
    • configurations

      protected List<Configuration> configurations
    • conditions

      protected List<FilterComponent> conditions
    • configurationModifyPermitted

      protected boolean configurationModifyPermitted
  • Constructor Details

    • GenericFilter

      public GenericFilter()
  • Method Details

    • setApplicationContext

      public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
      Specified by:
      setApplicationContext in interface org.springframework.context.ApplicationContextAware
    • afterPropertiesSet

      public void afterPropertiesSet()
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
    • autowireDependencies

      protected void autowireDependencies()
    • initComponent

      protected void initComponent()
    • initDefaultResponsiveSteps

      protected void initDefaultResponsiveSteps()
    • initEmptyConfiguration

      protected void initEmptyConfiguration()
    • createConfigurationRootLogicalFilterComponent

      protected LogicalFilterComponent<?> createConfigurationRootLogicalFilterComponent(LogicalFilterComponent.Operation rootOperation)
    • initContent

      protected JmixDetails initContent()
      Overrides:
      initContent in class com.vaadin.flow.component.Composite<JmixDetails>
    • initLayout

      protected void initLayout()
    • createContentWrapper

      protected com.vaadin.flow.component.orderedlayout.VerticalLayout createContentWrapper()
    • initContentWrapper

      protected void initContentWrapper(com.vaadin.flow.component.orderedlayout.VerticalLayout contentWrapper)
    • createControlsLayout

      protected com.vaadin.flow.component.orderedlayout.HorizontalLayout createControlsLayout()
    • initControlsLayout

      protected void initControlsLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout controlsLayout)
    • createAddConditionButton

      protected JmixButton createAddConditionButton()
    • initAddConditionButton

      protected void initAddConditionButton(JmixButton addConditionButton)
    • createApplyButton

      protected ComboButton createApplyButton()
    • initApplyButton

      protected void initApplyButton(ComboButton applyButton)
    • initSelectConfigurationDropdown

      protected void initSelectConfigurationDropdown()
    • updateApplyButtonText

      protected void updateApplyButtonText(boolean autoApply)
    • onApplyButtonClick

      protected void onApplyButtonClick(com.vaadin.flow.component.ClickEvent<com.vaadin.flow.component.contextmenu.MenuItem> clickEvent)
    • createResetFilterAction

      protected Action createResetFilterAction()
    • createSettingsButton

      protected DropdownButton createSettingsButton()
    • initSettingsButton

      protected void initSettingsButton(DropdownButton settingsButton)
    • getControlsLayout

      public com.vaadin.flow.component.HasComponents getControlsLayout()
    • getQueryCondition

      public LogicalCondition getQueryCondition()
      Returns:
      a LogicalCondition related to the configuration
    • getDataLoader

      public DataLoader getDataLoader()
      Returns:
      a DataLoader related to the filter
    • setDataLoader

      public void setDataLoader(DataLoader dataLoader)
      Sets a DataLoader related to the filter.
      Parameters:
      dataLoader - a DataLoader to set
    • updateDataLoaderInitialCondition

      protected void updateDataLoaderInitialCondition(@Nullable Condition condition)
    • isAutoApply

      public boolean isAutoApply()
      Returns:
      true if the filter should be automatically applied to the DataLoader when the value component value is changed
    • setAutoApply

      public void setAutoApply(boolean autoApply)
      Sets whether the filter should be automatically applied to the DataLoader when the value component value is changed.
      Parameters:
      autoApply - true if the filter should be automatically applied to the DataLoader when the value component value is changed
    • getApplyShortcut

      @Nullable public KeyCombination getApplyShortcut()
      Returns:
      KeyCombination that is used to apply the filter
    • setApplyShortcut

      public void setApplyShortcut(@Nullable String applyShortcut)
      Sets a new KeyCombination to apply the filter.
      Parameters:
      applyShortcut - string representation of a KeyCombination
    • updateCurrentConfigurationAutoApply

      protected void updateCurrentConfigurationAutoApply(boolean autoApply)
    • apply

      public void apply()
      Applies the current configuration.
    • setupLoaderFirstResult

      protected void setupLoaderFirstResult()
    • getResponsiveSteps

      public List<SupportsResponsiveSteps.ResponsiveStep> getResponsiveSteps()
      Description copied from interface: SupportsResponsiveSteps
      Get the list of SupportsResponsiveSteps.ResponsiveSteps used to configure this layout.
      Specified by:
      getResponsiveSteps in interface SupportsResponsiveSteps
      Returns:
      the list of SupportsResponsiveSteps.ResponsiveSteps used to configure this layout
      See Also:
    • setResponsiveSteps

      public void setResponsiveSteps(List<SupportsResponsiveSteps.ResponsiveStep> steps)
      Description copied from interface: SupportsResponsiveSteps
      Configure the responsive steps used in this layout.
      Specified by:
      setResponsiveSteps in interface SupportsResponsiveSteps
      Parameters:
      steps - list of SupportsResponsiveSteps.ResponsiveSteps to set
      See Also:
    • getSummaryText

      public String getSummaryText()
      Returns:
      this component summary text
    • setSummaryText

      public void setSummaryText(String summary)
      Sets this component summary text
      Parameters:
      summary - text to set
    • isOpened

      public boolean isOpened()
      Returns:
      whether this component is expanded or collapsed
    • setOpened

      public void setOpened(boolean opened)
      Sets whether this component is expanded or collapsed
      Parameters:
      opened - whether this component is expanded or collapsed
    • addOpenedChangeListener

      public com.vaadin.flow.shared.Registration addOpenedChangeListener(com.vaadin.flow.component.ComponentEventListener<GenericFilter.OpenedChangeEvent> listener)
      Adds a listener for opened-changed events fired by the component.
      Parameters:
      listener - the listener to set
      Returns:
      a Registration for removing the event listener
    • removeOpenedChangeListener

      protected void removeOpenedChangeListener(com.vaadin.flow.shared.Registration registration)
    • onOpenedChanged

      protected void onOpenedChanged(com.vaadin.flow.component.details.Details.OpenedChangeEvent openedChangeEvent)
    • addAction

      public void addAction(Action action, int index)
      Specified by:
      addAction in interface HasActions
    • removeAction

      public void removeAction(Action action)
      Specified by:
      removeAction in interface HasActions
    • removeAction

      public void removeAction(String id)
      Specified by:
      removeAction in interface HasActions
    • removeAllActions

      public void removeAllActions()
      Specified by:
      removeAllActions in interface HasActions
    • getActions

      public Collection<Action> getActions()
      Specified by:
      getActions in interface HasActions
    • getAction

      @Nullable public Action getAction(String id)
      Specified by:
      getAction in interface HasActions
    • getPropertyFiltersPredicate

      @Nullable public Predicate<MetaPropertyPath> getPropertyFiltersPredicate()
      Returns:
      a properties filter predicate
    • setPropertyFiltersPredicate

      public void setPropertyFiltersPredicate(@Nullable Predicate<MetaPropertyPath> propertyFiltersPredicate)
      Sets a predicate that tests whether a property with the given path should be available for filtering.
      Parameters:
      propertyFiltersPredicate - a predicate to set
    • addPropertyFiltersPredicate

      public void addPropertyFiltersPredicate(Predicate<MetaPropertyPath> propertyFiltersPredicate)
      Adds a predicate to the current properties filter predicate. The result predicate is a composed predicate that represents a short-circuiting logical AND of given predicate and current properties filter predicate.
      Parameters:
      propertyFiltersPredicate - a predicate to add
    • getCurrentConfiguration

      public Configuration getCurrentConfiguration()
      Gets the current configuration that is currently displayed inside the filter.
      Returns:
      a current configuration
    • setCurrentConfiguration

      public void setCurrentConfiguration(Configuration currentConfiguration)
      Sets the given configuration as current and displays filter components from the current configuration.
      Parameters:
      currentConfiguration - a configuration
    • setCurrentConfigurationInternal

      protected void setCurrentConfigurationInternal(Configuration currentConfiguration, boolean fromClient)
    • refreshCurrentConfigurationLayout

      protected void refreshCurrentConfigurationLayout()
    • updateRootLogicalFilterComponent

      protected void updateRootLogicalFilterComponent(LogicalFilterComponent<?> logicalFilterComponent)
    • resetFilterComponentDefaultValue

      protected void resetFilterComponentDefaultValue(PropertyFilter<?> propertyFilter)
    • updateSingleConditionRemoveButton

      protected void updateSingleConditionRemoveButton(SingleFilterComponentBase<?> singleFilter)
    • updateGroupConditionButtons

      protected void updateGroupConditionButtons(GroupFilter groupFilter)
    • createConditionRemoveButton

      protected com.vaadin.flow.component.Component createConditionRemoveButton(FilterComponent filterComponent, String removeButtonId)
    • removeFilterComponent

      protected void removeFilterComponent(FilterComponent filterComponent)
    • updateRootLayoutSummaryText

      protected void updateRootLayoutSummaryText()
    • getConfigurationName

      protected String getConfigurationName(Configuration configuration)
    • updateDataLoaderCondition

      protected void updateDataLoaderCondition()
    • getEmptyConfiguration

      public Configuration getEmptyConfiguration()
      Gets an empty configuration that is used when the user has not selected any of the existing configurations.
      Returns:
      an empty configuration
    • getConfiguration

      @Nullable public Configuration getConfiguration(String id)
      Gets a configuration by id.
      Parameters:
      id - the configuration id
      Returns:
      the configuration of null if not found
    • getConfigurations

      public List<Configuration> getConfigurations()
      Returns:
      a list of all configurations related to the filter
    • addConfiguration

      public DesignTimeConfiguration addConfiguration(String id, @Nullable String name)
      Adds design-time configuration with given id and name. A configuration is a set of FilterComponents. The configuration does not store a reference to all components, but stores a reference only to the root element LogicalFilterComponent from which the rest FilterComponents can be obtained. The root LogicalFilterComponent is generated with a LogicalFilterComponent.Operation.AND operation.

      The configuration defined in XML is a DesignTimeConfiguration.

      Parameters:
      id - a configuration id. Must be unique within this filter
      name - a configuration name
      Returns:
      DesignTimeConfiguration
      See Also:
    • addConfiguration

      public DesignTimeConfiguration addConfiguration(String id, @Nullable String name, LogicalFilterComponent.Operation rootOperation)
      Adds design-time configuration with given id and name. A configuration is a set of FilterComponents. The configuration does not store a reference to all components, but stores a reference only to the root element LogicalFilterComponent from which the rest FilterComponents can be obtained. The root LogicalFilterComponent is generated with a given operation.

      The configuration defined in XML is a DesignTimeConfiguration.

      Parameters:
      id - a configuration id. Must be unique within this filter
      name - a configuration name
      rootOperation - an operation of root LogicalFilterComponent
      Returns:
      DesignTimeConfiguration
    • addConfiguration

      public void addConfiguration(Configuration configuration)
      Adds a configuration to the filter.
      Parameters:
      configuration - configuration to add
      See Also:
    • removeConfiguration

      public void removeConfiguration(Configuration configuration)
      Removes a configuration from filter.
      Parameters:
      configuration - configuration to remove
    • updateSelectConfigurationDropdown

      protected void updateSelectConfigurationDropdown()
    • addSelectConfigurationAction

      protected void addSelectConfigurationAction(Configuration configuration)
    • createConfigurationAction

      protected Action createConfigurationAction(Configuration configuration)
    • addCondition

      public void addCondition(FilterComponent filterComponent)
      Adds a condition to the filter. A condition is a FilterComponent that is not initially added to any of the configurations, but the user can select this component in the AddConditionView in the Conditions section and add it to the RunTimeConfiguration.
      Parameters:
      filterComponent - a filter component to add to conditions
      See Also:
    • getConditions

      public List<FilterComponent> getConditions()
      Returns:
      a list of all conditions related to the filter
    • removeCondition

      public void removeCondition(FilterComponent filterComponent)
      Removes a condition from filter.
      Parameters:
      filterComponent - a filter component to remove from conditions
    • addConfigurationChangeListener

      public com.vaadin.flow.shared.Registration addConfigurationChangeListener(com.vaadin.flow.component.ComponentEventListener<GenericFilter.ConfigurationChangeEvent> listener)
    • addConfigurationRefreshListener

      public com.vaadin.flow.shared.Registration addConfigurationRefreshListener(com.vaadin.flow.component.ComponentEventListener<GenericFilter.ConfigurationRefreshEvent> listener)
    • loadConfigurationsAndApplyDefault

      public void loadConfigurationsAndApplyDefault()
    • clearValues

      protected void clearValues()
    • copy

      @Nullable protected Condition copy(@Nullable Condition condition)
    • getPropertyHierarchyDepth

      public int getPropertyHierarchyDepth()
      Returns:
      hierarchy depth of entity properties available for filtering.
      See Also:
    • setPropertyHierarchyDepth

      public void setPropertyHierarchyDepth(int propertyHierarchyDepth)
      Sets hierarchy depth of entity properties available for filtering. This property is used in the 'Add Condition' editor of the filter. For example, if the depth value is 2, then you can select an entity attribute contractor.city.country, if the value is 3, then contractor.city.country.name.
      Parameters:
      propertyHierarchyDepth - hierarchy depth of entity properties available for filtering