Search in sources :

Example 1 with Node

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);
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) Node(io.jmix.core.common.datastruct.Node) AbstractCondition(com.haulmont.cuba.gui.components.filter.condition.AbstractCondition) ConditionsTree(com.haulmont.cuba.gui.components.filter.ConditionsTree)

Example 2 with Node

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);
}
Also used : CustomCondition(com.haulmont.cuba.gui.components.filter.condition.CustomCondition) Node(io.jmix.core.common.datastruct.Node) FilterParser(com.haulmont.cuba.gui.components.filter.FilterParser) ConditionsTree(com.haulmont.cuba.gui.components.filter.ConditionsTree)

Example 3 with Node

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());
        }
    }
}
Also used : Element(org.dom4j.Element) Node(io.jmix.core.common.datastruct.Node) AbstractCondition(com.haulmont.cuba.gui.components.filter.condition.AbstractCondition)

Example 4 with Node

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));
        }
    }
}
Also used : Op(com.haulmont.cuba.core.global.filter.Op) Node(io.jmix.core.common.datastruct.Node) ArrayList(java.util.ArrayList) GroupCondition(com.haulmont.cuba.gui.components.filter.condition.GroupCondition) AbstractCondition(com.haulmont.cuba.gui.components.filter.condition.AbstractCondition)

Example 5 with Node

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);
    }
}
Also used : Node(io.jmix.core.common.datastruct.Node) AbstractCondition(com.haulmont.cuba.gui.components.filter.condition.AbstractCondition)

Aggregations

Node (io.jmix.core.common.datastruct.Node)13 AbstractCondition (com.haulmont.cuba.gui.components.filter.condition.AbstractCondition)7 ConditionsTree (com.haulmont.cuba.gui.components.filter.ConditionsTree)4 MetaClass (io.jmix.core.metamodel.model.MetaClass)3 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)3 ListComponent (com.haulmont.cuba.gui.components.ListComponent)2 GroupCondition (com.haulmont.cuba.gui.components.filter.condition.GroupCondition)2 GroupConditionDescriptor (com.haulmont.cuba.gui.components.filter.descriptor.GroupConditionDescriptor)2 KeyValueMetaClass (io.jmix.core.impl.keyvalue.KeyValueMetaClass)2 MetaPropertyPath (io.jmix.core.metamodel.model.MetaPropertyPath)2 Component (io.jmix.ui.component.Component)2 ArrayList (java.util.ArrayList)2 Element (org.dom4j.Element)2 CubaProperties (com.haulmont.cuba.CubaProperties)1 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)1 Messages (com.haulmont.cuba.core.global.Messages)1 Op (com.haulmont.cuba.core.global.filter.Op)1 AbstractWindow (com.haulmont.cuba.gui.components.AbstractWindow)1 Filter (com.haulmont.cuba.gui.components.Filter)1 GridLayout (com.haulmont.cuba.gui.components.GridLayout)1