Search in sources :

Example 11 with VarNode

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

the class ExpressionProposalProvider method init.

public void init(Object source) {
    XmlMapData mapData = mapperManager.getExternalData();
    int index = 0;
    boolean needVar = false;
    if (source instanceof OutputTreeNode || source instanceof OutputXmlTree) {
        needVar = true;
        index = mapData.getInputTrees().size();
    } else if (source instanceof TreeNode) {
        AbstractInOutTree abstractTree = XmlMapUtil.getAbstractInOutTree((TreeNode) source);
        index = mapData.getInputTrees().indexOf(abstractTree);
        if (index == -1) {
            index = 0;
        }
    } else if (source instanceof VarNode) {
        index = mapData.getInputTrees().size();
    } else if (source instanceof InputXmlTree) {
        index = mapData.getInputTrees().indexOf(source) + 1;
    }
    for (int i = 0; i < index; i++) {
        InputXmlTree inputTree = mapData.getInputTrees().get(i);
        getProposalsInside(inputTree.getNodes(), proposalsInside);
    }
    if (needVar) {
        getProposalsInside(mapData.getVarTables().get(0).getNodes(), proposalsInside);
    }
}
Also used : VarNode(org.talend.designer.xmlmap.model.emf.xmlmap.VarNode) 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) AbstractInOutTree(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree) XmlMapData(org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData)

Example 12 with VarNode

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

the class VarToolBarFigure method moveDown.

@Override
protected void moveDown() {
    CommandStack commandStack = getTableManager().getGraphicalViewer().getEditDomain().getCommandStack();
    commandStack.execute(new Command() {

        @Override
        public void execute() {
            List selectedEditParts = getTableManager().getGraphicalViewer().getSelectedEditParts();
            List<Integer> indexToMove = new ArrayList<Integer>();
            EList<VarNode> nodes = parentTable.getNodes();
            for (int i = 0; i < selectedEditParts.size(); i++) {
                Object obj = selectedEditParts.get(i);
                if (obj instanceof VarNodeEditPart) {
                    VarNode node = (VarNode) ((VarNodeEditPart) obj).getModel();
                    int indexOf = nodes.indexOf(node);
                    if (indexOf != -1 && indexOf < nodes.size() - 1) {
                        indexToMove.add(indexOf);
                    }
                }
            }
            Collections.sort(indexToMove);
            Collections.reverse(indexToMove);
            for (int i = 0; i < indexToMove.size(); i++) {
                int index = indexToMove.get(i);
                VarNode temp = nodes.get(index);
                nodes.remove(temp);
                nodes.add(index + 1, temp);
            }
            for (int i = 0; i < indexToMove.size(); i++) {
                EditPart part = (EditPart) tablePart.getChildren().get(indexToMove.get(i) + 1);
                tablePart.getViewer().appendSelection(part);
            }
        }
    });
}
Also used : VarNode(org.talend.designer.xmlmap.model.emf.xmlmap.VarNode) CommandStack(org.eclipse.gef.commands.CommandStack) VarNodeEditPart(org.talend.designer.xmlmap.parts.VarNodeEditPart) EList(org.eclipse.emf.common.util.EList) Command(org.eclipse.gef.commands.Command) VarNodeEditPart(org.talend.designer.xmlmap.parts.VarNodeEditPart) EditPart(org.eclipse.gef.EditPart) EList(org.eclipse.emf.common.util.EList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 13 with VarNode

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

the class VarToolBarFigure method moveUp.

@Override
protected void moveUp() {
    CommandStack commandStack = getTableManager().getGraphicalViewer().getEditDomain().getCommandStack();
    commandStack.execute(new Command() {

        @Override
        public void execute() {
            List selectedEditParts = getTableManager().getGraphicalViewer().getSelectedEditParts();
            List<Integer> indexToMove = new ArrayList<Integer>();
            EList<VarNode> nodes = parentTable.getNodes();
            for (int i = 0; i < selectedEditParts.size(); i++) {
                Object obj = selectedEditParts.get(i);
                if (obj instanceof VarNodeEditPart) {
                    VarNode node = (VarNode) ((VarNodeEditPart) obj).getModel();
                    int indexOf = nodes.indexOf(node);
                    if (indexOf != -1 && indexOf > 0) {
                        indexToMove.add(indexOf);
                    }
                }
            }
            Collections.sort(indexToMove);
            for (int i = 0; i < indexToMove.size(); i++) {
                int index = indexToMove.get(i);
                VarNode temp = nodes.get(index);
                nodes.remove(temp);
                nodes.add(index - 1, temp);
            }
            for (int i = 0; i < indexToMove.size(); i++) {
                EditPart part = (EditPart) tablePart.getChildren().get(indexToMove.get(i) - 1);
                tablePart.getViewer().appendSelection(part);
            }
        }
    });
}
Also used : VarNode(org.talend.designer.xmlmap.model.emf.xmlmap.VarNode) CommandStack(org.eclipse.gef.commands.CommandStack) VarNodeEditPart(org.talend.designer.xmlmap.parts.VarNodeEditPart) EList(org.eclipse.emf.common.util.EList) Command(org.eclipse.gef.commands.Command) VarNodeEditPart(org.talend.designer.xmlmap.parts.VarNodeEditPart) EditPart(org.eclipse.gef.EditPart) EList(org.eclipse.emf.common.util.EList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 14 with VarNode

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

the class SearchZoneMapper method search.

public void search(Map<Integer, Map<Integer, Figure>> searchMaps, String searchValue) {
    if (searchValue.equals("") || searchValue == null) {
        return;
    }
    List<InputXmlTree> inputTrees = mapperManager.getExternalData().getInputTrees();
    List<VarTable> varTables = mapperManager.getExternalData().getVarTables();
    List<OutputXmlTree> outputTrees = mapperManager.getExternalData().getOutputTrees();
    matcher.setPattern("*" + searchValue.trim() + "*");
    int index = -1;
    // for the InputTables
    for (InputXmlTree inputXmlTree : inputTrees) {
        // ExpressionFilter
        if (inputXmlTree.getExpressionFilter() != null && matcher.matches(inputXmlTree.getExpressionFilter())) {
            EList<Adapter> adapter = inputXmlTree.eAdapters();
            if (adapter.size() > 0) {
                if (adapter.get(0) instanceof InputXmlTreeEditPart) {
                    InputXmlTreeEditPart inputXmlTreeEditPart = (InputXmlTreeEditPart) adapter.get(0);
                    if (inputXmlTreeEditPart != null && inputXmlTreeEditPart.getFigure() != null && inputXmlTreeEditPart.getFigure() instanceof InputXmlTreeFigure) {
                        InputXmlTreeFigure inputXmlTreeFigure = (InputXmlTreeFigure) inputXmlTreeEditPart.getFigure();
                        Map<Integer, Figure> map = new HashMap<Integer, Figure>();
                        map.put(0, inputXmlTreeFigure.getFilterContainer());
                        index++;
                        searchMaps.put(index, map);
                    }
                }
            }
        }
        // TreeNode
        for (TreeNode node : inputXmlTree.getNodes()) {
            // id_Document type
            if (XmlMapUtil.DOCUMENT.equals(node.getType())) {
                for (TreeNode nodeTemp : XmlMapUtil.getFlatChildrenList(node)) {
                    if (getMatcherNodeFigure(nodeTemp).size() > 0) {
                        index++;
                        searchMaps.put(index, getMatcherNodeFigure(nodeTemp));
                    }
                }
            }
            if (getMatcherNodeFigure(node).size() > 0) {
                index++;
                searchMaps.put(index, getMatcherNodeFigure(node));
            }
        }
    }
    // for the VarsTables
    for (VarTable varTable : varTables) {
        for (VarNode node : varTable.getNodes()) {
            if (getMatcherNodeFigure(node).size() > 0) {
                index++;
                searchMaps.put(index, getMatcherNodeFigure(node));
            }
        }
    }
    // for the OutputTables
    for (OutputXmlTree outputXmlTree : outputTrees) {
        // ExpressionFilter
        if (outputXmlTree.getExpressionFilter() != null && matcher.matches(outputXmlTree.getExpressionFilter())) {
            EList<Adapter> adapter = outputXmlTree.eAdapters();
            if (adapter.size() > 0) {
                if (adapter.get(0) instanceof OutputXmlTreeEditPart) {
                    OutputXmlTreeEditPart outputXmlTreeEditPart = (OutputXmlTreeEditPart) adapter.get(0);
                    if (outputXmlTreeEditPart != null && outputXmlTreeEditPart.getFigure() != null && outputXmlTreeEditPart.getFigure() instanceof OutputXmlTreeFigure) {
                        OutputXmlTreeFigure outputXmlTreeFigure = (OutputXmlTreeFigure) outputXmlTreeEditPart.getFigure();
                        Map<Integer, Figure> map = new HashMap<Integer, Figure>();
                        map.put(0, outputXmlTreeFigure.getFilterContainer());
                        index++;
                        searchMaps.put(index, map);
                    }
                }
            }
        }
        // OutputTreeNode
        for (OutputTreeNode node : outputXmlTree.getNodes()) {
            // id_Document type
            if (XmlMapUtil.DOCUMENT.equals(node.getType())) {
                for (TreeNode nodeTemp : XmlMapUtil.getFlatChildrenList(node)) {
                    if (getMatcherNodeFigure(nodeTemp).size() > 0) {
                        index++;
                        searchMaps.put(index, getMatcherNodeFigure(nodeTemp));
                    }
                }
            } else {
                if (getMatcherNodeFigure(node).size() > 0) {
                    index++;
                    searchMaps.put(index, getMatcherNodeFigure(node));
                }
            }
        }
    }
}
Also used : VarNode(org.talend.designer.xmlmap.model.emf.xmlmap.VarNode) HashMap(java.util.HashMap) Adapter(org.eclipse.emf.common.notify.Adapter) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) InputXmlTreeFigure(org.talend.designer.xmlmap.figures.InputXmlTreeFigure) OutputXmlTreeEditPart(org.talend.designer.xmlmap.parts.OutputXmlTreeEditPart) IFigure(org.eclipse.draw2d.IFigure) OutputXmlTreeFigure(org.talend.designer.xmlmap.figures.OutputXmlTreeFigure) TableEntityFigure(org.talend.designer.gefabstractmap.figures.table.entity.TableEntityFigure) XmlmapTreeNodeFigure(org.talend.designer.xmlmap.figures.treeNode.XmlmapTreeNodeFigure) VarNodeFigure(org.talend.designer.xmlmap.figures.varnode.VarNodeFigure) InputXmlTreeFigure(org.talend.designer.xmlmap.figures.InputXmlTreeFigure) VarEntityFigure(org.talend.designer.gefabstractmap.figures.var.VarEntityFigure) Figure(org.eclipse.draw2d.Figure) InputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree) 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) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree) OutputXmlTreeFigure(org.talend.designer.xmlmap.figures.OutputXmlTreeFigure)

Example 15 with VarNode

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

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