use of com.haulmont.cuba.gui.components.filter.edit.FilterEditor in project cuba by cuba-platform.
the class AttributeEditor method openConstraintWizard.
public void openConstraintWizard() {
Class entityClass = attribute.getJavaClassForEntity();
if (entityClass == null) {
showNotification(getMessage("selectEntityType"));
return;
}
MetaClass metaClass = metadata.getClassNN(entityClass);
FakeFilterSupport fakeFilterSupport = new FakeFilterSupport(this, metaClass);
final Filter fakeFilter = fakeFilterSupport.createFakeFilter();
final FilterEntity filterEntity = fakeFilterSupport.createFakeFilterEntity(attribute.getFilterXml());
final ConditionsTree conditionsTree = fakeFilterSupport.createFakeConditionsTree(fakeFilter, filterEntity);
Map<String, Object> params = new HashMap<>();
params.put("filter", fakeFilter);
params.put("filterEntity", filterEntity);
params.put("conditions", conditionsTree);
params.put("useShortConditionForm", true);
FilterEditor filterEditor = (FilterEditor) openWindow("filterEditor", WindowManager.OpenType.DIALOG, params);
filterEditor.addCloseListener(actionId -> {
if (!COMMIT_ACTION_ID.equals(actionId))
return;
FilterParser filterParser1 = AppBeans.get(FilterParser.class);
filterEntity.setXml(filterParser1.getXml(filterEditor.getConditions(), Param.ValueProperty.DEFAULT_VALUE));
if (filterEntity.getXml() != null) {
Element element = Dom4j.readDocument(filterEntity.getXml()).getRootElement();
com.haulmont.cuba.core.global.filter.FilterParser filterParser = new com.haulmont.cuba.core.global.filter.FilterParser(element);
String jpql = new SecurityJpqlGenerator().generateJpql(filterParser.getRoot());
attribute.setWhereClause(jpql);
Set<String> joins = filterParser.getRoot().getJoins();
if (!joins.isEmpty()) {
String joinsStr = new StrBuilder().appendWithSeparators(joins, " ").toString();
attribute.setJoinClause(joinsStr);
}
attribute.setFilterXml(filterEntity.getXml());
}
});
}
use of com.haulmont.cuba.gui.components.filter.edit.FilterEditor in project cuba by cuba-platform.
the class ConstraintEditor method openWizard.
public void openWizard() {
String entityNameValue = entityName.getValue();
if (StringUtils.isBlank(entityNameValue)) {
showNotification(getMessage("notification.entityIsEmpty"), NotificationType.HUMANIZED);
entityName.requestFocus();
return;
}
FakeFilterSupport fakeFilterSupport = new FakeFilterSupport(this, metadata.getSession().getClass(entityNameValue));
WindowInfo windowInfo = windowConfig.getWindowInfo("filterEditor");
Map<String, Object> params = new HashMap<>();
Constraint constraint = getItem();
final Filter fakeFilter = fakeFilterSupport.createFakeFilter();
final FilterEntity filterEntity = fakeFilterSupport.createFakeFilterEntity(constraint.getFilterXml());
final ConditionsTree conditionsTree = fakeFilterSupport.createFakeConditionsTree(fakeFilter, filterEntity);
params.put("filter", fakeFilter);
params.put("filterEntity", filterEntity);
params.put("conditions", conditionsTree);
params.put("useShortConditionForm", true);
params.put("hideDynamicAttributes", constraint.getCheckType() != ConstraintCheckType.DATABASE);
params.put("hideCustomConditions", constraint.getCheckType() != ConstraintCheckType.DATABASE);
FilterEditor filterEditor = (FilterEditor) windowManagerProvider.get().openWindow(windowInfo, WindowManager.OpenType.DIALOG, params);
filterEditor.addCloseListener(actionId -> {
if (!COMMIT_ACTION_ID.equals(actionId))
return;
FilterParser filterParser1 = AppBeans.get(FilterParser.class);
// todo eude rename com.haulmont.cuba.gui.components.filter.FilterParser
filterEntity.setXml(filterParser1.getXml(filterEditor.getConditions(), Param.ValueProperty.DEFAULT_VALUE));
if (filterEntity.getXml() != null) {
Element element = Dom4j.readDocument(filterEntity.getXml()).getRootElement();
com.haulmont.cuba.core.global.filter.FilterParser filterParser = new com.haulmont.cuba.core.global.filter.FilterParser(element);
Constraint item = getItem();
if (item.getCheckType().database()) {
String jpql = new SecurityJpqlGenerator().generateJpql(filterParser.getRoot());
constraint.setWhereClause(jpql);
Set<String> joins = filterParser.getRoot().getJoins();
if (!joins.isEmpty()) {
String joinsStr = new StrBuilder().appendWithSeparators(joins, " ").toString();
constraint.setJoinClause(joinsStr);
}
}
if (item.getCheckType().memory()) {
String groovy = new GroovyGenerator().generateGroovy(filterParser.getRoot());
constraint.setGroovyScript(groovy);
}
constraint.setFilterXml(filterEntity.getXml());
}
});
}
Aggregations