use of io.jmix.core.common.datastruct.Node in project jmix by jmix-framework.
the class RelatedEntitiesBean method getRelatedEntitiesFilterXml.
protected String getRelatedEntitiesFilterXml(MetaClass relatedMetaCLass, Collection<? extends Entity> selectedEntities, Filter component, MetaDataDescriptor descriptor) {
ConditionsTree tree = new ConditionsTree();
String filterComponentPath = CubaComponentsHelper.getFilterComponentPath(component);
String[] strings = ValuePathHelper.parse(filterComponentPath);
String filterComponentName = ValuePathHelper.pathSuffix(strings);
MetaClass metaClass = getFilterMetaClass(component);
String relatedPrimaryKey = metadataTools.getPrimaryKeyName(relatedMetaCLass);
AbstractCondition condition = getOptimizedCondition(getParentIds(selectedEntities), metaClass, filterComponentName, relatedPrimaryKey, descriptor);
if (condition == null) {
condition = getNonOptimizedCondition(relatedMetaCLass, getRelatedIds(selectedEntities, descriptor), component, filterComponentName, relatedPrimaryKey);
}
tree.setRootNodes(Collections.singletonList(new Node<>(condition)));
return filterParser.getXml(tree, Param.ValueProperty.VALUE);
}
use of io.jmix.core.common.datastruct.Node in project jmix by jmix-framework.
the class FilteringLookupAction method createFilterXml.
protected String createFilterXml(Filter filterComponent) {
ConditionsTree tree = new ConditionsTree();
CustomCondition condition = createCustomCondition(filterComponent);
tree.setRootNodes(Collections.singletonList(new Node<>(condition)));
return AppBeans.get(FilterParser.class).getXml(tree, Param.ValueProperty.VALUE);
}
use of io.jmix.core.common.datastruct.Node in project jmix by jmix-framework.
the class FilterParserImpl method recursiveFromXml.
protected void recursiveFromXml(Element element, @Nullable Node<AbstractCondition> parentNode, Filter filter, String xml, ConditionsTree conditions) {
for (Element el : element.elements()) {
AbstractCondition condition;
if ("c".equals(el.getName())) {
String name = el.attributeValue("name");
if (name == null)
throw new IllegalStateException("'name' attribute expected for 'c' element: " + xml);
String type = el.attributeValue("type");
condition = createCondition(ConditionType.valueOf(type), el, filter, xml);
Node<AbstractCondition> node = new Node<>(condition);
if (parentNode != null)
parentNode.addChild(node);
else
conditions.getRootNodes().add(node);
} else if ("and".equals(el.getName()) || "or".equals(el.getName())) {
condition = createCondition(ConditionType.GROUP, el, filter, xml);
Node<AbstractCondition> node = new Node<>(condition);
if (parentNode != null)
parentNode.addChild(node);
else
conditions.getRootNodes().add(node);
recursiveFromXml(el, node, filter, xml, conditions);
} else {
throw new UnsupportedOperationException("Unknown element: " + el.getName());
}
}
}
use of io.jmix.core.common.datastruct.Node in project jmix by jmix-framework.
the class AppliedFilter method recursivelyCreateConditionCaption.
protected void recursivelyCreateConditionCaption(Node<AbstractCondition> node, StringBuilder sb) {
AbstractCondition condition = node.getData();
if (condition.getHidden())
return;
if (condition.isGroup()) {
GroupType groupType = ((GroupCondition) condition).getGroupType();
sb.append(groupType.getLocCaption()).append("(");
List<Node<AbstractCondition>> visibleChildNodes = new ArrayList<>();
for (Node<AbstractCondition> childNode : node.getChildren()) {
AbstractCondition childCondition = childNode.getData();
if (!childCondition.getHidden() && (childCondition.isGroup() || childCondition.getParam() != null && childCondition.getParam().getValue() != null))
visibleChildNodes.add(childNode);
}
Iterator<Node<AbstractCondition>> iterator = visibleChildNodes.iterator();
while (iterator.hasNext()) {
Node<AbstractCondition> childNode = iterator.next();
recursivelyCreateConditionCaption(childNode, sb);
if (iterator.hasNext())
sb.append(", ");
}
sb.append(")");
} else {
Param param = condition.getParam();
sb.append(condition.getLocCaption()).append(" ");
if (condition.getOperator() == Op.NOT_EMPTY) {
if (BooleanUtils.isTrue((Boolean) param.getValue())) {
sb.append(messages.getMessage(Op.class, "Op.NOT_EMPTY"));
} else {
sb.append(messages.getMessage(Op.class, "Op.EMPTY"));
}
} else {
sb.append(condition.getOperationCaption()).append(" ").append(formatParamValue(param));
}
}
}
use of io.jmix.core.common.datastruct.Node in project jmix by jmix-framework.
the class ConditionsTree method recursivelyCopyNode.
protected void recursivelyCopyNode(Node<AbstractCondition> srcNode, Node<AbstractCondition> dstNode) {
AbstractCondition srcCondition = srcNode.getData();
AbstractCondition dstCondition = srcCondition.createCopy();
dstNode.setData(dstCondition);
for (Node<AbstractCondition> srcChild : srcNode.getChildren()) {
Node<AbstractCondition> dstChild = new Node<>();
dstNode.addChild(dstChild);
recursivelyCopyNode(srcChild, dstChild);
}
}
Aggregations