Search in sources :

Example 6 with FilterConnection

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

the class XmlMapUtil method detachFilterSource.

public static void detachFilterSource(AbstractInOutTree tree, XmlMapData mapData) {
    for (FilterConnection connection : tree.getFilterIncomingConnections()) {
        if (connection.getSource() != null) {
            if (connection.getSource().getFilterOutGoingConnections().contains(connection)) {
                connection.getSource().getFilterOutGoingConnections().remove(connection);
                mapData.getConnections().remove(connection);
            }
        }
    }
    tree.getFilterIncomingConnections().clear();
}
Also used : FilterConnection(org.talend.designer.xmlmap.model.emf.xmlmap.FilterConnection)

Example 7 with FilterConnection

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

the class XmlMapUtil method updateTargetExpression.

public static void updateTargetExpression(AbstractNode renamedNode, String oldExpression, String newExpression, XmlMapExpressionManager expressionManager) {
    TableEntryLocation previousLocation = expressionManager.parseTableEntryLocation(oldExpression).get(0);
    TableEntryLocation newLocation = expressionManager.parseTableEntryLocation(newExpression).get(0);
    List<INodeConnection> connections = new ArrayList<INodeConnection>();
    connections.addAll(renamedNode.getOutgoingConnections());
    if (renamedNode instanceof TreeNode) {
        connections.addAll(((TreeNode) renamedNode).getLookupOutgoingConnections());
    }
    for (INodeConnection connection : connections) {
        AbstractNode target = connection.getTarget();
        List<TableEntryLocation> targetLocaitons = expressionManager.parseTableEntryLocation(target.getExpression());
        for (TableEntryLocation current : targetLocaitons) {
            if (current.equals(previousLocation)) {
                String replaced = expressionManager.replaceExpression(target.getExpression(), current, newLocation);
                target.setExpression(replaced);
            }
        }
    }
    for (FilterConnection connection : renamedNode.getFilterOutGoingConnections()) {
        AbstractInOutTree target = connection.getTarget();
        List<TableEntryLocation> targetLocaitons = expressionManager.parseTableEntryLocation(target.getExpressionFilter());
        for (TableEntryLocation current : targetLocaitons) {
            if (current.equals(previousLocation)) {
                String replaced = expressionManager.replaceExpression(target.getExpressionFilter(), current, newLocation);
                target.setExpressionFilter(replaced);
            }
        }
    }
}
Also used : INodeConnection(org.talend.designer.xmlmap.model.emf.xmlmap.INodeConnection) FilterConnection(org.talend.designer.xmlmap.model.emf.xmlmap.FilterConnection) AbstractNode(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) TableEntryLocation(org.talend.designer.xmlmap.ui.expressionutil.TableEntryLocation) ArrayList(java.util.ArrayList) AbstractInOutTree(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree)

Example 8 with FilterConnection

use of org.talend.designer.xmlmap.model.emf.xmlmap.FilterConnection 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 9 with FilterConnection

use of org.talend.designer.xmlmap.model.emf.xmlmap.FilterConnection 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 10 with FilterConnection

use of org.talend.designer.xmlmap.model.emf.xmlmap.FilterConnection 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

FilterConnection (org.talend.designer.xmlmap.model.emf.xmlmap.FilterConnection)10 TreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode)8 AbstractInOutTree (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree)6 OutputTreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode)5 VarNode (org.talend.designer.xmlmap.model.emf.xmlmap.VarNode)5 AbstractNode (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode)4 VarTable (org.talend.designer.xmlmap.model.emf.xmlmap.VarTable)4 ArrayList (java.util.ArrayList)3 Connection (org.talend.designer.xmlmap.model.emf.xmlmap.Connection)3 InputXmlTree (org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree)3 OutputXmlTree (org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree)3 XmlMapData (org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData)3 IConnection (org.talend.designer.xmlmap.model.emf.xmlmap.IConnection)2 INodeConnection (org.talend.designer.xmlmap.model.emf.xmlmap.INodeConnection)2 LookupConnection (org.talend.designer.xmlmap.model.emf.xmlmap.LookupConnection)2 TreeNodeEditPart (org.talend.designer.xmlmap.parts.TreeNodeEditPart)2 VarNodeEditPart (org.talend.designer.xmlmap.parts.VarNodeEditPart)2 TableEntryLocation (org.talend.designer.xmlmap.ui.expressionutil.TableEntryLocation)2 HashMap (java.util.HashMap)1 List (java.util.List)1