Search in sources :

Example 1 with Filter

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

the class RelatedEntitiesSupportImpl method buildScreen.

protected Screen buildScreen(RelatedEntitiesBuilder builder) {
    MetaClass metaClass = getMetaClass(builder);
    MetaProperty metaProperty = getMetaProperty(builder, metaClass);
    Screen screen = createScreen(builder, metaClass, metaProperty);
    boolean found = ComponentsHelper.walkComponents(screen.getWindow(), screenComponent -> {
        if (screenComponent instanceof Filter) {
            Filter filter = (Filter) screenComponent;
            DataLoader dataLoader = filter.getDataLoader();
            MetaClass actualMetaClass = dataLoader.getContainer().getEntityMetaClass();
            MetaClass relatedMetaClass = metaProperty.getRange().asClass();
            MetaClass effectiveMetaClass = extendedEntities.getEffectiveMetaClass(relatedMetaClass);
            if (Objects.equals(actualMetaClass, effectiveMetaClass)) {
                Collection selectedEntities = builder.getSelectedEntities() == null ? Collections.emptyList() : builder.getSelectedEntities();
                String configurationName = generateConfigurationName(builder, metaProperty);
                DesignTimeConfiguration configuration = createFilterConfiguration((Filter) screenComponent, configurationName);
                JpqlFilter jpqlFilter = createJpqlFilter(filter.getDataLoader(), metaProperty, metaClass, selectedEntities);
                configuration.getRootLogicalFilterComponent().add(jpqlFilter);
                configuration.setFilterComponentDefaultValue(jpqlFilter.getParameterName(), jpqlFilter.getValue());
                filter.setCurrentConfiguration(configuration);
                return true;
            }
        }
        return false;
    });
    if (!found) {
        screen.addAfterShowListener(event -> {
            ScreenContext screenContext = UiControllerUtils.getScreenContext(event.getSource());
            screenContext.getNotifications().create(Notifications.NotificationType.WARNING).withCaption(messages.getMessage("actions.Related.FilterNotFound")).show();
        });
    }
    return screen;
}
Also used : DataLoader(io.jmix.ui.model.DataLoader) ScreenContext(io.jmix.ui.screen.ScreenContext) MetaClass(io.jmix.core.metamodel.model.MetaClass) JpqlFilter(io.jmix.ui.component.JpqlFilter) Filter(io.jmix.ui.component.Filter) Screen(io.jmix.ui.screen.Screen) JpqlFilter(io.jmix.ui.component.JpqlFilter) DesignTimeConfiguration(io.jmix.ui.component.filter.configuration.DesignTimeConfiguration) Collection(java.util.Collection) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 2 with Filter

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

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

the class UiDataFilterSupport method getConfigurationsMap.

@Override
public Map<Filter.Configuration, Boolean> getConfigurationsMap(Filter filter) {
    Map<Filter.Configuration, Boolean> map = new TreeMap<>();
    List<FilterConfiguration> configurationModels = loadFilterConfigurationModels(filter);
    for (FilterConfiguration configurationModel : configurationModels) {
        Filter.Configuration configuration = filterConfigurationConverter.toConfiguration(configurationModel, filter);
        map.put(configuration, configurationModel.getDefaultForAll());
    }
    return map;
}
Also used : FilterConfiguration(io.jmix.uidata.entity.FilterConfiguration) Filter(io.jmix.ui.component.Filter) FilterConfiguration(io.jmix.uidata.entity.FilterConfiguration) TreeMap(java.util.TreeMap)

Example 4 with Filter

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

the class FilterSaveAsAction method copyConfiguration.

@SuppressWarnings({ "rawtypes", "unchecked" })
protected Filter.Configuration copyConfiguration(String newId, Filter.Configuration existingConfiguration) {
    LogicalFilterComponent rootLogicalFilterComponent = existingConfiguration.getRootLogicalFilterComponent();
    FilterConverter converter = filterComponents.getConverterByComponentClass(rootLogicalFilterComponent.getClass(), filter);
    Map<String, Object> valuesMap = filterSupport.initConfigurationValuesMap(existingConfiguration);
    LogicalFilterCondition logicalFilterCondition = (LogicalFilterCondition) converter.convertToModel(rootLogicalFilterComponent);
    filterSupport.resetConfigurationValuesMap(existingConfiguration, valuesMap);
    LogicalFilterComponent logicalFilterComponent = (LogicalFilterComponent) converter.convertToComponent(logicalFilterCondition);
    Filter.Configuration newConfiguration = new RunTimeConfiguration(newId, logicalFilterComponent, existingConfiguration.getOwner());
    filterSupport.refreshConfigurationDefaultValues(newConfiguration);
    filterSupport.resetConfigurationValuesMap(newConfiguration, valuesMap);
    return newConfiguration;
}
Also used : Filter(io.jmix.ui.component.Filter) LogicalFilterCondition(io.jmix.ui.entity.LogicalFilterCondition) RunTimeConfiguration(io.jmix.ui.component.filter.configuration.RunTimeConfiguration) FilterConverter(io.jmix.ui.component.filter.converter.FilterConverter) LogicalFilterComponent(io.jmix.ui.component.LogicalFilterComponent)

Example 5 with Filter

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

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