Search in sources :

Example 1 with ComposerEitherOrNodeData

use of org.eclipse.scout.rt.shared.data.form.fields.composer.ComposerEitherOrNodeData in project scout.rt by eclipse.

the class FormDataStatementBuilder method buildComposerOrNodes.

/**
 * do not use or override this method, it is protected for unit test purposes
 */
protected EntityContribution buildComposerOrNodes(List<ComposerEitherOrNodeData> nodes, EntityStrategy entityStrategy, AttributeStrategy attributeStrategy) {
    EntityContribution contrib = new EntityContribution();
    // check if only one condition
    StringBuilder buf = new StringBuilder();
    int count = 0;
    for (ComposerEitherOrNodeData node : nodes) {
        EntityContribution subContrib = buildTreeNodes(node.getChildNodes(), entityStrategy, attributeStrategy);
        contrib.getFromParts().addAll(subContrib.getFromParts());
        if (subContrib.getWhereParts().size() + subContrib.getHavingParts().size() > 0) {
            if (count > 0) {
                buf.append(" OR ");
                if (node.isNegative()) {
                    buf.append(" NOT ");
                }
            }
            buf.append("(");
            // remove possible outer join signs (+) in where / having constraint
            // this is necessary because outer joins are not allowed in OR clause
            // the removal of outer joins does not influence the result set
            buf.append(CollectionUtility.format(CollectionUtility.combine(subContrib.getWhereParts(), subContrib.getHavingParts()), " AND ").replaceAll("\\(\\+\\)", ""));
            buf.append(")");
            count++;
        }
    }
    if (count > 0) {
        if (count > 1) {
            buf.insert(0, "(");
            buf.append(")");
            contrib.getWhereParts().add(buf.toString());
        } else {
            String s = buf.toString();
            if (s.matches("\\(.*\\)")) {
                s = s.substring(1, s.length() - 1).trim();
            }
            contrib.getWhereParts().add(s);
        }
    }
    return contrib;
}
Also used : ComposerEitherOrNodeData(org.eclipse.scout.rt.shared.data.form.fields.composer.ComposerEitherOrNodeData)

Example 2 with ComposerEitherOrNodeData

use of org.eclipse.scout.rt.shared.data.form.fields.composer.ComposerEitherOrNodeData in project scout.rt by eclipse.

the class FormDataStatementBuilder method buildComposerEntityEitherOrSplit.

/**
 * only used with strategy {@link EntityStrategy#BuildConstraints}
 * <p>
 * do not use or override this method, it is protected for unit test purposes
 */
protected String buildComposerEntityEitherOrSplit(EntityStrategy entityStrategy, String baseStm, boolean negative, List<TreeNodeData> childParts) {
    if (entityStrategy != EntityStrategy.BuildConstraints) {
        return null;
    }
    List<List<ComposerEitherOrNodeData>> orBlocks = new ArrayList<List<ComposerEitherOrNodeData>>();
    List<TreeNodeData> otherParts = new ArrayList<TreeNodeData>();
    List<ComposerEitherOrNodeData> currentOrBlock = new ArrayList<ComposerEitherOrNodeData>();
    for (TreeNodeData ch : childParts) {
        if (ch instanceof ComposerEitherOrNodeData) {
            ComposerEitherOrNodeData orData = (ComposerEitherOrNodeData) ch;
            if (orData.isBeginOfEitherOr()) {
                if (currentOrBlock.size() > 0) {
                    orBlocks.add(new ArrayList<ComposerEitherOrNodeData>(currentOrBlock));
                }
                currentOrBlock.clear();
            }
            currentOrBlock.add(orData);
        } else {
            otherParts.add(ch);
        }
    }
    if (currentOrBlock.size() > 0) {
        orBlocks.add(new ArrayList<ComposerEitherOrNodeData>(currentOrBlock));
        currentOrBlock.clear();
    }
    // 
    if (orBlocks.size() > 0) {
        StringBuilder blockBuf = new StringBuilder();
        int blockCount = 0;
        for (List<ComposerEitherOrNodeData> list : orBlocks) {
            int elemCount = 0;
            StringBuilder elemBuf = new StringBuilder();
            for (ComposerEitherOrNodeData orData : list) {
                ArrayList<TreeNodeData> subList = new ArrayList<TreeNodeData>();
                subList.addAll(otherParts);
                subList.addAll(orData.getChildNodes());
                String s = buildComposerEntityEitherOrSplit(entityStrategy, baseStm, negative ^ orData.isNegative(), subList);
                if (s != null) {
                    if (elemCount > 0) {
                        elemBuf.append(" OR ");
                    }
                    elemBuf.append(" ( ");
                    elemBuf.append(s);
                    elemBuf.append(" ) ");
                    elemCount++;
                }
            }
            if (elemCount > 0) {
                if (blockCount > 0) {
                    blockBuf.append(" AND ");
                }
                blockBuf.append(" ( ");
                blockBuf.append(elemBuf.toString());
                blockBuf.append(" ) ");
                blockCount++;
            }
        }
        if (blockCount > 0) {
            return blockBuf.toString();
        }
        return null;
    }
    return buildComposerEntityZeroTraversingSplit(entityStrategy, baseStm, negative, childParts);
}
Also used : TreeNodeData(org.eclipse.scout.rt.shared.data.form.fields.treefield.TreeNodeData) ArrayList(java.util.ArrayList) ComposerEitherOrNodeData(org.eclipse.scout.rt.shared.data.form.fields.composer.ComposerEitherOrNodeData) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with ComposerEitherOrNodeData

use of org.eclipse.scout.rt.shared.data.form.fields.composer.ComposerEitherOrNodeData 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 ComposerEitherOrNodeData

use of org.eclipse.scout.rt.shared.data.form.fields.composer.ComposerEitherOrNodeData 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)

Example 5 with ComposerEitherOrNodeData

use of org.eclipse.scout.rt.shared.data.form.fields.composer.ComposerEitherOrNodeData in project scout.rt by eclipse.

the class ComposerFieldTest method testImportEitherOrNode.

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

ComposerEitherOrNodeData (org.eclipse.scout.rt.shared.data.form.fields.composer.ComposerEitherOrNodeData)5 TreeNodeData (org.eclipse.scout.rt.shared.data.form.fields.treefield.TreeNodeData)4 ITreeNode (org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode)3 EitherOrNode (org.eclipse.scout.rt.client.ui.form.fields.composer.node.EitherOrNode)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)1 List (java.util.List)1