Search in sources :

Example 1 with GlobalMapNode

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

the class GlobalMapKeysTable method createColumns.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.designer.gefabstractmap.figures.table.AbstractTable#createColumns()
     */
@Override
protected void createColumns() {
    layoutManager.setAjustToTableWidth(false);
    if (inputxmlTree != null && inputxmlTree.isLookup()) {
        expressionColumn = new TableColumn(ColumnKeyConstant.KEY_EXPRESSION);
        expressionColumn.setText(Messages.getString("InputTreeGlobalMapKeysTable.expressionTitle"));
        addColumn(expressionColumn);
        columnSash = new ColumnSash(this);
        columnSash.setLeftColumn(expressionColumn);
        addSeparator(columnSash);
        globalMapKeyColumn = new TableColumn(ColumnKeyConstant.KEY_NAME);
        globalMapKeyColumn.setText(Messages.getString("InputTreeGlobalMapKeysTable.globalMapKeyTitle"));
        columnSash.setRightColumn(globalMapKeyColumn);
        addColumn(globalMapKeyColumn);
        columnSash = new ColumnSash(this);
        columnSash.setLeftColumn(globalMapKeyColumn);
        addSeparator(columnSash);
        addColumn = new TableColumn(ColumnKeyConstant.KEY_VARIABLE);
        addColumn.setIcon(ImageProviderMapper.getImage(ImageInfo.ADD));
        addColumn.setLabelAlignment(PositionConstants.BOTTOM);
        columnSash.setRightColumn(addColumn);
        addColumn.setBorder(new MarginBorder(2));
        addColumn(addColumn);
        // add Listener
        addColumn.addMouseListener(new MouseListener() {

            @Override
            public void mousePressed(MouseEvent me) {
                GlobalMapNode defaultGlobalMapNode = XmlmapFactory.eINSTANCE.createGlobalMapNode();
                defaultGlobalMapNode.setExpression("");
                defaultGlobalMapNode.setName("\"myKey\"");
                inputxmlTree.getGlobalMapKeysValues().add(defaultGlobalMapNode);
            }

            @Override
            public void mouseReleased(MouseEvent me) {
            }

            @Override
            public void mouseDoubleClicked(MouseEvent me) {
            }
        });
    }
}
Also used : MouseListener(org.eclipse.draw2d.MouseListener) MouseEvent(org.eclipse.draw2d.MouseEvent) MarginBorder(org.eclipse.draw2d.MarginBorder) GlobalMapNode(org.talend.designer.xmlmap.model.emf.xmlmap.GlobalMapNode) ColumnSash(org.talend.designer.gefabstractmap.figures.table.ColumnSash) TableColumn(org.talend.designer.gefabstractmap.figures.table.TableColumn)

Example 2 with GlobalMapNode

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

the class GlobalMapNodeEditPart method getModelSourceConnections.

@Override
protected List getModelSourceConnections() {
    GlobalMapNode model = (GlobalMapNode) getModel();
    List list = new ArrayList();
    list.addAll(model.getLookupOutgoingConnections());
    return list;
}
Also used : ArrayList(java.util.ArrayList) GlobalMapNode(org.talend.designer.xmlmap.model.emf.xmlmap.GlobalMapNode) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with GlobalMapNode

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

the class XmlMapService method cloneTreeNode.

private EObject cloneTreeNode(EObject node) {
    if (node instanceof AbstractInOutTree) {
        AbstractInOutTree source = null;
        AbstractInOutTree oriSource = null;
        if (node instanceof InputXmlTree) {
            oriSource = (InputXmlTree) node;
            source = XmlmapFactory.eINSTANCE.createInputXmlTree();
            ((InputXmlTree) source).setActivateGlobalMap(((InputXmlTree) oriSource).isActivateGlobalMap());
            ((InputXmlTree) source).setInnerJoin(((InputXmlTree) oriSource).isInnerJoin());
            ((InputXmlTree) source).setLookup(((InputXmlTree) oriSource).isLookup());
            ((InputXmlTree) source).setLookupMode(((InputXmlTree) oriSource).getLookupMode());
            ((InputXmlTree) source).setMatchingMode(((InputXmlTree) oriSource).getMatchingMode());
            ((InputXmlTree) source).setPersistent(((InputXmlTree) oriSource).isPersistent());
        } else if (node instanceof OutputXmlTree) {
            oriSource = (OutputXmlTree) node;
            source = XmlmapFactory.eINSTANCE.createOutputXmlTree();
            ((OutputXmlTree) source).setAllInOne(((OutputXmlTree) oriSource).isAllInOne());
            ((OutputXmlTree) source).setEnableEmptyElement(((OutputXmlTree) oriSource).isEnableEmptyElement());
            ((OutputXmlTree) source).setErrorReject(((OutputXmlTree) oriSource).isErrorReject());
            ((OutputXmlTree) source).setReject(((OutputXmlTree) oriSource).isReject());
            ((OutputXmlTree) source).setRejectInnerJoin(((OutputXmlTree) oriSource).isRejectInnerJoin());
        }
        source.setActivateCondensedTool(oriSource.isActivateCondensedTool());
        source.setActivateExpressionFilter(oriSource.isActivateExpressionFilter());
        source.setExpressionFilter(oriSource.getExpressionFilter());
        source.setMinimized(oriSource.isMinimized());
        source.setMultiLoops(oriSource.isMultiLoops());
        source.setName(oriSource.getName());
        return source;
    } else if (node instanceof VarNode) {
        VarNode oriSource = (VarNode) node;
        VarNode source = XmlmapFactory.eINSTANCE.createVarNode();
        source.setExpression(oriSource.getExpression());
        source.setName(oriSource.getName());
        source.setNullable(oriSource.isNullable());
        source.setType(oriSource.getType());
        return source;
    } else if (node instanceof TreeNode) {
        TreeNode source = null;
        TreeNode oriSource = null;
        if (node instanceof OutputTreeNode) {
            oriSource = (OutputTreeNode) node;
            source = XmlmapFactory.eINSTANCE.createOutputTreeNode();
            ((OutputTreeNode) source).setAggregate(((OutputTreeNode) oriSource).isAggregate());
            ((OutputTreeNode) source).setInputLoopNodesTable(((OutputTreeNode) oriSource).getInputLoopNodesTable());
        } else if (node instanceof GlobalMapNode) {
            oriSource = (GlobalMapNode) node;
            source = XmlmapFactory.eINSTANCE.createGlobalMapNode();
            return source;
        } else {
            oriSource = (TreeNode) node;
            source = XmlmapFactory.eINSTANCE.createTreeNode();
        }
        source.setChoice(oriSource.isChoice());
        source.setDefaultValue(oriSource.getDefaultValue());
        source.setExpression(oriSource.getExpression());
        source.setGroup(oriSource.isGroup());
        source.setKey(oriSource.isKey());
        source.setLoop(oriSource.isLoop());
        source.setMain(oriSource.isMain());
        source.setName(oriSource.getName());
        source.setNodeType(oriSource.getNodeType());
        source.setNullable(oriSource.isNullable());
        source.setOptional(oriSource.isOptional());
        source.setPattern(oriSource.getPattern());
        source.setSubstitution(oriSource.isSubstitution());
        source.setType(oriSource.getType());
        source.setXpath(oriSource.getXpath());
        return source;
    }
    return null;
}
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) AbstractInOutTree(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree) GlobalMapNode(org.talend.designer.xmlmap.model.emf.xmlmap.GlobalMapNode) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode)

Example 4 with GlobalMapNode

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

the class GlobalMapNodeEditPart method setModel.

@Override
public void setModel(Object model) {
    super.setModel(model);
    entityManger = new GlobalMapNodeEntityManager((GlobalMapNode) model, this);
}
Also used : GlobalMapNode(org.talend.designer.xmlmap.model.emf.xmlmap.GlobalMapNode) GlobalMapNodeEntityManager(org.talend.designer.xmlmap.figures.treeNode.GlobalMapNodeEntityManager)

Example 5 with GlobalMapNode

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

GlobalMapNode (org.talend.designer.xmlmap.model.emf.xmlmap.GlobalMapNode)5 ArrayList (java.util.ArrayList)2 List (java.util.List)2 OutputTreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode)2 TreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode)2 VarNode (org.talend.designer.xmlmap.model.emf.xmlmap.VarNode)2 PatternSyntaxException (java.util.regex.PatternSyntaxException)1 MarginBorder (org.eclipse.draw2d.MarginBorder)1 MouseEvent (org.eclipse.draw2d.MouseEvent)1 MouseListener (org.eclipse.draw2d.MouseListener)1 EList (org.eclipse.emf.common.util.EList)1 JavaType (org.talend.core.model.metadata.types.JavaType)1 ColumnSash (org.talend.designer.gefabstractmap.figures.table.ColumnSash)1 TableColumn (org.talend.designer.gefabstractmap.figures.table.TableColumn)1 GlobalMapNodeEntityManager (org.talend.designer.xmlmap.figures.treeNode.GlobalMapNodeEntityManager)1 AbstractInOutTree (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree)1 AbstractNode (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode)1 INodeConnection (org.talend.designer.xmlmap.model.emf.xmlmap.INodeConnection)1 InputXmlTree (org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree)1 LookupConnection (org.talend.designer.xmlmap.model.emf.xmlmap.LookupConnection)1