Search in sources :

Example 1 with FilterComponent

use of io.jmix.ui.component.FilterComponent in project jmix by jmix-framework.

the class FilterConfigurationConverter method toConfiguration.

public Filter.Configuration toConfiguration(FilterConfiguration configurationModel, Filter filter) {
    String id = configurationModel.getConfigurationId();
    LogicalFilterCondition rootCondition = configurationModel.getRootCondition();
    FilterConverter converter = filterComponents.getConverterByModelClass(rootCondition.getClass(), filter);
    LogicalFilterComponent logicalFilterComponent = (LogicalFilterComponent) converter.convertToComponent(rootCondition);
    Filter.Configuration configuration = new RunTimeConfiguration(id, logicalFilterComponent, filter);
    configuration.setName(configurationModel.getName());
    for (FilterComponent filterComponent : logicalFilterComponent.getFilterComponents()) {
        if (filterComponent instanceof SingleFilterComponent) {
            configuration.setFilterComponentDefaultValue(((SingleFilterComponent<?>) filterComponent).getParameterName(), ((SingleFilterComponent<?>) filterComponent).getValue());
        }
    }
    return configuration;
}
Also used : Filter(io.jmix.ui.component.Filter) LogicalFilterCondition(io.jmix.ui.entity.LogicalFilterCondition) SingleFilterComponent(io.jmix.ui.component.SingleFilterComponent) LogicalFilterComponent(io.jmix.ui.component.LogicalFilterComponent) FilterComponent(io.jmix.ui.component.FilterComponent) RunTimeConfiguration(io.jmix.ui.component.filter.configuration.RunTimeConfiguration) FilterConverter(io.jmix.ui.component.filter.converter.FilterConverter) LogicalFilterComponent(io.jmix.ui.component.LogicalFilterComponent) SingleFilterComponent(io.jmix.ui.component.SingleFilterComponent)

Example 2 with FilterComponent

use of io.jmix.ui.component.FilterComponent in project jmix by jmix-framework.

the class FilterSupport method initConfigurationValuesMap.

@SuppressWarnings({ "unchecked", "rawtypes" })
public Map<String, Object> initConfigurationValuesMap(Filter.Configuration configuration) {
    Map<String, Object> valuesMap = new HashMap<>();
    LogicalFilterComponent rootLogicalComponent = configuration.getRootLogicalFilterComponent();
    for (FilterComponent filterComponent : rootLogicalComponent.getFilterComponents()) {
        if (filterComponent instanceof SingleFilterComponent) {
            String parameterName = ((SingleFilterComponent<?>) filterComponent).getParameterName();
            valuesMap.put(parameterName, ((SingleFilterComponent<?>) filterComponent).getValue());
            ((SingleFilterComponent) filterComponent).setValue(configuration.getFilterComponentDefaultValue(parameterName));
        }
    }
    return valuesMap;
}
Also used : HashMap(java.util.HashMap) LogicalFilterComponent(io.jmix.ui.component.LogicalFilterComponent) FilterComponent(io.jmix.ui.component.FilterComponent) SingleFilterComponent(io.jmix.ui.component.SingleFilterComponent) LogicalFilterComponent(io.jmix.ui.component.LogicalFilterComponent) SingleFilterComponent(io.jmix.ui.component.SingleFilterComponent)

Example 3 with FilterComponent

use of io.jmix.ui.component.FilterComponent in project jmix by jmix-framework.

the class FilterSupport method refreshConfigurationDefaultValues.

public void refreshConfigurationDefaultValues(Filter.Configuration configuration) {
    configuration.resetAllDefaultValues();
    LogicalFilterComponent rootLogicalComponent = configuration.getRootLogicalFilterComponent();
    for (FilterComponent filterComponent : rootLogicalComponent.getFilterComponents()) {
        if (filterComponent instanceof SingleFilterComponent) {
            configuration.setFilterComponentDefaultValue(((SingleFilterComponent<?>) filterComponent).getParameterName(), ((SingleFilterComponent<?>) filterComponent).getValue());
        }
    }
}
Also used : LogicalFilterComponent(io.jmix.ui.component.LogicalFilterComponent) FilterComponent(io.jmix.ui.component.FilterComponent) SingleFilterComponent(io.jmix.ui.component.SingleFilterComponent) LogicalFilterComponent(io.jmix.ui.component.LogicalFilterComponent) SingleFilterComponent(io.jmix.ui.component.SingleFilterComponent)

Example 4 with FilterComponent

use of io.jmix.ui.component.FilterComponent in project jmix by jmix-framework.

the class FilterSupport method refreshConfigurationValuesMap.

@SuppressWarnings({ "unchecked", "rawtypes" })
public void refreshConfigurationValuesMap(Filter.Configuration configuration, Map<String, Object> valuesMap) {
    LogicalFilterComponent rootLogicalComponent = configuration.getRootLogicalFilterComponent();
    for (FilterComponent filterComponent : rootLogicalComponent.getFilterComponents()) {
        if (filterComponent instanceof SingleFilterComponent) {
            String parameterName = ((SingleFilterComponent<?>) filterComponent).getParameterName();
            Object value = valuesMap.get(parameterName);
            Object defaultValue = configuration.getFilterComponentDefaultValue(parameterName);
            if (value == null && defaultValue != null) {
                ((SingleFilterComponent) filterComponent).setValue(defaultValue);
            } else {
                try {
                    ((SingleFilterComponent) filterComponent).setValue(value);
                } catch (ClassCastException e) {
                    ((SingleFilterComponent) filterComponent).setValue(defaultValue);
                }
            }
        }
    }
}
Also used : LogicalFilterComponent(io.jmix.ui.component.LogicalFilterComponent) FilterComponent(io.jmix.ui.component.FilterComponent) SingleFilterComponent(io.jmix.ui.component.SingleFilterComponent) LogicalFilterComponent(io.jmix.ui.component.LogicalFilterComponent) SingleFilterComponent(io.jmix.ui.component.SingleFilterComponent)

Example 5 with FilterComponent

use of io.jmix.ui.component.FilterComponent in project jmix by jmix-framework.

the class PredefinedConditionBuilder method createFilterConditions.

protected List<FilterCondition> createFilterConditions(Filter filter) {
    List<FilterComponent> components = filter.getConditions();
    List<FilterCondition> conditions = new ArrayList<>();
    HeaderFilterCondition conditionsHeaderCondition = createHeaderFilterCondition(messages.getMessage(PredefinedConditionBuilder.class, "predefinedConditionBuilder.headerCaption"));
    conditions.add(conditionsHeaderCondition);
    for (FilterComponent component : components) {
        FilterConverter converter = filterComponents.getConverterByComponentClass(component.getClass(), filter);
        FilterCondition condition = converter.convertToModel(component);
        condition.setParent(conditionsHeaderCondition);
        conditions.add(condition);
        if (condition instanceof LogicalFilterCondition) {
            List<FilterCondition> children = createFilterConditionsByLogicalFilterCondition((LogicalFilterCondition) condition, condition, true);
            conditions.addAll(children);
        }
    }
    return conditions;
}
Also used : FilterCondition(io.jmix.ui.entity.FilterCondition) LogicalFilterCondition(io.jmix.ui.entity.LogicalFilterCondition) HeaderFilterCondition(io.jmix.ui.entity.HeaderFilterCondition) LogicalFilterCondition(io.jmix.ui.entity.LogicalFilterCondition) ArrayList(java.util.ArrayList) FilterComponent(io.jmix.ui.component.FilterComponent) HeaderFilterCondition(io.jmix.ui.entity.HeaderFilterCondition) FilterConverter(io.jmix.ui.component.filter.converter.FilterConverter)

Aggregations

FilterComponent (io.jmix.ui.component.FilterComponent)8 LogicalFilterComponent (io.jmix.ui.component.LogicalFilterComponent)6 SingleFilterComponent (io.jmix.ui.component.SingleFilterComponent)5 FilterConverter (io.jmix.ui.component.filter.converter.FilterConverter)4 FilterCondition (io.jmix.ui.entity.FilterCondition)3 Filter (io.jmix.ui.component.Filter)2 HeaderFilterCondition (io.jmix.ui.entity.HeaderFilterCondition)2 LogicalFilterCondition (io.jmix.ui.entity.LogicalFilterCondition)2 ArrayList (java.util.ArrayList)2 RunTimeConfiguration (io.jmix.ui.component.filter.configuration.RunTimeConfiguration)1 GroupFilterCondition (io.jmix.ui.entity.GroupFilterCondition)1 HashMap (java.util.HashMap)1 Element (org.dom4j.Element)1