Search in sources :

Example 1 with TreeNodeData

use of org.eclipse.scout.rt.shared.data.form.fields.treefield.TreeNodeData in project scout.rt by eclipse.

the class AbstractTree method exportTreeNodeDataRec.

private void exportTreeNodeDataRec(List<ITreeNode> nodes, AbstractTreeFieldData treeData, TreeNodeData parentNodeData) {
    ArrayList<TreeNodeData> nodeDataList = new ArrayList<TreeNodeData>(nodes.size());
    for (ITreeNode node : nodes) {
        TreeNodeData nodeData = exportTreeNodeData(node, treeData);
        if (nodeData != null) {
            exportTreeNodeDataRec(node.getChildNodes(), treeData, nodeData);
            nodeDataList.add(nodeData);
        }
    }
    if (parentNodeData != null) {
        parentNodeData.setChildNodes(nodeDataList);
    } else {
        treeData.setRoots(nodeDataList);
    }
}
Also used : TreeNodeData(org.eclipse.scout.rt.shared.data.form.fields.treefield.TreeNodeData) ArrayList(java.util.ArrayList)

Example 2 with TreeNodeData

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

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

use of org.eclipse.scout.rt.shared.data.form.fields.treefield.TreeNodeData in project scout.rt by eclipse.

the class FormDataStatementBuilder method buildComposerEntityZeroTraversingSplit.

/**
 * only used with strategy {@link EntityStrategy#BuildConstraints} and one-to-many entity relation
 * <p>
 * do not use or override this method, it is protected for unit test purposes
 */
protected String buildComposerEntityZeroTraversingSplit(EntityStrategy entityStrategy, String baseStm, boolean negative, List<TreeNodeData> childParts) {
    if (entityStrategy != EntityStrategy.BuildConstraints) {
        return null;
    }
    ArrayList<TreeNodeData> nonZeroChildren = new ArrayList<TreeNodeData>(2);
    for (TreeNodeData ch : childParts) {
        switch(getAttributeKind(ch)) {
            case Undefined:
            case NonAggregation:
            case NonAggregationNonZeroTraversing:
            case AggregationNonZeroTraversing:
                {
                    nonZeroChildren.add(ch);
                    break;
                }
        }
    }
    // 
    // create entity part 1
    String entityPart1 = buildComposerEntityUnit(entityStrategy, baseStm, negative, childParts);
    // create negated entity part 2
    String entityPart2 = null;
    if (nonZeroChildren.size() < childParts.size()) {
        // negated negation
        entityPart2 = buildComposerEntityUnit(entityStrategy, baseStm, !negative, nonZeroChildren);
    }
    // combine parts
    if (entityPart2 != null) {
        return " ( " + entityPart1 + " OR " + entityPart2 + " ) ";
    }
    return entityPart1;
}
Also used : TreeNodeData(org.eclipse.scout.rt.shared.data.form.fields.treefield.TreeNodeData) ArrayList(java.util.ArrayList)

Example 5 with TreeNodeData

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

TreeNodeData (org.eclipse.scout.rt.shared.data.form.fields.treefield.TreeNodeData)6 ComposerEitherOrNodeData (org.eclipse.scout.rt.shared.data.form.fields.composer.ComposerEitherOrNodeData)4 ArrayList (java.util.ArrayList)3 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 List (java.util.List)1