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;
}
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;
}
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;
}
Aggregations