Search in sources :

Example 6 with LookupConnection

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

the class XmlMapUtil method getChildLookupConnections.

private static void getChildLookupConnections(List<IConnection> connections, List<? extends TreeNode> nodesList) {
    for (TreeNode node : nodesList) {
        EList<LookupConnection> outgoingConnections = node.getLookupOutgoingConnections();
        connections.addAll(outgoingConnections);
        if (!node.getChildren().isEmpty()) {
            getChildLookupConnections(connections, node.getChildren());
        }
    }
}
Also used : OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) LookupConnection(org.talend.designer.xmlmap.model.emf.xmlmap.LookupConnection)

Example 7 with LookupConnection

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

the class ProblemsAnalyser method checkNodeInputLookTableProblem.

private boolean checkNodeInputLookTableProblem(OutputTreeNode outputNode, InputXmlTree mainInputTree, boolean checkChildren) {
    for (Connection connection : outputNode.getIncomingConnections()) {
        if (connection.getSource() instanceof TreeNode) {
            TreeNode source = (TreeNode) connection.getSource();
            InputXmlTree abstractInOutTree = (InputXmlTree) XmlMapUtil.getAbstractInOutTree(source);
            if (abstractInOutTree == mainInputTree) {
                return true;
            } else {
                EList<LookupConnection> lookupIncomingConnections = source.getLookupIncomingConnections();
                for (LookupConnection lookupConn : lookupIncomingConnections) {
                    TreeNode sourceNode = (TreeNode) lookupConn.getSource();
                    AbstractInOutTree abstractInOutTree2 = XmlMapUtil.getAbstractInOutTree(sourceNode);
                    if (abstractInOutTree2 == mainInputTree) {
                        return true;
                    }
                }
            }
            if (checkChildren && !outputNode.getChildren().isEmpty()) {
                for (TreeNode child : outputNode.getChildren()) {
                    if (checkNodeInputLookTableProblem((OutputTreeNode) child, mainInputTree, checkChildren)) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : 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) 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) LookupConnection(org.talend.designer.xmlmap.model.emf.xmlmap.LookupConnection)

Example 8 with LookupConnection

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

the class InputLoopTableUtil method getLoopSourceFromLookupNode.

private static void getLoopSourceFromLookupNode(TreeNode connectionSource, InputXmlTree mainTable, List<TreeNode> soruceLoops) {
    EList<LookupConnection> lookupIncomingConnections = connectionSource.getLookupIncomingConnections();
    for (LookupConnection lookupConn : lookupIncomingConnections) {
        TreeNode sourceTreeNode = (TreeNode) lookupConn.getSource();
        AbstractInOutTree sourceTree = XmlMapUtil.getAbstractInOutTree(sourceTreeNode);
        if (sourceTree == mainTable) {
            TreeNode loopParentTreeNode = XmlMapUtil.getLoopParentNode(sourceTreeNode);
            if (loopParentTreeNode != null && !soruceLoops.contains(loopParentTreeNode)) {
                soruceLoops.add(loopParentTreeNode);
            }
        } else {
            getLoopSourceFromLookupNode(sourceTreeNode, mainTable, soruceLoops);
        }
    }
}
Also used : OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) AbstractInOutTree(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree) LookupConnection(org.talend.designer.xmlmap.model.emf.xmlmap.LookupConnection)

Example 9 with LookupConnection

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

the class SetLoopAction method addInputLoopNodesToOutput.

private void addInputLoopNodesToOutput(TreeNode loopNode, TreeNode loopOrChild) {
    addInputLoopNodesToOutput(loopNode, loopOrChild.getOutgoingConnections());
    // check related lookup nodes
    if (!loopOrChild.getLookupOutgoingConnections().isEmpty()) {
        for (LookupConnection lookupConnection : loopOrChild.getLookupOutgoingConnections()) {
            TreeNode lookupTarget = (TreeNode) lookupConnection.getTarget();
            addInputLoopNodesToOutput(loopNode, lookupTarget.getOutgoingConnections());
        }
    }
    if (!loopOrChild.getChildren().isEmpty()) {
        for (TreeNode child : loopOrChild.getChildren()) {
            addInputLoopNodesToOutput(loopNode, child);
        }
    }
}
Also used : OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) LookupConnection(org.talend.designer.xmlmap.model.emf.xmlmap.LookupConnection)

Example 10 with LookupConnection

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

the class DirectEditCommand method execute.

@Override
public void execute() {
    try {
        if (model != null) {
            if (DirectEditType.EXPRESSION.equals(type)) {
                List<TableEntryLocation> matchedLocations = expressionManager.parseTableEntryLocation((String) newValue);
                EList<? extends INodeConnection> connections = null;
                if (model instanceof OutputTreeNode || model instanceof VarNode) {
                    connections = model.getIncomingConnections();
                } else if (model instanceof TreeNode) {
                    connections = ((TreeNode) model).getLookupIncomingConnections();
                }
                List usefullConnections = new ArrayList();
                mapperData = XmlMapUtil.getXmlMapData(model);
                if (!matchedLocations.isEmpty()) {
                    for (int i = 0; i < matchedLocations.size(); i++) {
                        TableEntryLocation currentLocation = matchedLocations.get(i);
                        boolean found = false;
                        for (INodeConnection 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 (model instanceof OutputTreeNode) {
                                    findFromVar = true;
                                }
                                AbstractNode sourceNode = findConnectionSource(mapperData, currentLocation, XmlMapUtil.getXPathLength(convertToXpath), findFromVar);
                                if (sourceNode != null) {
                                    INodeConnection connection = null;
                                    if (model instanceof OutputTreeNode || model instanceof VarNode) {
                                        connection = XmlmapFactory.eINSTANCE.createConnection();
                                        sourceNode.getOutgoingConnections().add((Connection) connection);
                                        model.getIncomingConnections().add((Connection) connection);
                                    } else if (model instanceof TreeNode && sourceNode instanceof TreeNode) {
                                        TreeNode source = (TreeNode) sourceNode;
                                        connection = XmlmapFactory.eINSTANCE.createLookupConnection();
                                        source.getLookupOutgoingConnections().add((LookupConnection) connection);
                                        ((TreeNode) model).getLookupIncomingConnections().add((LookupConnection) connection);
                                    }
                                    //
                                    // if (model instanceof OutputTreeNode && sourceNode instanceof TreeNode) {
                                    // createInputLoopTable((TreeNode) sourceNode, (OutputTreeNode) model);
                                    // }
                                    connection.setSource(sourceNode);
                                    connection.setTarget(model);
                                    mapperData.getConnections().add(connection);
                                    usefullConnections.add(connection);
                                }
                            }
                        }
                    }
                } else {
                    if (!connections.isEmpty()) {
                        if (model instanceof OutputTreeNode || model instanceof VarNode) {
                            XmlMapUtil.detachConnectionsSouce(model, mapperData, false);
                            model.getIncomingConnections().clear();
                        } else if (model instanceof TreeNode) {
                            XmlMapUtil.detachLookupSource((TreeNode) model, mapperData);
                            ((TreeNode) model).getLookupIncomingConnections().clear();
                        }
                    }
                }
                List<INodeConnection> copyOfConnections = new ArrayList<INodeConnection>(connections);
                copyOfConnections.removeAll(usefullConnections);
                if (model instanceof OutputTreeNode || model instanceof VarNode) {
                    for (INodeConnection connection : copyOfConnections) {
                        if (connection.getSource() != null) {
                            if (connection.getSource().getOutgoingConnections().contains(connection)) {
                                connection.getSource().getOutgoingConnections().remove(connection);
                                mapperData.getConnections().remove(connection);
                            }
                        }
                    }
                    model.getIncomingConnections().removeAll(copyOfConnections);
                } else if (model instanceof TreeNode) {
                    for (INodeConnection connection : copyOfConnections) {
                        if (connection.getSource() != null) {
                            if (((TreeNode) connection.getSource()).getLookupOutgoingConnections().contains(connection)) {
                                ((TreeNode) connection.getSource()).getLookupOutgoingConnections().remove(connection);
                                mapperData.getConnections().remove(connection);
                            }
                        }
                    }
                    ((TreeNode) model).getLookupIncomingConnections().removeAll(copyOfConnections);
                }
                if (model instanceof OutputTreeNode) {
                    OutputTreeNode outModel = (OutputTreeNode) model;
                    if (NodeType.NAME_SPACE.equals(outModel.getNodeType()) && outModel.getExpression() != null && !"".equals(model.getExpression())) {
                        outModel.setDefaultValue("");
                    }
                }
                model.setExpression((String) newValue);
            } else if (DirectEditType.VAR_NODE_TYPE.equals(type)) {
                VarNode varModel = (VarNode) model;
                JavaType javaTypeFromLabel = JavaTypesManager.getJavaTypeFromLabel((String) newValue);
                if (javaTypeFromLabel == null) {
                    javaTypeFromLabel = JavaTypesManager.getDefaultJavaType();
                }
                varModel.setType(javaTypeFromLabel.getId());
            } else if (DirectEditType.NODE_NAME.equals(type)) {
                if (model instanceof VarNode) {
                    List<VarNode> children = new ArrayList<VarNode>();
                    children.addAll(((VarTable) model.eContainer()).getNodes());
                    children.remove(model);
                    String message = XmlMapUtil.isValidColumnName(children, (String) newValue);
                    if (message != null) {
                        MessageDialog.openError(null, "Error", message);
                        return;
                    }
                    String oldName = model.getName();
                    String oldExpression = XmlMapUtil.VAR_TABLE_NAME + XmlMapUtil.EXPRESSION_SEPARATOR + oldName;
                    model.setName((String) newValue);
                    String newExpression = XmlMapUtil.VAR_TABLE_NAME + XmlMapUtil.EXPRESSION_SEPARATOR + model.getName();
                    XmlMapUtil.updateTargetExpression(model, oldExpression, newExpression, expressionManager);
                } else if (model instanceof GlobalMapNode) {
                    model.setName((String) newValue);
                }
            }
        }
    } catch (PatternSyntaxException ex) {
    // Syntax error in the regular expression
    }
}
Also used : VarNode(org.talend.designer.xmlmap.model.emf.xmlmap.VarNode) INodeConnection(org.talend.designer.xmlmap.model.emf.xmlmap.INodeConnection) AbstractNode(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode) ArrayList(java.util.ArrayList) GlobalMapNode(org.talend.designer.xmlmap.model.emf.xmlmap.GlobalMapNode) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) LookupConnection(org.talend.designer.xmlmap.model.emf.xmlmap.LookupConnection) JavaType(org.talend.core.model.metadata.types.JavaType) 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) EList(org.eclipse.emf.common.util.EList) List(java.util.List) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Aggregations

LookupConnection (org.talend.designer.xmlmap.model.emf.xmlmap.LookupConnection)13 TreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode)10 OutputTreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode)9 AbstractInOutTree (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree)4 Connection (org.talend.designer.xmlmap.model.emf.xmlmap.Connection)3 InputXmlTree (org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree)3 VarNode (org.talend.designer.xmlmap.model.emf.xmlmap.VarNode)3 ArrayList (java.util.ArrayList)2 AbstractNode (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode)2 FilterConnection (org.talend.designer.xmlmap.model.emf.xmlmap.FilterConnection)2 IConnection (org.talend.designer.xmlmap.model.emf.xmlmap.IConnection)2 INodeConnection (org.talend.designer.xmlmap.model.emf.xmlmap.INodeConnection)2 VarTable (org.talend.designer.xmlmap.model.emf.xmlmap.VarTable)2 HashMap (java.util.HashMap)1 List (java.util.List)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1 EList (org.eclipse.emf.common.util.EList)1 EObject (org.eclipse.emf.ecore.EObject)1 JavaType (org.talend.core.model.metadata.types.JavaType)1 GlobalMapNode (org.talend.designer.xmlmap.model.emf.xmlmap.GlobalMapNode)1