Search in sources :

Example 1 with TableEntryLocation

use of org.talend.designer.xmlmap.ui.expressionutil.TableEntryLocation in project tdi-studio-se by Talend.

the class XmlMapConnectionBuilder method hasMaptchedLocation.

private boolean hasMaptchedLocation(XmlMapExpressionManager expressionManager, TableEntryLocation sourceLocation, EObject targetNodeOrTree, ExpressionType type) {
    String targetExpression = null;
    AbstractNode targetNode = null;
    AbstractInOutTree targetTree = null;
    switch(type) {
        case EXPRESSION:
            targetNode = (AbstractNode) targetNodeOrTree;
            targetExpression = targetNode.getExpression();
            break;
        case EXPRESSION_FILTER:
            targetTree = (AbstractInOutTree) targetNodeOrTree;
            targetExpression = targetTree.getExpressionFilter();
        default:
            break;
    }
    if (!"".equals(targetExpression) && targetExpression != null) {
        List<TableEntryLocation> targetLocations = expressionManager.parseTableEntryLocation(targetExpression);
        for (TableEntryLocation target : targetLocations) {
            if (sourceLocation.equals(target)) {
                return true;
            } else if (checkRootNodePrefix && !cancelForAll) {
                StringBuffer bf = new StringBuffer();
                String prefix = null;
                String nodeName = null;
                final String[] split = sourceLocation.toString().split("/");
                if (split.length > 2) {
                    for (int i = 0; i < split.length; i++) {
                        String value = split[i];
                        if (i == 1) {
                            int indexOf = split[1].indexOf(":");
                            if (indexOf != -1) {
                                prefix = split[1].substring(0, indexOf);
                                nodeName = split[1].substring(indexOf + 1, split[1].length());
                                value = nodeName;
                            } else {
                                break;
                            }
                        }
                        bf.append(value);
                        if (i < split.length - 1) {
                            bf.append("/");
                        }
                    }
                }
                if (bf.toString().equals(targetExpression)) {
                    if (applyForAll) {
                        // reset the target expression with prefix
                        if (targetNode != null) {
                            targetNode.setExpression(expressionManager.replaceExpression(targetExpression, target, sourceLocation));
                        }
                        if (targetTree != null) {
                            targetTree.setExpressionFilter(expressionManager.replaceExpression(targetExpression, target, sourceLocation));
                        }
                        return true;
                    } else {
                        PrefixChangeDialog dialog = new PrefixChangeDialog(new Shell());
                        dialog.setPrefix(prefix);
                        dialog.setRootNodeName(nodeName);
                        dialog.setSourceExpression(sourceLocation.toString());
                        dialog.setTargetExpression(target.toString());
                        if (dialog.open() == Window.OK) {
                            applyForAll = dialog.isApplyAll();
                            cancelForAll = dialog.isCancelAll();
                            if (cancelForAll) {
                                return false;
                            }
                            // reset the target expression with prefix
                            if (targetNode != null) {
                                targetNode.setExpression(expressionManager.replaceExpression(targetExpression, target, sourceLocation));
                            }
                            if (targetTree != null) {
                                targetTree.setExpressionFilter(expressionManager.replaceExpression(targetExpression, target, sourceLocation));
                            }
                            return true;
                        }
                    }
                }
            }
        }
    }
    return false;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) AbstractNode(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode) TableEntryLocation(org.talend.designer.xmlmap.ui.expressionutil.TableEntryLocation) AbstractInOutTree(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree) PrefixChangeDialog(org.talend.designer.xmlmap.ui.dialog.PrefixChangeDialog)

Example 2 with TableEntryLocation

use of org.talend.designer.xmlmap.ui.expressionutil.TableEntryLocation in project tdi-studio-se by Talend.

the class XmlMapConnectionBuilder method rebuildLink.

private void rebuildLink(int inputTreeIndex, List<TreeNode> children, XmlMapData mapData) {
    for (TreeNode treeNode : children) {
        if (XmlMapUtil.isDragable(treeNode)) {
            String expression = XmlMapUtil.convertToExpression(treeNode.getXpath());
            XmlMapExpressionManager expressionManager = new XmlMapExpressionManager();
            TableEntryLocation sourceLocation = expressionManager.parseTableEntryLocation(expression).get(0);
            // LOOKUP ,FILTER
            for (int i = inputTreeIndex; i < mapData.getInputTrees().size(); i++) {
                InputXmlTree treeTarget = mapData.getInputTrees().get(i);
                if (hasMaptchedLocation(expressionManager, sourceLocation, treeTarget, ExpressionType.EXPRESSION_FILTER)) {
                    createFilterConnection(treeNode, treeTarget, mapData);
                }
                checkTargetChildren(expressionManager, treeTarget.getNodes(), treeNode, sourceLocation, mapData);
            }
            // VAR
            for (VarNode varNode : mapData.getVarTables().get(0).getNodes()) {
                if (hasMaptchedLocation(expressionManager, sourceLocation, varNode, ExpressionType.EXPRESSION)) {
                    createConnection(treeNode, varNode, mapData);
                }
            }
            // OUTPUT,FILTER
            for (int i = 0; i < mapData.getOutputTrees().size(); i++) {
                OutputXmlTree outputTree = mapData.getOutputTrees().get(i);
                if (hasMaptchedLocation(expressionManager, sourceLocation, outputTree, ExpressionType.EXPRESSION_FILTER)) {
                    createFilterConnection(treeNode, outputTree, mapData);
                }
                checkTargetChildren(expressionManager, outputTree.getNodes(), treeNode, sourceLocation, mapData);
            }
        }
        if (!treeNode.getChildren().isEmpty()) {
            rebuildLink(inputTreeIndex, treeNode.getChildren(), mapData);
        }
    }
}
Also used : InputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree) VarNode(org.talend.designer.xmlmap.model.emf.xmlmap.VarNode) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) XmlMapExpressionManager(org.talend.designer.xmlmap.ui.expressionutil.XmlMapExpressionManager) TableEntryLocation(org.talend.designer.xmlmap.ui.expressionutil.TableEntryLocation) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree)

Example 3 with TableEntryLocation

use of org.talend.designer.xmlmap.ui.expressionutil.TableEntryLocation 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 4 with TableEntryLocation

use of org.talend.designer.xmlmap.ui.expressionutil.TableEntryLocation 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)

Example 5 with TableEntryLocation

use of org.talend.designer.xmlmap.ui.expressionutil.TableEntryLocation 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)

Aggregations

TableEntryLocation (org.talend.designer.xmlmap.ui.expressionutil.TableEntryLocation)6 AbstractNode (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode)4 TreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode)4 ArrayList (java.util.ArrayList)3 OutputTreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode)3 VarNode (org.talend.designer.xmlmap.model.emf.xmlmap.VarNode)3 List (java.util.List)2 EList (org.eclipse.emf.common.util.EList)2 AbstractInOutTree (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree)2 FilterConnection (org.talend.designer.xmlmap.model.emf.xmlmap.FilterConnection)2 INodeConnection (org.talend.designer.xmlmap.model.emf.xmlmap.INodeConnection)2 OutputXmlTree (org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree)2 XmlMapExpressionManager (org.talend.designer.xmlmap.ui.expressionutil.XmlMapExpressionManager)2 PatternSyntaxException (java.util.regex.PatternSyntaxException)1 Shell (org.eclipse.swt.widgets.Shell)1 JavaType (org.talend.core.model.metadata.types.JavaType)1 GlobalMapNode (org.talend.designer.xmlmap.model.emf.xmlmap.GlobalMapNode)1 InputXmlTree (org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree)1 LookupConnection (org.talend.designer.xmlmap.model.emf.xmlmap.LookupConnection)1 XmlMapData (org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData)1