Search in sources :

Example 16 with VarNode

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

the class InsertNewColumnCommand method execute.

@Override
public void execute() {
    if (rq == null || objects.getToTransfer() == null || targetEditPart == null || dropType == null) {
        return;
    }
    Object targetModel = targetEditPart.getModel();
    for (Object obj : objects.getToTransfer()) {
        AbstractNode createdNode = rq.getNewObject();
        // INPUT => OUTPUT INSERT
        if (objects.getType() == TransferdType.INPUT) {
            TreeNodeEditPart part = (TreeNodeEditPart) obj;
            TreeNode sourceNode = (TreeNode) part.getModel();
            String expression = XmlMapUtil.convertToExpression(sourceNode.getXpath());
            switch(dropType) {
                case DROP_INSERT_OUTPUT:
                    int index = -1;
                    OutputXmlTree outputTree = null;
                    if (targetModel instanceof OutputTreeNode) {
                        OutputTreeNode targetNode = (OutputTreeNode) targetModel;
                        if (targetNode.eContainer() instanceof OutputXmlTree) {
                            outputTree = (OutputXmlTree) targetNode.eContainer();
                            index = outputTree.getNodes().indexOf(targetNode);
                        }
                    } else if (targetModel instanceof OutputXmlTree) {
                        outputTree = (OutputXmlTree) targetModel;
                    }
                    if (outputTree != null) {
                        boolean fillNode = fillTreeNode(outputTree.getNodes(), sourceNode, outputTree.getName(), expression, (OutputTreeNode) createdNode);
                        if (!fillNode) {
                            return;
                        }
                        if (index != -1) {
                            outputTree.getNodes().add(index, (OutputTreeNode) createdNode);
                        } else {
                            outputTree.getNodes().add((OutputTreeNode) createdNode);
                        }
                        createConnection(sourceNode, createdNode);
                        AbstractInOutTree abstractTree = XmlMapUtil.getAbstractInOutTree(sourceNode);
                        createOutputMetadataColumn(abstractTree.getName(), outputTree.getName(), sourceNode, createdNode.getName(), index);
                    }
                    break;
                case DROP_INSERT_VAR:
                    VarNode targetVar = (VarNode) targetModel;
                    VarNode varNode = (VarNode) createdNode;
                    if (targetVar.eContainer() instanceof VarTable) {
                        VarTable varTable = (VarTable) targetVar.eContainer();
                        String validSourceName = validSourceNodeName(varTable.getNodes(), sourceNode);
                        String name = getUniqueTableEntry(varTable.getNodes(), validSourceName);
                        varNode.setName(name);
                        varNode.setType(sourceNode.getType());
                        varNode.setExpression(expression);
                        varTable.getNodes().add(varTable.getNodes().indexOf(targetVar), varNode);
                        createConnection(sourceNode, createdNode);
                    }
                    break;
                case DROP_INSERT_INPUT:
                    if (targetModel instanceof InputXmlTree) {
                        InputXmlTree inputTree = (InputXmlTree) targetModel;
                        boolean fillNode = fillTreeNode(inputTree.getNodes(), sourceNode, inputTree.getName(), expression, (TreeNode) createdNode);
                        if (!fillNode) {
                            return;
                        }
                        inputTree.getNodes().add((TreeNode) createdNode);
                        createLookupConnection(sourceNode, (TreeNode) createdNode);
                        AbstractInOutTree abstractTree = XmlMapUtil.getAbstractInOutTree(sourceNode);
                        createInputMetadataColumn(abstractTree.getName(), inputTree.getName(), sourceNode, createdNode.getName(), -1);
                    }
                default:
                    break;
            }
        } else // VAR => OUTPUT INSERT
        if (objects.getType() == TransferdType.VAR) {
            VarNodeEditPart part = (VarNodeEditPart) obj;
            VarNode sourceNode = (VarNode) part.getModel();
            //$NON-NLS-1$
            String tableName = "Var";
            if (sourceNode.eContainer() instanceof VarTable) {
                tableName = ((VarTable) sourceNode.eContainer()).getName();
            }
            //$NON-NLS-1$
            String expression = tableName + "." + sourceNode.getName();
            if (dropType == DropType.DROP_INSERT_OUTPUT) {
                int index = -1;
                OutputXmlTree outputTree = null;
                if (targetModel instanceof OutputTreeNode) {
                    OutputTreeNode targetNode = (OutputTreeNode) targetModel;
                    if (targetNode.eContainer() instanceof OutputXmlTree) {
                        outputTree = (OutputXmlTree) targetNode.eContainer();
                        index = outputTree.getNodes().indexOf(targetNode);
                    }
                } else if (targetModel instanceof OutputXmlTree) {
                    outputTree = (OutputXmlTree) targetModel;
                }
                if (outputTree != null) {
                    OutputTreeNode outputNode = (OutputTreeNode) createdNode;
                    String name = getUniqueTableEntry(outputTree.getNodes(), sourceNode.getName());
                    outputNode.setName(name);
                    outputNode.setType(sourceNode.getType());
                    outputNode.setExpression(expression);
                    outputNode.setXpath(XmlMapUtil.getXPath(outputTree.getName(), outputNode.getName(), outputNode.getNodeType()));
                    if (index != -1) {
                        outputTree.getNodes().add(index, (OutputTreeNode) createdNode);
                    } else {
                        outputTree.getNodes().add((OutputTreeNode) createdNode);
                    }
                    createConnection(sourceNode, createdNode);
                    createOutputMetadataColumn(null, outputTree.getName(), sourceNode, createdNode.getName(), index);
                // List<IMetadataTable> metadataTargets = manager.getMapperComponent().getMetadataList();
                // IMetadataTable metadataTarget = null;
                // if (metadataTargets != null) {
                // for (IMetadataTable target : metadataTargets) {
                // if (target.getTableName().equals(outputTree.getName())) {
                // metadataTarget = target;
                // }
                // }
                // if (metadataTarget != null) {
                // IMetadataColumn createNewColumn = new MetadataColumn();
                // createNewColumn.setLabel(outputNode.getName());
                // createNewColumn.setTalendType(outputNode.getType());
                // createNewColumn.setNullable(true);
                // metadataTarget.getListColumns().add(createNewColumn);
                // }
                // }
                }
            }
        }
    }
    switch(dropType) {
        case DROP_INSERT_OUTPUT:
            manager.getMapperUI().getTabFolderEditors().getOutputMetaEditorView().getTableViewerCreator().refresh();
        case DROP_INSERT_INPUT:
            manager.getMapperUI().getTabFolderEditors().getOutputMetaEditorView().getTableViewerCreator().refresh();
    }
}
Also used : VarNode(org.talend.designer.xmlmap.model.emf.xmlmap.VarNode) VarNodeEditPart(org.talend.designer.xmlmap.parts.VarNodeEditPart) AbstractNode(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode) AbstractInOutTree(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNodeEditPart(org.talend.designer.xmlmap.parts.TreeNodeEditPart) VarTable(org.talend.designer.xmlmap.model.emf.xmlmap.VarTable) InputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) TransferedObject(org.talend.designer.gefabstractmap.dnd.TransferedObject) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree)

Example 17 with VarNode

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

the class XmlMapService method checkXMLMapDifferents.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.service.IXmlMapService#checkXMLMapDifferents(org.talend.core.model.process.INode,
     * org.talend.core.model.process.INode)
     */
@Override
public boolean checkXMLMapDifferents(INode testNode, INode originalNode) {
    AbstractExternalData oriExternalData = originalNode.getExternalNode().getExternalEmfData();
    AbstractExternalData testExternalData = testNode.getExternalNode().getExternalEmfData();
    if (oriExternalData == null && testExternalData == null) {
        return false;
    }
    if (oriExternalData == null || testExternalData == null) {
        return true;
    }
    if (!(oriExternalData instanceof XmlMapData) || !(testExternalData instanceof XmlMapData)) {
        return false;
    }
    Map<String, String> inputConnNameMap = getInputConnectionNameMap(testNode);
    XmlMapData oriXmlData = (XmlMapData) oriExternalData;
    XmlMapData testXmlData = (XmlMapData) testExternalData;
    EList<InputXmlTree> oriInputs = oriXmlData.getInputTrees();
    EList<OutputXmlTree> oriOutputs = oriXmlData.getOutputTrees();
    EList<VarTable> oriVars = oriXmlData.getVarTables();
    EList<InputXmlTree> testInputs = testXmlData.getInputTrees();
    EList<OutputXmlTree> testOutputs = testXmlData.getOutputTrees();
    EList<VarTable> testVars = testXmlData.getVarTables();
    if (oriInputs.size() != testInputs.size()) {
        return true;
    }
    if (oriOutputs.size() != testOutputs.size()) {
        return true;
    }
    if (oriVars.size() != testVars.size()) {
        return true;
    }
    for (InputXmlTree oriInput : oriInputs) {
        String oriName = oriInput.getName();
        InputXmlTree testInput = null;
        for (InputXmlTree input : testInputs) {
            if (input.getName().equals(oriName)) {
                testInput = input;
                break;
            }
        }
        if (testInput == null) {
            testInput = getInputXmlTree(testNode, testInputs, oriName);
        }
        if (testInput == null) {
            return true;
        }
        if (oriInput.isActivateExpressionFilter() != testInput.isActivateExpressionFilter()) {
            return true;
        }
        if (oriInput.getExpressionFilter() != testInput.getExpressionFilter()) {
            return true;
        }
        if (oriInput.isMinimized() != testInput.isMinimized()) {
            return true;
        }
        if (oriInput.isActivateCondensedTool() != testInput.isActivateCondensedTool()) {
            return true;
        }
        EList<TreeNode> oriEntrys = oriInput.getNodes();
        EList<TreeNode> testEntrys = testInput.getNodes();
        if (oriEntrys.size() != testEntrys.size()) {
            return true;
        }
        for (TreeNode oriEntry : oriEntrys) {
            String oriEntryName = oriEntry.getName();
            boolean found = false;
            for (TreeNode testEntry : testEntrys) {
                if (oriEntryName.equals(testEntry.getName())) {
                    found = true;
                    if (checkExpression(oriEntry.getExpression(), testEntry.getExpression(), inputConnNameMap)) {
                        return true;
                    }
                    break;
                }
            }
            if (!found) {
                return true;
            }
        }
    }
    for (OutputXmlTree oriOutput : oriOutputs) {
        String oriName = oriOutput.getName();
        OutputXmlTree testOutput = null;
        for (OutputXmlTree output : testOutputs) {
            if (output.getName().equals(oriName)) {
                testOutput = output;
                break;
            }
        }
        if (testOutput == null) {
            testOutput = getOutputXmlTree(testNode, testOutputs, oriName);
        }
        if (testOutput == null) {
            return true;
        }
        if (oriOutput.isActivateExpressionFilter() != testOutput.isActivateExpressionFilter()) {
            return true;
        }
        if (oriOutput.getExpressionFilter() != testOutput.getExpressionFilter()) {
            return true;
        }
        if (oriOutput.isMinimized() != testOutput.isMinimized()) {
            return true;
        }
        if (oriOutput.isActivateCondensedTool() != testOutput.isActivateCondensedTool()) {
            return true;
        }
        EList<OutputTreeNode> oriEntrys = oriOutput.getNodes();
        EList<OutputTreeNode> testEntrys = testOutput.getNodes();
        if (oriEntrys.size() != testEntrys.size()) {
            return true;
        }
        for (OutputTreeNode oriEntry : oriEntrys) {
            String oriEntryName = oriEntry.getName();
            boolean found = false;
            for (OutputTreeNode testEntry : testEntrys) {
                if (oriEntryName.equals(testEntry.getName())) {
                    found = true;
                    if (found) {
                        if (checkChildOutputTreeNode(oriEntry, testEntry, inputConnNameMap)) {
                            return true;
                        }
                    }
                    break;
                }
            }
            if (!found) {
                return true;
            }
        }
    }
    for (VarTable oriVar : oriVars) {
        String oriName = oriVar.getName();
        VarTable testVar = null;
        for (VarTable var : testVars) {
            if (var.getName().equals(oriName)) {
                testVar = var;
                break;
            }
        }
        if (testVar == null) {
            return true;
        }
        if (oriVar.isMinimized() != testVar.isMinimized()) {
            return true;
        }
        EList<VarNode> oriEntrys = oriVar.getNodes();
        EList<VarNode> testEntrys = testVar.getNodes();
        if (oriEntrys.size() != testEntrys.size()) {
            return true;
        }
        for (VarNode oriEntry : oriEntrys) {
            String oriEntryName = oriEntry.getName();
            boolean found = false;
            for (VarNode testEntry : testEntrys) {
                if (oriEntryName.equals(testEntry.getName())) {
                    found = true;
                    if (checkExpression(oriEntry.getExpression(), testEntry.getExpression(), inputConnNameMap)) {
                        return true;
                    }
                }
            }
            if (!found) {
                return true;
            }
        }
    }
    return false;
}
Also used : VarNode(org.talend.designer.xmlmap.model.emf.xmlmap.VarNode) AbstractExternalData(org.talend.designer.core.model.utils.emf.talendfile.AbstractExternalData) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) InputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree) VarTable(org.talend.designer.xmlmap.model.emf.xmlmap.VarTable) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree) XmlMapData(org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData)

Example 18 with VarNode

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

the class XmlMapService method externalEmfDataClone.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.core.service.IXmlMapService#externalEmfDataClone(org.talend.designer.core.model.utils.emf.talendfile
     * .AbstractExternalData)
     */
@Override
public AbstractExternalData externalEmfDataClone(AbstractExternalData externalEmfData) {
    if (!(externalEmfData instanceof XmlMapData)) {
        return externalEmfData;
    }
    Map<EObject, EObject> nodeMaps = new HashMap<EObject, EObject>();
    XmlMapData newXmlMapData = XmlmapFactory.eINSTANCE.createXmlMapData();
    XmlMapData xmlMapData = (XmlMapData) externalEmfData;
    EList<InputXmlTree> oriInputs = xmlMapData.getInputTrees();
    EList<OutputXmlTree> oriOutputs = xmlMapData.getOutputTrees();
    EList<VarTable> oriVars = xmlMapData.getVarTables();
    EList<IConnection> oriConns = xmlMapData.getConnections();
    for (IConnection oriConn : oriConns) {
        if (oriConn instanceof INodeConnection) {
            AbstractNode sourceNode = ((INodeConnection) oriConn).getSource();
            AbstractNode targetNode = ((INodeConnection) oriConn).getTarget();
            EObject source = null;
            if (nodeMaps.get(sourceNode) != null) {
                source = nodeMaps.get(sourceNode);
            } else {
                source = cloneTreeNode(sourceNode);
                nodeMaps.put(sourceNode, source);
            }
            EObject target = null;
            if (nodeMaps.get(targetNode) != null) {
                target = nodeMaps.get(targetNode);
            } else {
                target = cloneTreeNode(targetNode);
                nodeMaps.put(targetNode, target);
            }
            if (oriConn instanceof Connection) {
                new XmlMapConnectionBuilder().createConnection((AbstractNode) source, (AbstractNode) target, newXmlMapData);
            } else if (oriConn instanceof LookupConnection) {
                new XmlMapConnectionBuilder().createLookupConnection((TreeNode) source, (TreeNode) target, newXmlMapData);
            }
        } else if (oriConn instanceof FilterConnection) {
            AbstractNode sourceNode = ((FilterConnection) oriConn).getSource();
            AbstractInOutTree targetNode = ((FilterConnection) oriConn).getTarget();
            EObject source = null;
            if (nodeMaps.get(sourceNode) != null) {
                source = nodeMaps.get(sourceNode);
            } else {
                source = cloneTreeNode(sourceNode);
                nodeMaps.put(sourceNode, source);
            }
            EObject target = null;
            if (nodeMaps.get(targetNode) != null) {
                target = nodeMaps.get(targetNode);
            } else {
                target = cloneTreeNode(targetNode);
                nodeMaps.put(targetNode, target);
            }
            new XmlMapConnectionBuilder().createFilterConnection((AbstractNode) source, (AbstractInOutTree) target, newXmlMapData);
        }
    }
    for (InputXmlTree inputXml : oriInputs) {
        InputXmlTree newInputXml = null;
        if (nodeMaps.get(inputXml) == null) {
            newInputXml = (InputXmlTree) cloneTreeNode(inputXml);
        } else {
            newInputXml = (InputXmlTree) nodeMaps.get(inputXml);
        }
        if (inputXml.getNodes() != null) {
            for (TreeNode treeNode : inputXml.getNodes()) {
                EObject obj = nodeMaps.get(treeNode);
                if ((obj != null) && !newInputXml.getNodes().contains(obj)) {
                    newInputXml.getNodes().add((TreeNode) obj);
                }
            }
        }
        if (!newXmlMapData.getInputTrees().contains(newInputXml)) {
            newXmlMapData.getInputTrees().add(newInputXml);
        }
        nodeMaps.put(inputXml, newInputXml);
    }
    for (OutputXmlTree outputXml : oriOutputs) {
        OutputXmlTree newOutputXml = null;
        if (nodeMaps.get(outputXml) == null) {
            newOutputXml = (OutputXmlTree) cloneTreeNode(outputXml);
        } else {
            newOutputXml = (OutputXmlTree) nodeMaps.get(outputXml);
        }
        if (outputXml.getNodes() != null) {
            for (OutputTreeNode treeNode : outputXml.getNodes()) {
                EObject obj = nodeMaps.get(treeNode);
                if ((obj != null) && !newOutputXml.getNodes().contains(obj)) {
                    newOutputXml.getNodes().add((OutputTreeNode) obj);
                }
            }
        }
        // }
        if (!newXmlMapData.getOutputTrees().contains(newOutputXml)) {
            newXmlMapData.getOutputTrees().add(newOutputXml);
        }
        nodeMaps.put(outputXml, newOutputXml);
    }
    for (VarTable varXml : oriVars) {
        VarTable newVarXml = null;
        if (nodeMaps.get(varXml) == null) {
            newVarXml = XmlmapFactory.eINSTANCE.createVarTable();
            newVarXml.setMinimized(varXml.isMinimized());
            newVarXml.setName(varXml.getName());
            if (varXml.getNodes() != null) {
                for (VarNode treeNode : varXml.getNodes()) {
                    EObject obj = nodeMaps.get(treeNode);
                    if (obj != null) {
                        newVarXml.getNodes().add((VarNode) obj);
                    }
                }
            }
            if (!newXmlMapData.getVarTables().contains(newVarXml)) {
                newXmlMapData.getVarTables().add(newVarXml);
            }
            nodeMaps.put(varXml, newVarXml);
        }
    }
    return newXmlMapData;
}
Also used : VarNode(org.talend.designer.xmlmap.model.emf.xmlmap.VarNode) INodeConnection(org.talend.designer.xmlmap.model.emf.xmlmap.INodeConnection) FilterConnection(org.talend.designer.xmlmap.model.emf.xmlmap.FilterConnection) HashMap(java.util.HashMap) AbstractNode(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode) FilterConnection(org.talend.designer.xmlmap.model.emf.xmlmap.FilterConnection) INodeConnection(org.talend.designer.xmlmap.model.emf.xmlmap.INodeConnection) IConnection(org.talend.designer.xmlmap.model.emf.xmlmap.IConnection) Connection(org.talend.designer.xmlmap.model.emf.xmlmap.Connection) LookupConnection(org.talend.designer.xmlmap.model.emf.xmlmap.LookupConnection) AbstractInOutTree(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree) IConnection(org.talend.designer.xmlmap.model.emf.xmlmap.IConnection) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) LookupConnection(org.talend.designer.xmlmap.model.emf.xmlmap.LookupConnection) InputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree) VarTable(org.talend.designer.xmlmap.model.emf.xmlmap.VarTable) XmlMapConnectionBuilder(org.talend.designer.xmlmap.util.XmlMapConnectionBuilder) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) EObject(org.eclipse.emf.ecore.EObject) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree) XmlMapData(org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData)

Example 19 with VarNode

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

the class TreeSettingDirectEditCommand method calculateFilterConnections.

private void calculateFilterConnections(AbstractInOutTree abstractTree, String newValue) {
    XmlMapData mapperData = (XmlMapData) abstractTree.eContainer();
    List<TableEntryLocation> matchedLocations = expressionManager.parseTableEntryLocation((String) newValue);
    EList<FilterConnection> connections = abstractTree.getFilterIncomingConnections();
    List usefullConnections = new ArrayList();
    if (!matchedLocations.isEmpty()) {
        for (int i = 0; i < matchedLocations.size(); i++) {
            TableEntryLocation currentLocation = matchedLocations.get(i);
            boolean found = false;
            for (FilterConnection conn : connections) {
                TableEntryLocation sourceLocation = null;
                if (conn.getSource() instanceof TreeNode) {
                    sourceLocation = expressionManager.parseTableEntryLocation(XmlMapUtil.convertToExpression(((TreeNode) conn.getSource()).getXpath())).get(0);
                } else if (conn.getSource() instanceof VarNode) {
                    VarNode varNode = (VarNode) conn.getSource();
                    sourceLocation = new TableEntryLocation(((VarTable) varNode.eContainer()).getName(), varNode.getName());
                }
                if (currentLocation.equals(sourceLocation)) {
                    found = true;
                    usefullConnections.add(conn);
                    break;
                }
            }
            if (!found) {
                if (mapperData != null) {
                    String convertToXpath = XmlMapUtil.convertToXpath(currentLocation.toString());
                    boolean findFromVar = false;
                    if (abstractTree instanceof OutputXmlTree) {
                        findFromVar = true;
                    }
                    AbstractNode sourceNode = findConnectionSource(mapperData, currentLocation, XmlMapUtil.getXPathLength(convertToXpath), findFromVar);
                    if (sourceNode != null) {
                        FilterConnection connection = null;
                        connection = XmlmapFactory.eINSTANCE.createFilterConnection();
                        sourceNode.getFilterOutGoingConnections().add(connection);
                        abstractTree.getFilterIncomingConnections().add(connection);
                        connection.setSource(sourceNode);
                        connection.setTarget(abstractTree);
                        mapperData.getConnections().add(connection);
                        usefullConnections.add(connection);
                    }
                }
            }
        }
        List<FilterConnection> copyOfConnections = new ArrayList<FilterConnection>(connections);
        copyOfConnections.removeAll(usefullConnections);
        for (FilterConnection connection : copyOfConnections) {
            if (connection.getSource() != null) {
                if (connection.getSource().getFilterOutGoingConnections().contains(connection)) {
                    connection.getSource().getFilterOutGoingConnections().remove(connection);
                    mapperData.getConnections().remove(connection);
                }
            }
        }
        abstractTree.getFilterIncomingConnections().removeAll(copyOfConnections);
    } else if (!connections.isEmpty()) {
        for (FilterConnection connection : connections) {
            if (connection.getSource() != null) {
                if (connection.getSource().getFilterOutGoingConnections().contains(connection)) {
                    connection.getSource().getFilterOutGoingConnections().remove(connection);
                    mapperData.getConnections().remove(connection);
                }
            }
        }
        abstractTree.getFilterIncomingConnections().removeAll(connections);
    }
}
Also used : VarNode(org.talend.designer.xmlmap.model.emf.xmlmap.VarNode) FilterConnection(org.talend.designer.xmlmap.model.emf.xmlmap.FilterConnection) AbstractNode(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode) ArrayList(java.util.ArrayList) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) TableEntryLocation(org.talend.designer.xmlmap.ui.expressionutil.TableEntryLocation) 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 20 with VarNode

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

the class CreateNodeAndConnectionCommand method doUpdate.

// private void createInputLoopTable(TreeNode sourceNode, OutputTreeNode targetOutputNode) {
// EditPartViewer viewer = targetEditPart.getViewer();
// if (viewer instanceof XmlMapGraphicViewer) {
// InputLoopTableUtil.addSourceLoopToInputLoopTable(sourceNode, targetOutputNode, ((XmlMapGraphicViewer) viewer)
// .getMapperManager().getMainInputTree());
// }
// }
private void doUpdate(AbstractNode sourceNode) {
    if (targetEditPart instanceof OutputTreeNodeEditPart) {
        OutputTreeNode targetOutputNode = (OutputTreeNode) ((OutputTreeNodeEditPart) targetEditPart).getModel();
        String expression = targetOutputNode.getExpression();
        if (sourceNode instanceof TreeNode) {
            if (expression == null) {
                expression = XmlMapUtil.convertToExpression(((TreeNode) sourceNode).getXpath());
            } else {
                expression = expression + " " + XmlMapUtil.convertToExpression(((TreeNode) sourceNode).getXpath());
            }
        } else if (sourceNode instanceof VarNode) {
            String tableName = "Var";
            if (sourceNode.eContainer() instanceof VarTable) {
                tableName = ((VarTable) sourceNode.eContainer()).getName();
            }
            if (expression == null) {
                expression = tableName + "." + sourceNode.getName();
            } else {
                expression = expression + " " + tableName + "." + sourceNode.getName();
            }
        }
        // if (sourceNode instanceof TreeNode) {
        // createInputLoopTable((TreeNode) sourceNode, targetOutputNode);
        // }
        targetOutputNode.setExpression(expression);
        Connection conn = XmlmapFactory.eINSTANCE.createConnection();
        conn.setSource(sourceNode);
        conn.setTarget(targetOutputNode);
        targetOutputNode.getIncomingConnections().add(conn);
        sourceNode.getOutgoingConnections().add(conn);
        if (xmlMapData != null) {
            xmlMapData.getConnections().add(conn);
        }
    } else if (targetEditPart instanceof TreeNodeEditPart) {
        /* for lookup connections */
        if (sourceNode instanceof TreeNode) {
            TreeNode targetTreeNode = (TreeNode) targetEditPart.getModel();
            String expression = targetTreeNode.getExpression();
            if (expression == null) {
                expression = "";
            }
            expression = expression + " " + XmlMapUtil.convertToExpression(((TreeNode) sourceNode).getXpath());
            targetTreeNode.setExpression(expression);
            LookupConnection conn = XmlmapFactory.eINSTANCE.createLookupConnection();
            conn.setSource(sourceNode);
            conn.setTarget(targetTreeNode);
            targetTreeNode.getLookupIncomingConnections().add(conn);
            ((TreeNode) sourceNode).getLookupOutgoingConnections().add(conn);
            if (xmlMapData != null) {
                xmlMapData.getConnections().add(conn);
            }
        }
    } else if (targetEditPart instanceof VarNodeEditPart) {
        /* for varTable drag drop */
        if (sourceNode instanceof TreeNode) {
            VarNodeEditPart targetPart = (VarNodeEditPart) targetEditPart;
            VarNode targetNode = (VarNode) targetPart.getModel();
            String expression = targetNode.getExpression();
            if (expression == null) {
                expression = "";
            }
            expression = expression + " " + XmlMapUtil.convertToExpression(((TreeNode) sourceNode).getXpath());
            if (targetNode.getName() == null || "".equals(targetNode.getName())) {
                String findUniqueVarColumnName = XmlMapUtil.findUniqueVarColumnName(sourceNode.getName(), xmlMapData.getVarTables().get(0));
                targetNode.setName(findUniqueVarColumnName);
            }
            targetNode.setExpression(expression.trim());
            targetNode.setType(sourceNode.getType());
            Connection conn = XmlmapFactory.eINSTANCE.createConnection();
            conn.setSource(sourceNode);
            conn.setTarget(targetNode);
            targetNode.getIncomingConnections().add(conn);
            sourceNode.getOutgoingConnections().add(conn);
            if (xmlMapData != null) {
                xmlMapData.getConnections().add(conn);
            }
        }
    } else if (targetEditPart instanceof InputXmlTreeEditPart || targetEditPart instanceof OutputXmlTreeEditPart) {
        AbstractInOutTree treeModel = (AbstractInOutTree) targetEditPart.getModel();
        String expression = treeModel.getExpressionFilter();
        if (sourceNode instanceof TreeNode) {
            if (expression == null) {
                expression = XmlMapUtil.convertToExpression(((TreeNode) sourceNode).getXpath());
            } else {
                expression = expression + " " + XmlMapUtil.convertToExpression(((TreeNode) sourceNode).getXpath());
            }
        } else if (sourceNode instanceof VarNode) {
            String tableName = "Var";
            if (sourceNode.eContainer() instanceof VarTable) {
                tableName = ((VarTable) sourceNode.eContainer()).getName();
            }
            if (expression == null) {
                expression = tableName + "." + sourceNode.getName();
            } else {
                expression = expression + " " + tableName + "." + sourceNode.getName();
            }
        }
        treeModel.setExpressionFilter(expression);
        FilterConnection connection = XmlmapFactory.eINSTANCE.createFilterConnection();
        connection.setSource(sourceNode);
        connection.setTarget(treeModel);
        treeModel.getFilterIncomingConnections().add(connection);
        sourceNode.getFilterOutGoingConnections().add(connection);
        xmlMapData.getConnections().add(connection);
    }
}
Also used : VarNode(org.talend.designer.xmlmap.model.emf.xmlmap.VarNode) VarNodeEditPart(org.talend.designer.xmlmap.parts.VarNodeEditPart) FilterConnection(org.talend.designer.xmlmap.model.emf.xmlmap.FilterConnection) FilterConnection(org.talend.designer.xmlmap.model.emf.xmlmap.FilterConnection) Connection(org.talend.designer.xmlmap.model.emf.xmlmap.Connection) LookupConnection(org.talend.designer.xmlmap.model.emf.xmlmap.LookupConnection) AbstractInOutTree(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) LookupConnection(org.talend.designer.xmlmap.model.emf.xmlmap.LookupConnection) TreeNodeEditPart(org.talend.designer.xmlmap.parts.TreeNodeEditPart) OutputTreeNodeEditPart(org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart) OutputXmlTreeEditPart(org.talend.designer.xmlmap.parts.OutputXmlTreeEditPart) VarTable(org.talend.designer.xmlmap.model.emf.xmlmap.VarTable) InputXmlTreeEditPart(org.talend.designer.xmlmap.parts.InputXmlTreeEditPart) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) OutputTreeNodeEditPart(org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart)

Aggregations

VarNode (org.talend.designer.xmlmap.model.emf.xmlmap.VarNode)28 TreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode)19 OutputTreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode)17 VarTable (org.talend.designer.xmlmap.model.emf.xmlmap.VarTable)13 InputXmlTree (org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree)12 OutputXmlTree (org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree)12 VarNodeEditPart (org.talend.designer.xmlmap.parts.VarNodeEditPart)11 AbstractNode (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode)9 XmlMapData (org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData)8 ArrayList (java.util.ArrayList)7 List (java.util.List)7 TransferedObject (org.talend.designer.gefabstractmap.dnd.TransferedObject)7 TreeNodeEditPart (org.talend.designer.xmlmap.parts.TreeNodeEditPart)7 EList (org.eclipse.emf.common.util.EList)6 AbstractInOutTree (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree)6 FilterConnection (org.talend.designer.xmlmap.model.emf.xmlmap.FilterConnection)6 EditPart (org.eclipse.gef.EditPart)4 Command (org.eclipse.gef.commands.Command)4 CommandStack (org.eclipse.gef.commands.CommandStack)4 Connection (org.talend.designer.xmlmap.model.emf.xmlmap.Connection)4