Search in sources :

Example 26 with EConnectionType

use of org.talend.core.model.process.EConnectionType in project tdi-studio-se by Talend.

the class CreateComponentOnLinkHelper method getTargetArgs.

public static List<Object> getTargetArgs(Connection connection, Node node) {
    List<Object> connArgs = new ArrayList<Object>();
    IMetadataTable meta = null;
    String connectName = null;
    INodeConnector connector = node.getConnectorFromType(EConnectionType.FLOW_MAIN);
    for (INodeConnector tconnector : node.getConnectorsFromType(EConnectionType.FLOW_MAIN)) {
        if (connector.getMaxLinkOutput() != 0) {
            connector = tconnector;
            break;
        }
    }
    EConnectionType connectType = node.getConnectorFromName(connector.getName()).getDefaultConnectionType();
    if (connectType.hasConnectionCategory(EConnectionType.FLOW)) {
        // String name = "*New Output*" + " (" + connector.getMenuName() + ")";
        if (node.getConnectorFromName(connector.getName()).isMultiSchema()) {
            String tableName = connection.getMetaName();
            meta = connection.getSource().getMetadataTable(tableName);
            if (connector.isMultiSchema()) {
                if (connection.getTarget().getConnectorFromName(node.getConnectorFromName(connector.getName()).getName()).isMultiSchema()) {
                // Connection conn = (Connection) connection.getTarget().getIncomingConnections().get(0);
                // node.getMetadataList().add(conn.getMetadataTable());
                } else {
                    MetadataTable table = (MetadataTable) connection.getTarget().getMetadataList().get(0).clone();
                    table.setLabel(tableName);
                    node.getMetadataList().add(table);
                }
            }
        } else {
            if (node.getMetadataList().size() == 0) {
                meta = null;
            } else {
                meta = node.getMetadataFromConnector(connector.getName());
            }
            connectName = node.getProcess().generateUniqueConnectionName(Process.DEFAULT_ROW_CONNECTION_NAME);
        }
        if (connectType.equals(EConnectionType.FLOW_MAIN) || connectType.equals(EConnectionType.FLOW_REF)) {
            if (meta == null) {
                connArgs.add(null);
            } else {
                connArgs.add(meta.getTableName());
            }
        } else {
            connArgs.add(node.getUniqueName());
        }
        String baseName = node.getConnectionName();
        String fromConnectionName = null;
        if (node.getProcess().checkValidConnectionName(baseName)) {
            fromConnectionName = node.getProcess().generateUniqueConnectionName(baseName);
        }
        if (fromConnectionName != null && connectType.hasConnectionCategory(IConnectionCategory.FLOW) && node.getProcess().checkValidConnectionName(fromConnectionName, false) && !connector.isMultiSchema()) {
            connArgs.add(fromConnectionName);
        } else {
            connArgs.add(connectName);
        }
        connArgs.add(null);
    }
    return connArgs;
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) ArrayList(java.util.ArrayList) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.MetadataTable) EConnectionType(org.talend.core.model.process.EConnectionType) INodeConnector(org.talend.core.model.process.INodeConnector)

Example 27 with EConnectionType

use of org.talend.core.model.process.EConnectionType in project tdi-studio-se by Talend.

the class DummyNodeAnchor method getDirectionPosition.

private Point getDirectionPosition(Point figCenter, Point reference) {
    Dimension nodeSize = this.source.getSize();
    EConnectionCategory category = null;
    EConnectionType lineStyle = null;
    if (connection != null) {
        lineStyle = connection.getLineStyle();
        category = lineStyle.getCategory();
    } else {
        lineStyle = ConnectionManager.getNewConnectionType();
        category = lineStyle.getCategory();
    }
    Point result = new Point(figCenter);
    if (category == EConnectionCategory.MAIN && lineStyle != EConnectionType.FLOW_REF) {
        if (!isTargetAnchor) {
            result.x = figCenter.x + nodeSize.width / 2;
        } else {
            result.x = figCenter.x - nodeSize.width / 2;
        }
        return result;
    } else if (category == EConnectionCategory.OTHER && (lineStyle == EConnectionType.FLOW_REF || lineStyle == EConnectionType.TABLE_REF)) {
        if (target != null) {
            int sourceY = this.source.getPosY();
            int targetY = this.target.getPosY();
            Rectangle sourceBounds = new Rectangle(this.source.getLocation(), this.source.getSize());
            Rectangle targetBounds = new Rectangle(this.target.getLocation(), this.target.getSize());
            if (!isTargetAnchor) {
                if (target.equals(source)) {
                    Point tempPoint = new Point(reference.x - nodeSize.width / 2, reference.y - nodeSize.height / 2);
                    targetBounds = new Rectangle(tempPoint, this.target.getSize());
                    targetY = reference.y - nodeSize.height / 2;
                }
                if (sourceY <= targetY) {
                    if ((targetBounds.getTopRight().y == sourceBounds.getBottomLeft().y)) {
                        result.y = figCenter.y - nodeSize.height / 2;
                    } else {
                        result.y = figCenter.y + nodeSize.height / 2;
                    }
                } else {
                    if (targetBounds.getBottomLeft().y == sourceBounds.getTopRight().y) {
                        result.y = figCenter.y + nodeSize.height / 2;
                    } else {
                        result.y = figCenter.y - nodeSize.height / 2;
                    }
                }
                return result;
            }
            //
            if (sourceY < targetY) {
                result.y = figCenter.y - nodeSize.height / 2;
            } else {
                result.y = figCenter.y + nodeSize.height / 2;
            }
            return result;
        }
    }
    return null;
}
Also used : Rectangle(org.eclipse.draw2d.geometry.Rectangle) EConnectionCategory(org.talend.core.model.process.EConnectionCategory) Dimension(org.eclipse.draw2d.geometry.Dimension) Point(org.eclipse.draw2d.geometry.Point) EConnectionType(org.talend.core.model.process.EConnectionType)

Example 28 with EConnectionType

use of org.talend.core.model.process.EConnectionType in project tdi-studio-se by Talend.

the class ComponentChooseDialog method createComponentOnLink.

private boolean createComponentOnLink(Node node, Point originalPoint) {
    boolean executed = false;
    RootEditPart rep = editor.getViewer().getRootEditPart().getRoot();
    Point viewOriginalPosition = new Point();
    if (rep instanceof ScalableFreeformRootEditPart) {
        ScalableFreeformRootEditPart root = (ScalableFreeformRootEditPart) rep;
        Viewport viewport = (Viewport) root.getFigure();
        viewOriginalPosition = viewport.getViewLocation();
    }
    Point point = new Point(originalPoint.x + viewOriginalPosition.x, originalPoint.y + viewOriginalPosition.y);
    point.x = (int) (point.x / AnimatableZoomManager.currentZoom);
    point.y = (int) (point.y / AnimatableZoomManager.currentZoom);
    org.talend.designer.core.ui.editor.connections.Connection targetConnection = null;
    if (selectedConnectionPart != null) {
        targetConnection = (org.talend.designer.core.ui.editor.connections.Connection) selectedConnectionPart.getModel();
    }
    if (targetConnection != null) {
        IProcess2 p = editor.getProcess();
        NodeContainer nodeContainer = ((Process) node.getProcess()).loadNodeContainer(node, false);
        // TDI-21099
        if (p instanceof Process) {
            CreateNodeContainerCommand createCmd = new CreateNodeContainerCommand((Process) p, nodeContainer, point);
            execCommandStack(createCmd);
            // reconnect the node
            Node originalTarget = (Node) targetConnection.getTarget();
            EConnectionType connectionType = EConnectionType.FLOW_MAIN;
            if (GlobalServiceRegister.getDefault().isServiceRegistered(ICamelDesignerCoreService.class)) {
                ICamelDesignerCoreService camelService = (ICamelDesignerCoreService) GlobalServiceRegister.getDefault().getService(ICamelDesignerCoreService.class);
                if (camelService.isRouteBuilderNode(node)) {
                    connectionType = camelService.getTargetConnectionType(node);
                }
            }
            INodeConnector targetConnector = node.getConnectorFromType(connectionType);
            for (INodeConnector connector : node.getConnectorsFromType(connectionType)) {
                if (connector.getMaxLinkOutput() != 0) {
                    targetConnector = connector;
                    break;
                }
            }
            ConnectionCreateCommand.setCreatingConnection(true);
            // bug 21411
            if (PluginChecker.isJobLetPluginLoaded()) {
                IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
                if (service != null && service.isJobletComponent(targetConnection.getTarget())) {
                    if (targetConnection.getTarget() instanceof Node) {
                        NodeContainer jobletContainer = ((Node) targetConnection.getTarget()).getNodeContainer();
                        // remove the old connection in the container
                        jobletContainer.getInputs().remove(targetConnection);
                    }
                }
            }
            ConnectionReconnectCommand cmd2 = new ConnectionReconnectCommand(targetConnection);
            cmd2.setNewTarget(node);
            execCommandStack(cmd2);
            List<Object> nodeArgs = CreateComponentOnLinkHelper.getTargetArgs(targetConnection, node);
            ConnectionCreateCommand nodeCmd = new ConnectionCreateCommand(node, targetConnector.getName(), nodeArgs, false);
            nodeCmd.setTarget(originalTarget);
            execCommandStack(nodeCmd);
            // Setting,such as the target is TMap
            if (node.getOutgoingConnections().size() > 0) {
                if (node.getExternalNode() instanceof MapperExternalNode) {
                    CreateComponentOnLinkHelper.setupTMap(node);
                }
                if (originalTarget.getExternalNode() instanceof MapperExternalNode) {
                    CreateComponentOnLinkHelper.updateTMap(originalTarget, targetConnection, node.getOutgoingConnections().get(0));
                }
                originalTarget.renameData(targetConnection.getName(), node.getOutgoingConnections().get(0).getName());
            }
            if (!ConnectionCreateCommand.isCreatingConnection()) {
                return true;
            }
            executed = true;
        }
    }
    return executed;
}
Also used : ICamelDesignerCoreService(org.talend.designer.core.ICamelDesignerCoreService) INode(org.talend.core.model.process.INode) RepositoryNode(org.talend.repository.model.RepositoryNode) HL7FileNode(org.talend.core.model.metadata.builder.connection.HL7FileNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) Node(org.talend.designer.core.ui.editor.nodes.Node) IExternalNode(org.talend.core.model.process.IExternalNode) XMLFileNode(org.talend.core.model.metadata.builder.connection.XMLFileNode) MapperExternalNode(org.talend.core.model.process.node.MapperExternalNode) Viewport(org.eclipse.draw2d.Viewport) NodeContainer(org.talend.designer.core.ui.editor.nodecontainer.NodeContainer) IProcess(org.talend.core.model.process.IProcess) Point(org.eclipse.draw2d.geometry.Point) INodeConnector(org.talend.core.model.process.INodeConnector) ConnectionReconnectCommand(org.talend.designer.core.ui.editor.cmd.ConnectionReconnectCommand) IJobletProviderService(org.talend.core.ui.IJobletProviderService) CreateNodeContainerCommand(org.talend.designer.core.ui.editor.cmd.CreateNodeContainerCommand) TalendScalableFreeformRootEditPart(org.talend.designer.core.ui.editor.TalendScalableFreeformRootEditPart) ScalableFreeformRootEditPart(org.eclipse.gef.editparts.ScalableFreeformRootEditPart) ConnectionCreateCommand(org.talend.designer.core.ui.editor.cmd.ConnectionCreateCommand) IProcess2(org.talend.core.model.process.IProcess2) SAPFunctionRepositoryObject(org.talend.core.repository.model.repositoryObject.SAPFunctionRepositoryObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) QueryRepositoryObject(org.talend.core.repository.model.repositoryObject.QueryRepositoryObject) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject) SalesforceModuleRepositoryObject(org.talend.core.repository.model.repositoryObject.SalesforceModuleRepositoryObject) MetadataColumnRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject) SAPIDocRepositoryObject(org.talend.core.repository.model.repositoryObject.SAPIDocRepositoryObject) MapperExternalNode(org.talend.core.model.process.node.MapperExternalNode) EConnectionType(org.talend.core.model.process.EConnectionType) TalendScalableFreeformRootEditPart(org.talend.designer.core.ui.editor.TalendScalableFreeformRootEditPart) RootEditPart(org.eclipse.gef.RootEditPart) ScalableFreeformRootEditPart(org.eclipse.gef.editparts.ScalableFreeformRootEditPart)

Example 29 with EConnectionType

use of org.talend.core.model.process.EConnectionType in project tdi-studio-se by Talend.

the class ConnectionAddUniqueNameMigrationTask method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
     */
@Override
public ExecutionResult execute(Item item) {
    try {
        uniqueConnectionNameList.clear();
        ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
        ProcessType processType = getProcessType(item);
        boolean modified = false;
        if (processType != null) {
            for (Object o : processType.getConnection()) {
                ConnectionType currentConnection = (ConnectionType) o;
                ElementParameterType uniqueNameParam = null;
                for (Object paramObject : currentConnection.getElementParameter()) {
                    ElementParameterType paramType = (ElementParameterType) paramObject;
                    if (UNIQUE_NAME.equals(paramType.getName())) {
                        uniqueNameParam = paramType;
                    }
                }
                if (uniqueNameParam == null) {
                    uniqueNameParam = TalendFileFactory.eINSTANCE.createElementParameterType();
                    uniqueNameParam.setName("UNIQUE_NAME");
                    uniqueNameParam.setField(EParameterFieldType.TEXT.getName());
                    uniqueNameParam.setContextMode(false);
                    currentConnection.getElementParameter().add(uniqueNameParam);
                }
                String value = uniqueNameParam.getValue();
                String baseName = "";
                if (value == null || "".equals(value)) {
                    modified = true;
                    EConnectionType connectionType = EConnectionType.getTypeFromId(currentConnection.getLineStyle());
                    if (connectionType.hasConnectionCategory(IConnectionCategory.UNIQUE_NAME) && connectionType.hasConnectionCategory(IConnectionCategory.FLOW)) {
                        baseName = null;
                    } else if (connectionType.equals(EConnectionType.ITERATE)) {
                        baseName = "iterate";
                    } else if (connectionType.equals(EConnectionType.TABLE)) {
                        baseName = null;
                    } else if (connectionType.equals(EConnectionType.SYNCHRONIZE) || connectionType.equals(EConnectionType.PARALLELIZE)) {
                        baseName = null;
                    } else {
                        baseName = connectionType.getDefaultLinkName();
                    }
                    String uniqueName = "";
                    if (connectionType.equals(EConnectionType.TABLE)) {
                        uniqueName = currentConnection.getMetaname();
                    } else {
                        uniqueName = currentConnection.getLabel();
                    }
                    if (baseName != null && !"".equals(baseName)) {
                        uniqueName = generateUniqueConnectionName(baseName);
                    }
                    uniqueNameParam.setValue(uniqueName);
                    uniqueConnectionNameList.add(uniqueName);
                }
            }
        }
        if (modified) {
            factory.save(item, true);
            return ExecutionResult.SUCCESS_WITH_ALERT;
        } else {
            return ExecutionResult.SUCCESS_NO_ALERT;
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) ConnectionType(org.talend.designer.core.model.utils.emf.talendfile.ConnectionType) EConnectionType(org.talend.core.model.process.EConnectionType) EConnectionType(org.talend.core.model.process.EConnectionType) MalformedPatternException(org.apache.oro.text.regex.MalformedPatternException)

Example 30 with EConnectionType

use of org.talend.core.model.process.EConnectionType in project tdi-studio-se by Talend.

the class ConnectionCreateActionTest method testRun1.

private void testRun1() {
    EConnectionType ct = EConnectionType.TABLE;
    String text = "TALEND.JOBS (Table)";
    int end = text.length() - 1;
    //$NON-NLS-1$
    int start = text.lastIndexOf("(") + 1;
    String tableName = text.substring(start, end);
    assertEquals("Table", tableName);
    IMetadataTable meta = node.getMetadataTable("JOBS");
    String connectionName = meta.getLabel();
    assertEquals(connectionName, "JOBS");
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) EConnectionType(org.talend.core.model.process.EConnectionType)

Aggregations

EConnectionType (org.talend.core.model.process.EConnectionType)32 INode (org.talend.core.model.process.INode)9 INodeConnector (org.talend.core.model.process.INodeConnector)9 ArrayList (java.util.ArrayList)8 IConnection (org.talend.core.model.process.IConnection)7 Node (org.talend.designer.core.ui.editor.nodes.Node)7 Point (org.eclipse.draw2d.geometry.Point)5 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)5 List (java.util.List)4 EConnectionCategory (org.talend.core.model.process.EConnectionCategory)4 Dimension (org.eclipse.draw2d.geometry.Dimension)3 Rectangle (org.eclipse.draw2d.geometry.Rectangle)3 ConnectionType (org.talend.designer.core.model.utils.emf.talendfile.ConnectionType)3 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)3 MalformedPatternException (org.apache.oro.text.regex.MalformedPatternException)2 PointList (org.eclipse.draw2d.geometry.PointList)2 CreateConnectionRequest (org.eclipse.gef.requests.CreateConnectionRequest)2 IComponentConversion (org.talend.core.model.components.conversions.IComponentConversion)2 IComponentFilter (org.talend.core.model.components.filters.IComponentFilter)2 HL7FileNode (org.talend.core.model.metadata.builder.connection.HL7FileNode)2