Search in sources :

Example 11 with VarNodeEditPart

use of org.talend.designer.xmlmap.parts.VarNodeEditPart in project tdi-studio-se by Talend.

the class InsertNewColumnCommand method execute.

@Override
public void execute() {
    if (rq == null || objects.getToTransfer() == null || targetEditPart == null || dropType == null) {
        return;
    }
    Object targetModel = targetEditPart.getModel();
    for (Object obj : objects.getToTransfer()) {
        AbstractNode createdNode = rq.getNewObject();
        // INPUT => OUTPUT INSERT
        if (objects.getType() == TransferdType.INPUT) {
            TreeNodeEditPart part = (TreeNodeEditPart) obj;
            TreeNode sourceNode = (TreeNode) part.getModel();
            String expression = XmlMapUtil.convertToExpression(sourceNode.getXpath());
            switch(dropType) {
                case DROP_INSERT_OUTPUT:
                    int index = -1;
                    OutputXmlTree outputTree = null;
                    if (targetModel instanceof OutputTreeNode) {
                        OutputTreeNode targetNode = (OutputTreeNode) targetModel;
                        if (targetNode.eContainer() instanceof OutputXmlTree) {
                            outputTree = (OutputXmlTree) targetNode.eContainer();
                            index = outputTree.getNodes().indexOf(targetNode);
                        }
                    } else if (targetModel instanceof OutputXmlTree) {
                        outputTree = (OutputXmlTree) targetModel;
                    }
                    if (outputTree != null) {
                        boolean fillNode = fillTreeNode(outputTree.getNodes(), sourceNode, outputTree.getName(), expression, (OutputTreeNode) createdNode);
                        if (!fillNode) {
                            return;
                        }
                        if (index != -1) {
                            outputTree.getNodes().add(index, (OutputTreeNode) createdNode);
                        } else {
                            outputTree.getNodes().add((OutputTreeNode) createdNode);
                        }
                        createConnection(sourceNode, createdNode);
                        AbstractInOutTree abstractTree = XmlMapUtil.getAbstractInOutTree(sourceNode);
                        createOutputMetadataColumn(abstractTree.getName(), outputTree.getName(), sourceNode, createdNode.getName(), index);
                    }
                    break;
                case DROP_INSERT_VAR:
                    VarNode targetVar = (VarNode) targetModel;
                    VarNode varNode = (VarNode) createdNode;
                    if (targetVar.eContainer() instanceof VarTable) {
                        VarTable varTable = (VarTable) targetVar.eContainer();
                        String validSourceName = validSourceNodeName(varTable.getNodes(), sourceNode);
                        String name = getUniqueTableEntry(varTable.getNodes(), validSourceName);
                        varNode.setName(name);
                        varNode.setType(sourceNode.getType());
                        varNode.setExpression(expression);
                        varTable.getNodes().add(varTable.getNodes().indexOf(targetVar), varNode);
                        createConnection(sourceNode, createdNode);
                    }
                    break;
                case DROP_INSERT_INPUT:
                    if (targetModel instanceof InputXmlTree) {
                        InputXmlTree inputTree = (InputXmlTree) targetModel;
                        boolean fillNode = fillTreeNode(inputTree.getNodes(), sourceNode, inputTree.getName(), expression, (TreeNode) createdNode);
                        if (!fillNode) {
                            return;
                        }
                        inputTree.getNodes().add((TreeNode) createdNode);
                        createLookupConnection(sourceNode, (TreeNode) createdNode);
                        AbstractInOutTree abstractTree = XmlMapUtil.getAbstractInOutTree(sourceNode);
                        createInputMetadataColumn(abstractTree.getName(), inputTree.getName(), sourceNode, createdNode.getName(), -1);
                    }
                default:
                    break;
            }
        } else // VAR => OUTPUT INSERT
        if (objects.getType() == TransferdType.VAR) {
            VarNodeEditPart part = (VarNodeEditPart) obj;
            VarNode sourceNode = (VarNode) part.getModel();
            //$NON-NLS-1$
            String tableName = "Var";
            if (sourceNode.eContainer() instanceof VarTable) {
                tableName = ((VarTable) sourceNode.eContainer()).getName();
            }
            //$NON-NLS-1$
            String expression = tableName + "." + sourceNode.getName();
            if (dropType == DropType.DROP_INSERT_OUTPUT) {
                int index = -1;
                OutputXmlTree outputTree = null;
                if (targetModel instanceof OutputTreeNode) {
                    OutputTreeNode targetNode = (OutputTreeNode) targetModel;
                    if (targetNode.eContainer() instanceof OutputXmlTree) {
                        outputTree = (OutputXmlTree) targetNode.eContainer();
                        index = outputTree.getNodes().indexOf(targetNode);
                    }
                } else if (targetModel instanceof OutputXmlTree) {
                    outputTree = (OutputXmlTree) targetModel;
                }
                if (outputTree != null) {
                    OutputTreeNode outputNode = (OutputTreeNode) createdNode;
                    String name = getUniqueTableEntry(outputTree.getNodes(), sourceNode.getName());
                    outputNode.setName(name);
                    outputNode.setType(sourceNode.getType());
                    outputNode.setExpression(expression);
                    outputNode.setXpath(XmlMapUtil.getXPath(outputTree.getName(), outputNode.getName(), outputNode.getNodeType()));
                    if (index != -1) {
                        outputTree.getNodes().add(index, (OutputTreeNode) createdNode);
                    } else {
                        outputTree.getNodes().add((OutputTreeNode) createdNode);
                    }
                    createConnection(sourceNode, createdNode);
                    createOutputMetadataColumn(null, outputTree.getName(), sourceNode, createdNode.getName(), index);
                // List<IMetadataTable> metadataTargets = manager.getMapperComponent().getMetadataList();
                // IMetadataTable metadataTarget = null;
                // if (metadataTargets != null) {
                // for (IMetadataTable target : metadataTargets) {
                // if (target.getTableName().equals(outputTree.getName())) {
                // metadataTarget = target;
                // }
                // }
                // if (metadataTarget != null) {
                // IMetadataColumn createNewColumn = new MetadataColumn();
                // createNewColumn.setLabel(outputNode.getName());
                // createNewColumn.setTalendType(outputNode.getType());
                // createNewColumn.setNullable(true);
                // metadataTarget.getListColumns().add(createNewColumn);
                // }
                // }
                }
            }
        }
    }
    switch(dropType) {
        case DROP_INSERT_OUTPUT:
            manager.getMapperUI().getTabFolderEditors().getOutputMetaEditorView().getTableViewerCreator().refresh();
        case DROP_INSERT_INPUT:
            manager.getMapperUI().getTabFolderEditors().getOutputMetaEditorView().getTableViewerCreator().refresh();
    }
}
Also used : VarNode(org.talend.designer.xmlmap.model.emf.xmlmap.VarNode) VarNodeEditPart(org.talend.designer.xmlmap.parts.VarNodeEditPart) AbstractNode(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode) AbstractInOutTree(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNodeEditPart(org.talend.designer.xmlmap.parts.TreeNodeEditPart) VarTable(org.talend.designer.xmlmap.model.emf.xmlmap.VarTable) 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) TransferedObject(org.talend.designer.gefabstractmap.dnd.TransferedObject) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree)

Example 12 with VarNodeEditPart

use of org.talend.designer.xmlmap.parts.VarNodeEditPart 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

VarNodeEditPart (org.talend.designer.xmlmap.parts.VarNodeEditPart)12 VarNode (org.talend.designer.xmlmap.model.emf.xmlmap.VarNode)10 TreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode)9 TreeNodeEditPart (org.talend.designer.xmlmap.parts.TreeNodeEditPart)9 TransferedObject (org.talend.designer.gefabstractmap.dnd.TransferedObject)7 OutputTreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode)7 VarTable (org.talend.designer.xmlmap.model.emf.xmlmap.VarTable)6 OutputTreeNodeEditPart (org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart)6 AbstractNode (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 EditPart (org.eclipse.gef.EditPart)4 Command (org.eclipse.gef.commands.Command)4 EList (org.eclipse.emf.common.util.EList)3 CommandStack (org.eclipse.gef.commands.CommandStack)3 AbstractInOutTree (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree)3 FilterConnection (org.talend.designer.xmlmap.model.emf.xmlmap.FilterConnection)3 Point (org.eclipse.draw2d.geometry.Point)2 Shell (org.eclipse.swt.widgets.Shell)2 TableEntityPart (org.talend.designer.gefabstractmap.part.TableEntityPart)2