Search in sources :

Example 31 with OutputXmlTree

use of org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree in project tdi-studio-se by Talend.

the class DropContextAnalyzer method checkDropOutputDocChildValid.

private boolean checkDropOutputDocChildValid(Object targetModel) {
    OutputTreeNode outputNode = (OutputTreeNode) targetModel;
    NodeType nodeType = outputNode.getNodeType();
    if (outputNode.eContainer() instanceof OutputTreeNode && nodeType != NodeType.ATTRIBUT && nodeType != NodeType.NAME_SPACE) {
        dropType = DropType.DROP_OUTPUT_DOC_CHILD;
        return true;
    } else if (outputNode.eContainer() instanceof OutputXmlTree && !XmlMapUtil.DOCUMENT.equals(outputNode.getType())) {
        dropType = DropType.DROP_INSERT_OUTPUT;
        return true;
    }
    return false;
}
Also used : NodeType(org.talend.designer.xmlmap.model.emf.xmlmap.NodeType) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree)

Example 32 with OutputXmlTree

use of org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree in project tdi-studio-se by Talend.

the class MapDataHelper method rebuildModelOutputs.

public void rebuildModelOutputs(List<IMetadataTable> outputMetadataTables, XmlMapData mapData) {
    for (IMetadataTable meatadataTable : outputMetadataTables) {
        String name = meatadataTable.getTableName();
        OutputXmlTree outputTree = null;
        for (OutputXmlTree out : mapData.getOutputTrees()) {
            if (out.getName() != null && out.getName().equals(name)) {
                outputTree = out;
                break;
            }
        }
        if (outputTree == null) {
            outputTree = XmlmapFactory.eINSTANCE.createOutputXmlTree();
            outputTree.setName(name);
            mapData.getOutputTrees().add(outputTree);
        }
        List<IMetadataColumn> listColumns = meatadataTable.getListColumns();
        if (listColumns != null) {
            EList<OutputTreeNode> nodes = outputTree.getNodes();
            for (int i = 0; i < listColumns.size(); i++) {
                IMetadataColumn column = listColumns.get(i);
                OutputTreeNode found = null;
                int j = 0;
                for (; j < nodes.size(); j++) {
                    OutputTreeNode node = nodes.get(j);
                    if (node.getName() != null && node.getName().equals(column.getLabel())) {
                        found = node;
                        break;
                    }
                }
                if (found != null) {
                    // set in case talend type changed in metadata
                    found.setType(column.getTalendType());
                    if (i != j) {
                        // do switch to keep the same sequence
                        OutputTreeNode temp = nodes.get(j);
                        nodes.remove(j);
                        nodes.add(i, temp);
                    }
                } else {
                    found = XmlmapFactory.eINSTANCE.createOutputTreeNode();
                    found.setName(column.getLabel());
                    found.setType(column.getTalendType());
                    found.setNullable(column.isNullable());
                    found.setXpath(XmlMapUtil.getXPath(outputTree.getName(), found.getName(), found.getNodeType()));
                    nodes.add(i, found);
                }
                // add a default root for document
                if (XmlMapUtil.DOCUMENT.equals(found.getType())) {
                    EList<TreeNode> children = found.getChildren();
                    if (children.isEmpty()) {
                        XmlMapUtil.detachConnectionsSouce(found, mapData);
                        TreeNode treeRoot = XmlmapFactory.eINSTANCE.createOutputTreeNode();
                        treeRoot.setName("root");
                        treeRoot.setType(XmlMapUtil.DEFAULT_DATA_TYPE);
                        treeRoot.setNodeType(NodeType.ELEMENT);
                        treeRoot.setXpath(XmlMapUtil.getXPath(found.getXpath(), treeRoot.getName(), treeRoot.getNodeType()));
                        treeRoot.setLoop(true);
                        treeRoot.setMain(true);
                        children.add(treeRoot);
                    }
                } else // remove children and connections for children if not document
                {
                    EList<TreeNode> children = found.getChildren();
                    if (!children.isEmpty()) {
                        XmlMapUtil.detachNodeConnections(found, mapData, true);
                        found.getChildren().clear();
                    }
                }
            }
            if (nodes.size() > listColumns.size()) {
                List unUsed = new ArrayList();
                for (int i = listColumns.size(); i < nodes.size(); i++) {
                    OutputTreeNode node = nodes.get(i);
                    XmlMapUtil.detachConnectionsSouce(node, mapData);
                    unUsed.add(node);
                }
                nodes.removeAll(unUsed);
            }
        }
        mapData.getOutputTrees().add(outputTree);
        // re-build the connections in case any unnecessary connections are created because of previous bugs and
        // can't be deleted
        rebuildOutputNodesConnections(outputTree.getNodes(), mapData);
    }
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) ArrayList(java.util.ArrayList) List(java.util.List) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode)

Example 33 with OutputXmlTree

use of org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree in project tdi-studio-se by Talend.

the class XMLMapperHelper method hasAggregateColumn.

private static boolean hasAggregateColumn(final INode xmlMapperNode) {
    boolean hasAggregateColumn = false;
    List<? extends IConnection> outConnections = (List<? extends IConnection>) xmlMapperNode.getOutgoingConnections();
    XmlMapData xmlMapData = (XmlMapData) ElementParameterParser.getObjectValueXMLTree(xmlMapperNode);
    if (xmlMapData != null && outConnections != null && outConnections.size() > 0) {
        List<OutputXmlTree> outputTables = xmlMapData.getOutputTrees();
        HashMap<String, IConnection> hNameToConnection = new HashMap<String, IConnection>();
        for (IConnection connection : outConnections) {
            hNameToConnection.put(connection.getName(), connection);
        }
        for (OutputXmlTree outputTable : outputTables) {
            String tableName = outputTable.getName();
            IConnection connection = hNameToConnection.get(tableName);
            if (connection == null) {
                continue;
            }
            List<TreeNode> editableNodes = new ArrayList<TreeNode>();
            for (TreeNode node : outputTable.getNodes()) {
                getEditableNodes(node, editableNodes);
            }
            for (TreeNode node : editableNodes) {
                if (((OutputTreeNode) node).isAggregate()) {
                    hasAggregateColumn = true;
                    break;
                }
            }
        }
    }
    return hasAggregateColumn;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IConnection(org.talend.core.model.process.IConnection) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) EList(org.eclipse.emf.common.util.EList) ArrayList(java.util.ArrayList) List(java.util.List) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree) XmlMapData(org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData)

Example 34 with OutputXmlTree

use of org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree in project tdi-studio-se by Talend.

the class XMLMapperHelper method hasMultiLoops.

private static boolean hasMultiLoops(final INode xmlMapperNode) {
    boolean hasMultiLoops = false;
    List<? extends IConnection> outConnections = (List<? extends IConnection>) xmlMapperNode.getOutgoingConnections();
    XmlMapData xmlMapData = (XmlMapData) ElementParameterParser.getObjectValueXMLTree(xmlMapperNode);
    if (xmlMapData != null && outConnections != null && outConnections.size() > 0) {
        List<OutputXmlTree> outputTables = xmlMapData.getOutputTrees();
        HashMap<String, IConnection> hNameToConnection = new HashMap<String, IConnection>();
        for (IConnection connection : outConnections) {
            hNameToConnection.put(connection.getName(), connection);
        }
        for (OutputXmlTree outputTable : outputTables) {
            String tableName = outputTable.getName();
            IConnection connection = hNameToConnection.get(tableName);
            if (connection == null) {
                continue;
            }
            if (outputTable.isMultiLoops()) {
                hasMultiLoops = true;
                break;
            }
        }
    }
    return hasMultiLoops;
}
Also used : HashMap(java.util.HashMap) EList(org.eclipse.emf.common.util.EList) ArrayList(java.util.ArrayList) List(java.util.List) IConnection(org.talend.core.model.process.IConnection) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree) XmlMapData(org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData)

Example 35 with OutputXmlTree

use of org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree in project tdi-studio-se by Talend.

the class XMLMapperHelper method hasAllInOne.

private static boolean hasAllInOne(final INode xmlMapperNode) {
    boolean hasAllInOne = false;
    List<? extends IConnection> outConnections = (List<? extends IConnection>) xmlMapperNode.getOutgoingConnections();
    XmlMapData xmlMapData = (XmlMapData) ElementParameterParser.getObjectValueXMLTree(xmlMapperNode);
    if (xmlMapData != null && outConnections != null && outConnections.size() > 0) {
        List<OutputXmlTree> outputTables = xmlMapData.getOutputTrees();
        HashMap<String, IConnection> hNameToConnection = new HashMap<String, IConnection>();
        for (IConnection connection : outConnections) {
            hNameToConnection.put(connection.getName(), connection);
        }
        for (OutputXmlTree outputTable : outputTables) {
            String tableName = outputTable.getName();
            IConnection connection = hNameToConnection.get(tableName);
            if (connection == null) {
                continue;
            }
            if (outputTable.isAllInOne()) {
                hasAllInOne = true;
                break;
            }
        }
    }
    return hasAllInOne;
}
Also used : HashMap(java.util.HashMap) EList(org.eclipse.emf.common.util.EList) ArrayList(java.util.ArrayList) List(java.util.List) IConnection(org.talend.core.model.process.IConnection) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree) XmlMapData(org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData)

Aggregations

OutputXmlTree (org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree)49 OutputTreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode)30 InputXmlTree (org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree)26 TreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode)26 ArrayList (java.util.ArrayList)17 XmlMapData (org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData)15 AbstractInOutTree (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree)13 VarNode (org.talend.designer.xmlmap.model.emf.xmlmap.VarNode)12 List (java.util.List)11 InputLoopNodesTable (org.talend.designer.xmlmap.model.emf.xmlmap.InputLoopNodesTable)9 VarTable (org.talend.designer.xmlmap.model.emf.xmlmap.VarTable)9 OutputXmlTreeEditPart (org.talend.designer.xmlmap.parts.OutputXmlTreeEditPart)7 EList (org.eclipse.emf.common.util.EList)6 AbstractNode (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode)6 HashMap (java.util.HashMap)5 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)5 Connection (org.talend.designer.xmlmap.model.emf.xmlmap.Connection)5 InputXmlTreeEditPart (org.talend.designer.xmlmap.parts.InputXmlTreeEditPart)4 EditPart (org.eclipse.gef.EditPart)3 Command (org.eclipse.gef.commands.Command)3