Search in sources :

Example 6 with Filter

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

the class UiDataFilterSupport method getFragmentFilterConfigurationModel.

protected FilterConfiguration getFragmentFilterConfigurationModel(Filter.Configuration configuration, ScreenFragment configurationFragment) {
    Filter filter = configuration.getOwner();
    FilterConfiguration configurationModel;
    if (configurationFragment instanceof UiDataFilterConfigurationModelFragment) {
        ScreenData screenData = UiControllerUtils.getScreenData(configurationFragment.getHostController());
        InstanceContainer<FilterConfiguration> configurationDc = screenData.getContainer(CONFIGURATION_CONTAINER_ID);
        configurationModel = configurationDc.getItem();
        if (filter.getId() != null && filter.getFrame() != null && ((UiDataFilterConfigurationModelFragment) configurationFragment).getDefaultForMeFieldVisible()) {
            ScreenSettingsFacet settingsFacet = UiControllerUtils.getFacet(filter.getFrame(), ScreenSettingsFacet.class);
            if (settingsFacet != null) {
                saveFilterSettings(settingsFacet, filter.getId(), configurationModel);
            }
        }
    } else {
        configurationModel = loadFilterConfigurationModel(filter, configuration.getId());
    }
    if (configurationModel == null) {
        configurationModel = createFilterConfigurationModel(configuration);
    }
    return configurationModel;
}
Also used : ScreenSettingsFacet(io.jmix.ui.settings.facet.ScreenSettingsFacet) Filter(io.jmix.ui.component.Filter) FilterConfiguration(io.jmix.uidata.entity.FilterConfiguration) UiDataFilterConfigurationModelFragment(io.jmix.uidata.app.filter.configuration.UiDataFilterConfigurationModelFragment) ScreenData(io.jmix.ui.model.ScreenData)

Example 7 with Filter

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

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

the class FilterAddConditionAction method initDefaultSelectHandler.

protected void initDefaultSelectHandler() {
    selectHandler = selectedConditions -> {
        if (!selectedConditions.isEmpty()) {
            Filter.Configuration currentConfiguration = filter.getCurrentConfiguration();
            boolean dataLoadNeeded = false;
            for (FilterCondition selectedCondition : selectedConditions) {
                FilterConverter converter = filterComponents.getConverterByModelClass(selectedCondition.getClass(), filter);
                FilterCondition parent = selectedCondition.getParent();
                if (parent instanceof HeaderFilterCondition) {
                    selectedCondition.setParent(null);
                }
                FilterComponent filterComponent = converter.convertToComponent(selectedCondition);
                currentConfiguration.getRootLogicalFilterComponent().add(filterComponent);
                currentConfiguration.setFilterComponentModified(filterComponent, true);
                boolean nonNullDefaultValue = setFilterComponentDefaultValue(filterComponent, currentConfiguration);
                if (nonNullDefaultValue) {
                    dataLoadNeeded = true;
                }
            }
            filter.setCurrentConfiguration(currentConfiguration);
            if (dataLoadNeeded) {
                filter.apply();
            }
        }
    };
}
Also used : Filter(io.jmix.ui.component.Filter) FilterCondition(io.jmix.ui.entity.FilterCondition) HeaderFilterCondition(io.jmix.ui.entity.HeaderFilterCondition) LogicalFilterComponent(io.jmix.ui.component.LogicalFilterComponent) FilterComponent(io.jmix.ui.component.FilterComponent) SingleFilterComponent(io.jmix.ui.component.SingleFilterComponent) FilterConverter(io.jmix.ui.component.filter.converter.FilterConverter) HeaderFilterCondition(io.jmix.ui.entity.HeaderFilterCondition)

Example 9 with Filter

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

the class FilterSupport method initFilterConfiguration.

protected Filter.Configuration initFilterConfiguration(String id, String name, Filter.Configuration existedConfiguration, boolean isNewConfiguration, LogicalFilterComponent rootFilterComponent) {
    Filter.Configuration resultConfiguration;
    if (isNewConfiguration) {
        resultConfiguration = new RunTimeConfiguration(id, rootFilterComponent, existedConfiguration.getOwner());
    } else if (!existedConfiguration.getId().equals(id)) {
        Filter owner = existedConfiguration.getOwner();
        resultConfiguration = new RunTimeConfiguration(id, rootFilterComponent, owner);
        owner.removeConfiguration(existedConfiguration);
    } else {
        resultConfiguration = existedConfiguration;
        resultConfiguration.setRootLogicalFilterComponent(rootFilterComponent);
    }
    resultConfiguration.setName(name);
    return resultConfiguration;
}
Also used : Filter(io.jmix.ui.component.Filter) RunTimeConfiguration(io.jmix.ui.component.filter.configuration.RunTimeConfiguration)

Aggregations

Filter (io.jmix.ui.component.Filter)9 LogicalFilterComponent (io.jmix.ui.component.LogicalFilterComponent)5 FilterConverter (io.jmix.ui.component.filter.converter.FilterConverter)5 RunTimeConfiguration (io.jmix.ui.component.filter.configuration.RunTimeConfiguration)3 LogicalFilterCondition (io.jmix.ui.entity.LogicalFilterCondition)3 FilterComponent (io.jmix.ui.component.FilterComponent)2 SingleFilterComponent (io.jmix.ui.component.SingleFilterComponent)2 Screen (io.jmix.ui.screen.Screen)2 FilterConfiguration (io.jmix.uidata.entity.FilterConfiguration)2 MetaClass (io.jmix.core.metamodel.model.MetaClass)1 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)1 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 JpqlFilter (io.jmix.ui.component.JpqlFilter)1 DesignTimeConfiguration (io.jmix.ui.component.filter.configuration.DesignTimeConfiguration)1 FilterCondition (io.jmix.ui.entity.FilterCondition)1 HeaderFilterCondition (io.jmix.ui.entity.HeaderFilterCondition)1 DataLoader (io.jmix.ui.model.DataLoader)1