Search in sources :

Example 1 with EitherOrNode

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

the class AbstractComposerField method addAdditionalOrNode.

@Override
public EitherOrNode addAdditionalOrNode(ITreeNode eitherOrNode, boolean negated) {
    EitherOrNode node = interceptCreateAdditionalOrNode(eitherOrNode, negated);
    if (node != null) {
        getTree().addChildNode(eitherOrNode.getChildNodeIndex() + 1, eitherOrNode.getParentNode(), node);
        getTree().setNodeExpanded(node, true);
    }
    return node;
}
Also used : EitherOrNode(org.eclipse.scout.rt.client.ui.form.fields.composer.node.EitherOrNode)

Example 2 with EitherOrNode

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

the class AbstractComposerField method addEitherNode.

@Override
public EitherOrNode addEitherNode(ITreeNode parentNode, boolean negated) {
    EitherOrNode node = interceptCreateEitherNode(parentNode, negated);
    if (node != null) {
        getTree().addChildNode(parentNode, node);
        getTree().setNodeExpanded(node, true);
    }
    return node;
}
Also used : EitherOrNode(org.eclipse.scout.rt.client.ui.form.fields.composer.node.EitherOrNode)

Example 3 with EitherOrNode

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

the class ComposerFieldTest method testExportEitherOrNode.

@Test
public void testExportEitherOrNode() throws Exception {
    // setup field
    ITreeNode parentNode = m_composerField.getTree().getRootNode();
    EitherOrNode eitherNode = m_composerField.addEitherNode(parentNode, false);
    m_composerField.addAdditionalOrNode(eitherNode, false);
    // export
    m_composerField.exportFormFieldData(m_fieldData);
    // verify export
    assertEquals(2, m_fieldData.getRootCount());
    // 
    TreeNodeData eitherNodeData = m_fieldData.getRoots().get(0);
    assertTrue(eitherNodeData instanceof ComposerEitherOrNodeData);
    assertTrue(((ComposerEitherOrNodeData) eitherNodeData).isBeginOfEitherOr());
    assertFalse(((ComposerEitherOrNodeData) eitherNodeData).isNegative());
    // 
    TreeNodeData orNodeData = m_fieldData.getRoots().get(1);
    assertTrue(orNodeData instanceof ComposerEitherOrNodeData);
    assertFalse(((ComposerEitherOrNodeData) orNodeData).isBeginOfEitherOr());
    assertFalse(((ComposerEitherOrNodeData) orNodeData).isNegative());
}
Also used : EitherOrNode(org.eclipse.scout.rt.client.ui.form.fields.composer.node.EitherOrNode) ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) TreeNodeData(org.eclipse.scout.rt.shared.data.form.fields.treefield.TreeNodeData) ComposerEitherOrNodeData(org.eclipse.scout.rt.shared.data.form.fields.composer.ComposerEitherOrNodeData) Test(org.junit.Test)

Example 4 with EitherOrNode

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

the class AbstractComposerField method execCreateAdditionalOrNode.

/**
 * 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 #interceptCreateAdditionalOrNode(ITreeNode, boolean)}
 */
@ConfigOperation
@Order(140)
protected EitherOrNode execCreateAdditionalOrNode(ITreeNode eitherOrNode, boolean negated) {
    EitherOrNode node = new EitherOrNode(this, false);
    node.setNegative(negated);
    node.setStatus(ITreeNode.STATUS_INSERTED);
    return node;
}
Also used : EitherOrNode(org.eclipse.scout.rt.client.ui.form.fields.composer.node.EitherOrNode) Order(org.eclipse.scout.rt.platform.Order) ConfigOperation(org.eclipse.scout.rt.platform.annotations.ConfigOperation)

Example 5 with EitherOrNode

use of org.eclipse.scout.rt.client.ui.form.fields.composer.node.EitherOrNode 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)

Aggregations

EitherOrNode (org.eclipse.scout.rt.client.ui.form.fields.composer.node.EitherOrNode)11 ITreeNode (org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode)6 ArrayList (java.util.ArrayList)3 ComposerEitherOrNodeData (org.eclipse.scout.rt.shared.data.form.fields.composer.ComposerEitherOrNodeData)3 TreeNodeData (org.eclipse.scout.rt.shared.data.form.fields.treefield.TreeNodeData)3 Test (org.junit.Test)3 AttributeNode (org.eclipse.scout.rt.client.ui.form.fields.composer.node.AttributeNode)2 EntityNode (org.eclipse.scout.rt.client.ui.form.fields.composer.node.EntityNode)2 Order (org.eclipse.scout.rt.platform.Order)2 ConfigOperation (org.eclipse.scout.rt.platform.annotations.ConfigOperation)2 IDataModelAttributeOp (org.eclipse.scout.rt.shared.data.model.IDataModelAttributeOp)2 Element (org.w3c.dom.Element)2 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 AttributePath (org.eclipse.scout.rt.shared.data.model.AttributePath)1 EntityPath (org.eclipse.scout.rt.shared.data.model.EntityPath)1 IDataModelAttribute (org.eclipse.scout.rt.shared.data.model.IDataModelAttribute)1 IDataModelEntity (org.eclipse.scout.rt.shared.data.model.IDataModelEntity)1