Search in sources :

Example 6 with LogicalFilterComponent

use of io.jmix.ui.component.LogicalFilterComponent 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 7 with LogicalFilterComponent

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

the class FilterConfigurationConverter method toConfigurationModel.

public FilterConfiguration toConfigurationModel(Filter.Configuration configuration, FilterConfiguration configurationModel) {
    Filter filter = configuration.getOwner();
    String filterComponentId = generateFilterPath(filter);
    configurationModel.setComponentId(filterComponentId);
    LogicalFilterComponent rootLogicalFilterComponent = configuration.getRootLogicalFilterComponent();
    FilterConverter converter = filterComponents.getConverterByComponentClass(rootLogicalFilterComponent.getClass(), configuration.getOwner());
    configurationModel.setRootCondition((GroupFilterCondition) converter.convertToModel(rootLogicalFilterComponent));
    return configurationModel;
}
Also used : Filter(io.jmix.ui.component.Filter) FilterConverter(io.jmix.ui.component.filter.converter.FilterConverter) LogicalFilterComponent(io.jmix.ui.component.LogicalFilterComponent)

Example 8 with LogicalFilterComponent

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

the class FilterEditAction method onEditScreenAfterCommit.

@SuppressWarnings({ "rawtypes", "unchecked" })
protected void onEditScreenAfterCommit(ScreenFragment configurationFormFragment, LogicalFilterCondition filterCondition, FilterConverter converter, boolean isNewConfiguration, Filter.Configuration currentConfiguration, Map<String, Object> valuesMap) {
    LogicalFilterComponent rootFilterComponent = (LogicalFilterComponent) converter.convertToComponent(filterCondition);
    Filter.Configuration resultConfiguration = filterSupport.saveCurrentFilterConfiguration(currentConfiguration, isNewConfiguration, rootFilterComponent, configurationFormFragment);
    filterSupport.refreshConfigurationDefaultValues(resultConfiguration);
    resultConfiguration.setModified(false);
    filterSupport.refreshConfigurationValuesMap(resultConfiguration, valuesMap);
    if (isNewConfiguration || !currentConfiguration.getId().equals(resultConfiguration.getId())) {
        filter.addConfiguration(resultConfiguration);
    }
    filter.setCurrentConfiguration(resultConfiguration);
    if (isNewConfiguration) {
        filter.getEmptyConfiguration().getRootLogicalFilterComponent().removeAll();
    }
    filter.apply();
}
Also used : Filter(io.jmix.ui.component.Filter) LogicalFilterComponent(io.jmix.ui.component.LogicalFilterComponent)

Example 9 with LogicalFilterComponent

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

the class FilterEditAction method execute.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void execute() {
    if (filter.getFrame() == null) {
        throw new IllegalStateException("Filter component is not attached to the Frame");
    }
    Filter.Configuration currentConfiguration = filter.getCurrentConfiguration();
    boolean isNewConfiguration = Objects.equals(currentConfiguration.getId(), filter.getEmptyConfiguration().getId());
    LogicalFilterComponent rootComponent = currentConfiguration.getRootLogicalFilterComponent();
    Class modelClass = filterComponents.getModelClass(rootComponent.getClass());
    FilterConverter converter = filterComponents.getConverterByComponentClass(rootComponent.getClass(), filter);
    Map<String, Object> valuesMap = filterSupport.initConfigurationValuesMap(currentConfiguration);
    LogicalFilterCondition model = (LogicalFilterCondition) converter.convertToModel(rootComponent);
    Screen editScreen = createEditScreen(modelClass, model);
    applyScreenConfigurer(editScreen);
    ScreenFragment screenFragment = filterSupport.createFilterConfigurationFragment(editScreen.getWindow().getFrameOwner(), isNewConfiguration, currentConfiguration);
    Fragment fragment = screenFragment.getFragment();
    fragment.setWidthFull();
    editScreen.getWindow().add(fragment, 0);
    editScreen.getWindow().setCaption(messages.getMessage(FilterEditAction.class, "configurationEdit.caption"));
    if (editScreen instanceof GroupFilterConditionEdit) {
        Component groupConditionBox = editScreen.getWindow().getComponent("groupConditionBox");
        if (groupConditionBox instanceof Component.HasCaption) {
            ((Component.HasCaption) groupConditionBox).setCaption(messages.getMessage(FilterEditAction.class, "configurationEdit.rootGroupCondition"));
        }
    }
    editScreen.addAfterCloseListener(afterCloseEvent -> {
        if (afterCloseEvent.closedWith(StandardOutcome.COMMIT)) {
            LogicalFilterCondition filterCondition = (LogicalFilterCondition) ((FilterConditionEdit) afterCloseEvent.getSource()).getInstanceContainer().getItem();
            onEditScreenAfterCommit(screenFragment, filterCondition, converter, isNewConfiguration, currentConfiguration, valuesMap);
        } else {
            filterSupport.resetConfigurationValuesMap(currentConfiguration, valuesMap);
        }
    });
    editScreen.show();
}
Also used : Screen(io.jmix.ui.screen.Screen) LogicalFilterCondition(io.jmix.ui.entity.LogicalFilterCondition) GroupFilterConditionEdit(io.jmix.ui.app.filter.condition.GroupFilterConditionEdit) FilterConditionEdit(io.jmix.ui.app.filter.condition.FilterConditionEdit) FilterConverter(io.jmix.ui.component.filter.converter.FilterConverter) ScreenFragment(io.jmix.ui.screen.ScreenFragment) Fragment(io.jmix.ui.component.Fragment) GroupFilterConditionEdit(io.jmix.ui.app.filter.condition.GroupFilterConditionEdit) ScreenFragment(io.jmix.ui.screen.ScreenFragment) Filter(io.jmix.ui.component.Filter) LogicalFilterComponent(io.jmix.ui.component.LogicalFilterComponent) Component(io.jmix.ui.component.Component) LogicalFilterComponent(io.jmix.ui.component.LogicalFilterComponent)

Example 10 with LogicalFilterComponent

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

the class ConfigurationConditionBuilder method createFilterConditionsByConfiguration.

protected List<FilterCondition> createFilterConditionsByConfiguration(Filter.Configuration configuration, @Nullable FilterCondition parent, boolean addHeaderCondition) {
    List<FilterCondition> conditions = new ArrayList<>();
    LogicalFilterComponent rootLogicalFilterComponent = configuration.getRootLogicalFilterComponent();
    FilterConverter converter = filterComponents.getConverterByComponentClass(rootLogicalFilterComponent.getClass(), configuration.getOwner());
    LogicalFilterCondition rootGroupCondition = (LogicalFilterCondition) converter.convertToModel(rootLogicalFilterComponent);
    FilterCondition configurationHeaderCondition = null;
    if (addHeaderCondition) {
        configurationHeaderCondition = createHeaderFilterCondition(configuration.getName());
        configurationHeaderCondition.setParent(parent);
        conditions.add(configurationHeaderCondition);
    }
    List<FilterCondition> groupConditions = createFilterConditionsByLogicalFilterCondition(rootGroupCondition, addHeaderCondition ? configurationHeaderCondition : parent, true);
    conditions.addAll(groupConditions);
    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) FilterConverter(io.jmix.ui.component.filter.converter.FilterConverter) LogicalFilterComponent(io.jmix.ui.component.LogicalFilterComponent)

Aggregations

LogicalFilterComponent (io.jmix.ui.component.LogicalFilterComponent)10 FilterConverter (io.jmix.ui.component.filter.converter.FilterConverter)6 Filter (io.jmix.ui.component.Filter)5 FilterComponent (io.jmix.ui.component.FilterComponent)4 SingleFilterComponent (io.jmix.ui.component.SingleFilterComponent)4 LogicalFilterCondition (io.jmix.ui.entity.LogicalFilterCondition)4 RunTimeConfiguration (io.jmix.ui.component.filter.configuration.RunTimeConfiguration)2 FilterCondition (io.jmix.ui.entity.FilterCondition)2 FilterConditionEdit (io.jmix.ui.app.filter.condition.FilterConditionEdit)1 GroupFilterConditionEdit (io.jmix.ui.app.filter.condition.GroupFilterConditionEdit)1 Component (io.jmix.ui.component.Component)1 Fragment (io.jmix.ui.component.Fragment)1 HeaderFilterCondition (io.jmix.ui.entity.HeaderFilterCondition)1 Screen (io.jmix.ui.screen.Screen)1 ScreenFragment (io.jmix.ui.screen.ScreenFragment)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1