Search in sources :

Example 1 with AttributeNode

use of org.eclipse.scout.rt.client.ui.form.fields.composer.node.AttributeNode in project scout.rt by eclipse.

the class AbstractComposerField method execCreateAttributeNode.

/**
 * Override this method to decorate or enhance new nodes whenever they are created
 *
 * @return the new node or null to ignore the add of a new node of this type
 *         <p>
 *         Normally overrides call super. {@link #execCreateAttributeNode(ITreeNode, IDataModelAttribute, Integer,
 *         IComposerOp, Object[], List<String>)}
 */
@ConfigOperation
@Order(120)
protected AttributeNode execCreateAttributeNode(ITreeNode parentNode, IDataModelAttribute a, Integer aggregationType, IDataModelAttributeOp op, List<? extends Object> values, List<String> texts) {
    if (aggregationType != null && aggregationType == DataModelConstants.AGGREGATION_NONE) {
        aggregationType = null;
    }
    AttributeNode node = new AttributeNode(this, a);
    node.setAggregationType(aggregationType);
    node.setOp(op);
    node.setValues(values);
    node.setTexts(texts);
    node.setStatus(ITreeNode.STATUS_INSERTED);
    return node;
}
Also used : AttributeNode(org.eclipse.scout.rt.client.ui.form.fields.composer.node.AttributeNode) Order(org.eclipse.scout.rt.platform.Order) ConfigOperation(org.eclipse.scout.rt.platform.annotations.ConfigOperation)

Example 2 with AttributeNode

use of org.eclipse.scout.rt.client.ui.form.fields.composer.node.AttributeNode in project scout.rt by eclipse.

the class AbstractComposerField method storeXMLRec.

private void storeXMLRec(Element x, ITreeNode parent) {
    for (ITreeNode node : parent.getChildNodes()) {
        if (node instanceof EntityNode) {
            EntityNode entityNode = (EntityNode) node;
            Element xEntity = x.getOwnerDocument().createElement("entity");
            xEntity.setAttribute("id", DataModelUtility.entityPathToExternalId(getDataModel(), interceptResolveEntityPath(entityNode)));
            xEntity.setAttribute("negated", (entityNode.isNegative() ? "true" : "false"));
            List<String> texts = entityNode.getTexts();
            xEntity.setAttribute("displayValues", CollectionUtility.hasElements(texts) ? StringUtility.emptyIfNull(CollectionUtility.firstElement(texts)) : null);
            x.appendChild(xEntity);
            // recursion
            storeXMLRec(xEntity, node);
        } else if (node instanceof AttributeNode) {
            AttributeNode attNode = (AttributeNode) node;
            Element xAtt = x.getOwnerDocument().createElement("attribute");
            xAtt.setAttribute("id", DataModelUtility.attributePathToExternalId(getDataModel(), interceptResolveAttributePath(attNode)));
            IDataModelAttributeOp op = attNode.getOp();
            try {
                xAtt.setAttribute("op", op.getOperator() + "");
                if (attNode.getAggregationType() != null) {
                    xAtt.setAttribute("aggregationType", attNode.getAggregationType() + "");
                }
            } catch (Exception e) {
                LOG.warn("write op {}", op, e);
            }
            List<String> texts = attNode.getTexts();
            if (CollectionUtility.hasElements(texts)) {
                Iterator<String> it = texts.iterator();
                xAtt.setAttribute("displayValue", StringUtility.emptyIfNull(it.next()));
                int i = 2;
                while (it.hasNext()) {
                    xAtt.setAttribute(("displayValue" + i), StringUtility.emptyIfNull(it.next()));
                    i++;
                }
            }
            List<Object> values = attNode.getValues();
            if (values != null) {
                int i = 0;
                for (Object value : values) {
                    String valueName = (i == 0 ? "value" : "value" + (i + 1));
                    try {
                        XmlUtility.setObjectAttribute(xAtt, valueName, value);
                    } catch (Exception e) {
                        LOG.warn("write value[{}] for attribute {}: {}", i, attNode.getAttribute(), value, e);
                    }
                    i++;
                }
            }
            x.appendChild(xAtt);
        } else if (node instanceof EitherOrNode) {
            EitherOrNode orNode = (EitherOrNode) node;
            Element xOr = x.getOwnerDocument().createElement("or");
            xOr.setAttribute("begin", "" + orNode.isBeginOfEitherOr());
            xOr.setAttribute("negated", (orNode.isNegative() ? "true" : "false"));
            x.appendChild(xOr);
            // recursion
            storeXMLRec(xOr, node);
        }
    }
}
Also used : EitherOrNode(org.eclipse.scout.rt.client.ui.form.fields.composer.node.EitherOrNode) ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) AttributeNode(org.eclipse.scout.rt.client.ui.form.fields.composer.node.AttributeNode) Element(org.w3c.dom.Element) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) IDataModelAttributeOp(org.eclipse.scout.rt.shared.data.model.IDataModelAttributeOp) EntityNode(org.eclipse.scout.rt.client.ui.form.fields.composer.node.EntityNode)

Example 3 with AttributeNode

use of org.eclipse.scout.rt.client.ui.form.fields.composer.node.AttributeNode in project scout.rt by eclipse.

the class ComposerDisplayTextBuilder method visitAndNodes.

private void visitAndNodes(List<? extends ITreeNode> nodes, StringBuilder buf, String prefix) {
    Iterator<? extends ITreeNode> nodeIt = nodes.iterator();
    ITreeNode node = null;
    boolean skipDoNext = false;
    while (nodeIt.hasNext() || skipDoNext) {
        // to ensure visit first node after an either or...
        if (!skipDoNext) {
            node = nodeIt.next();
        }
        // reset
        skipDoNext = false;
        if (node instanceof EntityNode) {
            visitEntityNode((EntityNode) node, buf, prefix);
        } else if (node instanceof AttributeNode) {
            visitAttributeNode((AttributeNode) node, buf, prefix);
        } else if (node instanceof EitherOrNode) {
            List<EitherOrNode> eitherOrNodes = new ArrayList<EitherOrNode>();
            eitherOrNodes.add((EitherOrNode) node);
            while (nodeIt.hasNext()) {
                node = nodeIt.next();
                if (node instanceof EitherOrNode) {
                    eitherOrNodes.add((EitherOrNode) node);
                } else {
                    skipDoNext = true;
                    break;
                }
            }
            visitOrNodes(eitherOrNodes, buf, prefix);
        }
    }
}
Also used : EitherOrNode(org.eclipse.scout.rt.client.ui.form.fields.composer.node.EitherOrNode) ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) AttributeNode(org.eclipse.scout.rt.client.ui.form.fields.composer.node.AttributeNode) ArrayList(java.util.ArrayList) EntityNode(org.eclipse.scout.rt.client.ui.form.fields.composer.node.EntityNode)

Aggregations

AttributeNode (org.eclipse.scout.rt.client.ui.form.fields.composer.node.AttributeNode)3 ArrayList (java.util.ArrayList)2 ITreeNode (org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode)2 EitherOrNode (org.eclipse.scout.rt.client.ui.form.fields.composer.node.EitherOrNode)2 EntityNode (org.eclipse.scout.rt.client.ui.form.fields.composer.node.EntityNode)2 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Order (org.eclipse.scout.rt.platform.Order)1 ConfigOperation (org.eclipse.scout.rt.platform.annotations.ConfigOperation)1 IDataModelAttributeOp (org.eclipse.scout.rt.shared.data.model.IDataModelAttributeOp)1 Element (org.w3c.dom.Element)1