Search in sources :

Example 1 with AbstractCondition

use of com.haulmont.cuba.gui.components.filter.condition.AbstractCondition in project cuba by cuba-platform.

the class AddConditionHelper method _addCondition.

protected void _addCondition(AbstractConditionDescriptor descriptor, ConditionsTree conditionsTree) {
    final AbstractCondition condition = descriptor.createCondition();
    if (descriptor instanceof CustomConditionCreator) {
        WindowInfo windowInfo = windowConfig.getWindowInfo("customConditionEditor");
        Map<String, Object> params = new HashMap<>();
        params.put("condition", condition);
        params.put("conditionsTree", conditionsTree);
        params.put("filter", filter);
        final CustomConditionEditor window = (CustomConditionEditor) windowManager.openWindow(windowInfo, OpenType.DIALOG, params);
        window.addCloseListener(actionId -> {
            if (Window.COMMIT_ACTION_ID.equals(actionId)) {
                handler.handle(condition);
            }
        });
    } else if (descriptor instanceof DynamicAttributesConditionCreator) {
        WindowInfo windowInfo = windowConfig.getWindowInfo("dynamicAttributesConditionEditor");
        Map<String, Object> params = new HashMap<>();
        params.put("condition", condition);
        params.put("filter", filter);
        DynamicAttributesConditionEditor window = (DynamicAttributesConditionEditor) windowManager.openWindow(windowInfo, OpenType.DIALOG, params);
        window.addCloseListener(actionId -> {
            if (Window.COMMIT_ACTION_ID.equals(actionId)) {
                handler.handle(condition);
            }
        });
    } else {
        handler.handle(condition);
    }
}
Also used : CustomConditionCreator(com.haulmont.cuba.gui.components.filter.descriptor.CustomConditionCreator) WindowManager(com.haulmont.cuba.gui.WindowManager) WindowInfo(com.haulmont.cuba.gui.config.WindowInfo) Collection(java.util.Collection) AddConditionWindow(com.haulmont.cuba.gui.components.filter.addcondition.AddConditionWindow) HashMap(java.util.HashMap) AbstractCondition(com.haulmont.cuba.gui.components.filter.condition.AbstractCondition) AppBeans(com.haulmont.cuba.core.global.AppBeans) CustomConditionEditor(com.haulmont.cuba.gui.components.filter.edit.CustomConditionEditor) ConditionDescriptorsTreeBuilderAPI(com.haulmont.cuba.gui.components.filter.addcondition.ConditionDescriptorsTreeBuilderAPI) AbstractConditionDescriptor(com.haulmont.cuba.gui.components.filter.descriptor.AbstractConditionDescriptor) Window(com.haulmont.cuba.gui.components.Window) DynamicAttributesConditionCreator(com.haulmont.cuba.gui.components.filter.descriptor.DynamicAttributesConditionCreator) Configuration(com.haulmont.cuba.core.global.Configuration) WindowConfig(com.haulmont.cuba.gui.config.WindowConfig) DynamicAttributesConditionEditor(com.haulmont.cuba.gui.components.filter.edit.DynamicAttributesConditionEditor) Tree(com.haulmont.bali.datastruct.Tree) Map(java.util.Map) ClientConfig(com.haulmont.cuba.client.ClientConfig) WindowManagerProvider(com.haulmont.cuba.gui.WindowManagerProvider) Filter(com.haulmont.cuba.gui.components.Filter) OpenType(com.haulmont.cuba.gui.WindowManager.OpenType) CustomConditionEditor(com.haulmont.cuba.gui.components.filter.edit.CustomConditionEditor) CustomConditionCreator(com.haulmont.cuba.gui.components.filter.descriptor.CustomConditionCreator) HashMap(java.util.HashMap) WindowInfo(com.haulmont.cuba.gui.config.WindowInfo) DynamicAttributesConditionEditor(com.haulmont.cuba.gui.components.filter.edit.DynamicAttributesConditionEditor) DynamicAttributesConditionCreator(com.haulmont.cuba.gui.components.filter.descriptor.DynamicAttributesConditionCreator) AbstractCondition(com.haulmont.cuba.gui.components.filter.condition.AbstractCondition) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with AbstractCondition

use of com.haulmont.cuba.gui.components.filter.condition.AbstractCondition in project cuba by cuba-platform.

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.getMainMessage("Op.NOT_EMPTY"));
            } else {
                sb.append(messages.getMainMessage("Op.EMPTY"));
            }
        } else {
            sb.append(condition.getOperationCaption()).append(" ").append(formatParamValue(param));
        }
    }
}
Also used : Node(com.haulmont.bali.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 3 with AbstractCondition

use of com.haulmont.cuba.gui.components.filter.condition.AbstractCondition in project cuba by cuba-platform.

the class AppliedFilter method getText.

public String getText() {
    String name = filterEntity.getName();
    if (StringUtils.isBlank(name)) {
        name = messages.getMainMessage(filterEntity.getCode());
    }
    StringBuilder sb = new StringBuilder(name);
    List<Node<AbstractCondition>> visibleRootNodesWithValues = new ArrayList<>();
    for (Node<AbstractCondition> rootNode : conditions.getRootNodes()) {
        AbstractCondition condition = rootNode.getData();
        if (!condition.getHidden() && (condition.isGroup() || condition.getParam() != null && condition.getParam().getValue() != null))
            visibleRootNodesWithValues.add(rootNode);
    }
    Iterator<Node<AbstractCondition>> iterator = visibleRootNodesWithValues.iterator();
    if (iterator.hasNext())
        sb.append(": ");
    while (iterator.hasNext()) {
        Node<AbstractCondition> rootNode = iterator.next();
        recursivelyCreateConditionCaption(rootNode, sb);
        if (iterator.hasNext())
            sb.append(", ");
    }
    return sb.toString();
}
Also used : Node(com.haulmont.bali.datastruct.Node) ArrayList(java.util.ArrayList) AbstractCondition(com.haulmont.cuba.gui.components.filter.condition.AbstractCondition)

Example 4 with AbstractCondition

use of com.haulmont.cuba.gui.components.filter.condition.AbstractCondition in project cuba by cuba-platform.

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(com.haulmont.bali.datastruct.Node) AbstractCondition(com.haulmont.cuba.gui.components.filter.condition.AbstractCondition)

Example 5 with AbstractCondition

use of com.haulmont.cuba.gui.components.filter.condition.AbstractCondition in project cuba by cuba-platform.

the class RelatedEntitiesBean method getRelatedEntitiesFilterXml.

protected String getRelatedEntitiesFilterXml(MetaClass relatedMetaCLass, Collection<? extends Entity> selectedEntities, Filter component, MetaDataDescriptor descriptor) {
    ConditionsTree tree = new ConditionsTree();
    String filterComponentPath = ComponentsHelper.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(com.haulmont.chile.core.model.MetaClass) Node(com.haulmont.bali.datastruct.Node) AbstractCondition(com.haulmont.cuba.gui.components.filter.condition.AbstractCondition) ConditionsTree(com.haulmont.cuba.gui.components.filter.ConditionsTree)

Aggregations

AbstractCondition (com.haulmont.cuba.gui.components.filter.condition.AbstractCondition)6 Node (com.haulmont.bali.datastruct.Node)5 GroupCondition (com.haulmont.cuba.gui.components.filter.condition.GroupCondition)2 ArrayList (java.util.ArrayList)2 Tree (com.haulmont.bali.datastruct.Tree)1 MetaClass (com.haulmont.chile.core.model.MetaClass)1 ClientConfig (com.haulmont.cuba.client.ClientConfig)1 AppBeans (com.haulmont.cuba.core.global.AppBeans)1 Configuration (com.haulmont.cuba.core.global.Configuration)1 WindowManager (com.haulmont.cuba.gui.WindowManager)1 OpenType (com.haulmont.cuba.gui.WindowManager.OpenType)1 WindowManagerProvider (com.haulmont.cuba.gui.WindowManagerProvider)1 Filter (com.haulmont.cuba.gui.components.Filter)1 Window (com.haulmont.cuba.gui.components.Window)1 ConditionsTree (com.haulmont.cuba.gui.components.filter.ConditionsTree)1 AddConditionWindow (com.haulmont.cuba.gui.components.filter.addcondition.AddConditionWindow)1 ConditionDescriptorsTreeBuilderAPI (com.haulmont.cuba.gui.components.filter.addcondition.ConditionDescriptorsTreeBuilderAPI)1 AbstractConditionDescriptor (com.haulmont.cuba.gui.components.filter.descriptor.AbstractConditionDescriptor)1 CustomConditionCreator (com.haulmont.cuba.gui.components.filter.descriptor.CustomConditionCreator)1 DynamicAttributesConditionCreator (com.haulmont.cuba.gui.components.filter.descriptor.DynamicAttributesConditionCreator)1