Search in sources :

Example 6 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 execCreateEitherNode.

/**
 * 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 #interceptCreateEitherNode(ITreeNode, boolean)}
 */
@ConfigOperation
@Order(130)
protected EitherOrNode execCreateEitherNode(ITreeNode parentNode, boolean negated) {
    EitherOrNode node = new EitherOrNode(this, true);
    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 7 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 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 8 with EitherOrNode

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

Example 9 with EitherOrNode

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

the class ComposerDisplayTextBuilder method visitOrNodes.

private void visitOrNodes(List<? extends EitherOrNode> nodes, StringBuilder buf, String prefix) {
    for (EitherOrNode node : nodes) {
        buf.append(prefix);
        buf.append(node.getCell().getText());
        buf.append("\n");
        // add children
        visitAndNodes(node.getChildNodes(), buf, prefix + " ");
    }
}
Also used : EitherOrNode(org.eclipse.scout.rt.client.ui.form.fields.composer.node.EitherOrNode)

Example 10 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 testImportEitherOrOrNode.

@Test
public void testImportEitherOrOrNode() throws Exception {
    // setup field data
    ComposerEitherOrNodeData eitherNodeData = new ComposerEitherOrNodeData();
    eitherNodeData.setBeginOfEitherOr(true);
    ComposerEitherOrNodeData or1NodeData = new ComposerEitherOrNodeData();
    ComposerEitherOrNodeData or2NodeData = new ComposerEitherOrNodeData();
    List<TreeNodeData> rootList = Arrays.<TreeNodeData>asList(eitherNodeData, or1NodeData, or2NodeData);
    m_fieldData.setRoots(rootList);
    // import
    m_composerField.importFormFieldData(m_fieldData, false);
    // verify import
    ITreeNode rootNode = m_composerField.getTree().getRootNode();
    assertEquals(3, rootNode.getChildNodeCount());
    // 
    ITreeNode eitherNode = rootNode.getChildNode(0);
    assertTrue(eitherNode instanceof EitherOrNode);
    assertTrue(((EitherOrNode) eitherNode).isBeginOfEitherOr());
    assertFalse(((EitherOrNode) eitherNode).isNegative());
    // 
    ITreeNode or1Node = rootNode.getChildNode(1);
    assertTrue(or1Node instanceof EitherOrNode);
    assertFalse(((EitherOrNode) or1Node).isBeginOfEitherOr());
    assertFalse(((EitherOrNode) or1Node).isNegative());
    // 
    ITreeNode or2Node = rootNode.getChildNode(2);
    assertTrue(or2Node instanceof EitherOrNode);
    assertFalse(((EitherOrNode) or2Node).isBeginOfEitherOr());
    assertFalse(((EitherOrNode) or2Node).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)

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