Search in sources :

Example 1 with IDataModelAttributeOp

use of org.eclipse.scout.rt.shared.data.model.IDataModelAttributeOp in project scout.rt by eclipse.

the class AbstractDataModelOperatorField method setAttribute.

public void setAttribute(IDataModelAttribute attribute) {
    IDataModelAttributeOp oldOp = getValue();
    ((DataModelOperatorLookupCall) getLookupCall()).setAttribute(attribute);
    IDataModelAttributeOp newOp = null;
    if (attribute != null) {
        setView(true, true, false);
        HashSet<IDataModelAttributeOp> tmp = new HashSet<IDataModelAttributeOp>();
        List<IDataModelAttributeOp> ops = attribute.getOperators();
        tmp.addAll(ops);
        if (tmp.contains(oldOp)) {
            newOp = oldOp;
        } else {
            newOp = CollectionUtility.firstElement(ops);
        }
    } else {
        setView(false, false, false);
    }
    setValue(newOp);
}
Also used : IDataModelAttributeOp(org.eclipse.scout.rt.shared.data.model.IDataModelAttributeOp) HashSet(java.util.HashSet)

Example 2 with IDataModelAttributeOp

use of org.eclipse.scout.rt.shared.data.model.IDataModelAttributeOp in project scout.rt by eclipse.

the class AbstractComposerField method loadXMLRec.

private void loadXMLRec(Element x, ITreeNode parent) {
    // build tree
    for (Element xmlElem : XmlUtility.getChildElements(x)) {
        if ("attribute".equals(xmlElem.getTagName())) {
            String id = xmlElem.getAttribute("id");
            IDataModelAttributeOp op;
            Integer aggregationType = 0;
            try {
                int operator = DataModelConstants.OPERATOR_EQ;
                String opAttribName = "op";
                if (xmlElem.hasAttribute(opAttribName)) {
                    operator = Integer.parseInt(xmlElem.getAttribute(opAttribName));
                }
                op = DataModelAttributeOp.create(operator);
                String aggregTypeName = "aggregationType";
                if (xmlElem.hasAttribute(aggregTypeName)) {
                    aggregationType = Integer.parseInt(xmlElem.getAttribute(aggregTypeName));
                }
                if (aggregationType == 0) {
                    aggregationType = null;
                }
            } catch (Exception e) {
                LOG.warn("read op", e);
                continue;
            }
            ArrayList<Object> valueList = new ArrayList<Object>();
            try {
                for (int i = 1; i <= 5; i++) {
                    String valueName = (i == 1 ? "value" : "value" + i);
                    if (xmlElem.hasAttribute(valueName)) {
                        valueList.add(XmlUtility.getObjectAttribute(xmlElem, valueName));
                    }
                }
            } catch (Exception e) {
                LOG.warn("read value for attribute {}", id, e);
                continue;
            }
            ArrayList<String> displayValueList = new ArrayList<String>();
            for (int i = 1; i <= 5; i++) {
                String displayValueName = (i == 1 ? "displayValue" : "displayValue" + i);
                if (xmlElem.hasAttribute(displayValueName)) {
                    String val = null;
                    if (xmlElem.hasAttribute(displayValueName)) {
                        val = xmlElem.getAttribute(displayValueName);
                    }
                    displayValueList.add(val);
                }
            }
            // find definition
            AttributePath attPath = DataModelUtility.externalIdToAttributePath(getDataModel(), id);
            IDataModelAttribute foundAtt = (attPath != null ? attPath.getAttribute() : null);
            if (foundAtt == null) {
                LOG.warn("cannot find attribute with id={}", id);
                continue;
            }
            ITreeNode node = addAttributeNode(parent, foundAtt, aggregationType, op, valueList, displayValueList);
            if (node != null) {
                // add children recursive
                loadXMLRec(xmlElem, node);
            }
        } else if ("entity".equals(xmlElem.getTagName())) {
            String id = xmlElem.getAttribute("id");
            boolean negated = Boolean.parseBoolean(xmlElem.getAttribute("negated"));
            String text = null;
            if (xmlElem.hasAttribute("displayValues")) {
                text = xmlElem.getAttribute("displayValues");
            }
            // find definition
            EntityPath entityPath = DataModelUtility.externalIdToEntityPath(getDataModel(), id);
            IDataModelEntity foundEntity = (entityPath != null ? entityPath.lastElement() : null);
            if (foundEntity == null) {
                LOG.warn("cannot find entity with id={}", id);
                continue;
            }
            ITreeNode node = addEntityNode(parent, foundEntity, negated, null, text != null ? Collections.singletonList(text) : null);
            if (node != null) {
                // add children recursive
                loadXMLRec(xmlElem, node);
            }
        } else if ("or".equals(xmlElem.getTagName())) {
            boolean beginning = Boolean.parseBoolean(xmlElem.getAttribute("begin"));
            boolean negated = Boolean.parseBoolean(xmlElem.getAttribute("negated"));
            ITreeNode node = null;
            if (beginning) {
                node = addEitherNode(parent, negated);
            } else {
                // find last EitherOrNode
                EitherOrNode orNode = null;
                for (ITreeNode n : parent.getChildNodes()) {
                    if (n instanceof EitherOrNode && ((EitherOrNode) n).isEndOfEitherOr()) {
                        orNode = (EitherOrNode) n;
                    }
                }
                if (orNode != null) {
                    node = addAdditionalOrNode(orNode, negated);
                }
            }
            if (node != null) {
                // add children recursive
                loadXMLRec(xmlElem, node);
            }
        }
    }
}
Also used : EntityPath(org.eclipse.scout.rt.shared.data.model.EntityPath) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) IDataModelEntity(org.eclipse.scout.rt.shared.data.model.IDataModelEntity) IDataModelAttribute(org.eclipse.scout.rt.shared.data.model.IDataModelAttribute) EitherOrNode(org.eclipse.scout.rt.client.ui.form.fields.composer.node.EitherOrNode) ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) IDataModelAttributeOp(org.eclipse.scout.rt.shared.data.model.IDataModelAttributeOp) AttributePath(org.eclipse.scout.rt.shared.data.model.AttributePath)

Example 3 with IDataModelAttributeOp

use of org.eclipse.scout.rt.shared.data.model.IDataModelAttributeOp 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 4 with IDataModelAttributeOp

use of org.eclipse.scout.rt.shared.data.model.IDataModelAttributeOp in project scout.rt by eclipse.

the class DataModelOperatorLookupCall method execCreateLookupRows.

@Override
protected List<ILookupRow<IDataModelAttributeOp>> execCreateLookupRows() {
    List<ILookupRow<IDataModelAttributeOp>> result = new ArrayList<ILookupRow<IDataModelAttributeOp>>();
    List<IDataModelAttributeOp> ops = null;
    if (m_attribute != null) {
        ops = m_attribute.getOperators();
    }
    if (ops != null) {
        for (IDataModelAttributeOp op : ops) {
            String text = op.getShortText();
            if (text != null && text.indexOf("{0}") >= 0) {
                text = text.replace("{0}", "n");
            }
            if (text != null && text.indexOf("{1}") >= 0) {
                text = text.replace("{1}", "m");
            }
            result.add(new LookupRow<IDataModelAttributeOp>(op, text));
        }
    }
    return result;
}
Also used : ILookupRow(org.eclipse.scout.rt.shared.services.lookup.ILookupRow) ArrayList(java.util.ArrayList) IDataModelAttributeOp(org.eclipse.scout.rt.shared.data.model.IDataModelAttributeOp)

Example 5 with IDataModelAttributeOp

use of org.eclipse.scout.rt.shared.data.model.IDataModelAttributeOp in project scout.rt by eclipse.

the class ComposerAttributeForm method activateValueField.

/**
 * activate value field function
 */
private void activateValueField() {
    IDataModelAttribute att = getAttributeField().getCheckedKey();
    IDataModelAttributeOp op = getOperatorField().getCheckedKey();
    List<Object> newValues = getSelectedValues();
    // 
    if (att == null) {
        getValueField().clearSelectionContext();
    } else {
        getValueField().setSelectionContext(att, op, newValues);
    }
}
Also used : IDataModelAttributeOp(org.eclipse.scout.rt.shared.data.model.IDataModelAttributeOp) IDataModelAttribute(org.eclipse.scout.rt.shared.data.model.IDataModelAttribute)

Aggregations

IDataModelAttributeOp (org.eclipse.scout.rt.shared.data.model.IDataModelAttributeOp)6 ArrayList (java.util.ArrayList)3 ITreeNode (org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode)3 IDataModelAttribute (org.eclipse.scout.rt.shared.data.model.IDataModelAttribute)3 EitherOrNode (org.eclipse.scout.rt.client.ui.form.fields.composer.node.EitherOrNode)2 Element (org.w3c.dom.Element)2 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 ComposerAttributeForm (org.eclipse.scout.rt.client.ui.form.fields.composer.internal.ComposerAttributeForm)1 AttributeNode (org.eclipse.scout.rt.client.ui.form.fields.composer.node.AttributeNode)1 EntityNode (org.eclipse.scout.rt.client.ui.form.fields.composer.node.EntityNode)1 AttributePath (org.eclipse.scout.rt.shared.data.model.AttributePath)1 EntityPath (org.eclipse.scout.rt.shared.data.model.EntityPath)1 IDataModelEntity (org.eclipse.scout.rt.shared.data.model.IDataModelEntity)1 ILookupRow (org.eclipse.scout.rt.shared.services.lookup.ILookupRow)1