Search in sources :

Example 1 with JpqlFilter

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

the class RelatedEntitiesSupportImpl method createJpqlFilter.

protected JpqlFilter createJpqlFilter(DataLoader dataLoader, MetaProperty metaProperty, MetaClass parentMetaClass, Collection selectedParentEntities) {
    JpqlFilter jpqlFilter = uiComponents.create(JpqlFilter.NAME);
    jpqlFilter.setDataLoader(dataLoader);
    jpqlFilter.setHasInExpression(true);
    jpqlFilter.setVisible(false);
    Class parameterClass = parentMetaClass.getJavaClass();
    jpqlFilter.setParameterClass(parameterClass);
    jpqlFilter.setParameterName(jpqlFilterSupport.generateParameterName(null, parameterClass.getSimpleName()));
    String where = getWhereExpression(metaProperty, parentMetaClass);
    jpqlFilter.setCondition(where, null);
    HasValue valueComponent = singleFilterSupport.generateValueComponent(metaProperty.getDomain(), true, parameterClass);
    jpqlFilter.setValueComponent(valueComponent);
    jpqlFilter.setValue(selectedParentEntities);
    return jpqlFilter;
}
Also used : JpqlFilter(io.jmix.ui.component.JpqlFilter) MetaClass(io.jmix.core.metamodel.model.MetaClass) HasValue(io.jmix.ui.component.HasValue)

Example 2 with JpqlFilter

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

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

the class JpqlFilterConverter method convertToComponent.

@SuppressWarnings("unchecked")
@Override
public JpqlFilter<?> convertToComponent(JpqlFilterCondition model) {
    JpqlFilter jpqlFilter = super.convertToComponent(model);
    jpqlFilter.setCaption(model.getCaption());
    jpqlFilter.setCaptionPosition(model.getCaptionPosition());
    jpqlFilter.setRequired(model.getRequired());
    jpqlFilter.setParameterName(model.getParameterName());
    if (model.getParameterClass() != null) {
        jpqlFilter.setParameterClass(classManager.loadClass(model.getParameterClass()));
    }
    jpqlFilter.setCondition(model.getWhere(), model.getJoin());
    jpqlFilter.setHasInExpression(model.getHasInExpression());
    HasValue valueComponent = convertValueComponentToComponent(jpqlFilter, model);
    Object defaultValue = convertDefaultValueToComponent(jpqlFilter, model);
    jpqlFilter.setValueComponent(valueComponent);
    jpqlFilter.setValue(defaultValue);
    return jpqlFilter;
}
Also used : JpqlFilter(io.jmix.ui.component.JpqlFilter) HasValue(io.jmix.ui.component.HasValue)

Aggregations

JpqlFilter (io.jmix.ui.component.JpqlFilter)3 MetaClass (io.jmix.core.metamodel.model.MetaClass)2 HasValue (io.jmix.ui.component.HasValue)2 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)1 Filter (io.jmix.ui.component.Filter)1 DesignTimeConfiguration (io.jmix.ui.component.filter.configuration.DesignTimeConfiguration)1 DataLoader (io.jmix.ui.model.DataLoader)1 Screen (io.jmix.ui.screen.Screen)1 ScreenContext (io.jmix.ui.screen.ScreenContext)1 Collection (java.util.Collection)1