Search in sources :

Example 21 with INodeConnector

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

the class JobletConnectionReconnectCommand method undo.

@Override
public void undo() {
    if (newSource != null) {
        INodeConnector connector = oldSource.getConnectorFromName(connectorName);
        connector.setCurLinkNbOutput(connector.getCurLinkNbOutput() + 1);
        connector = newSource.getConnectorFromName(connectorName);
        connector.setCurLinkNbOutput(connector.getCurLinkNbOutput() - 1);
        if (connection.getLineStyle().hasConnectionCategory(IConnectionCategory.FLOW)) {
            boolean builtInNewSource = newSource.getConnectorFromName(connectorName).isMultiSchema();
            boolean builtInOldSource = oldSource.getConnectorFromName(connectorName).isMultiSchema();
            if ((!builtInNewSource) && (!builtInOldSource)) {
                setSchemaToNotBuiltInNode(newSource, oldSource, oldMetadataTable);
                if (oldSource.getJobletNode() != null) {
                    connection.setMetaName(oldSource.getJobletNode().getUniqueName());
                } else
                    connection.setMetaName(oldSource.getUniqueName());
            } else {
                if (!builtInNewSource) {
                    oldSource.getMetadataList().add(oldMetadataTable);
                    connection.setMetaName(oldMetadataTable.getTableName());
                }
                if (!builtInOldSource) {
                    int num = 0;
                    for (int i = 0; i < newSource.getMetadataList().size(); i++) {
                        IMetadataTable meta = newSource.getMetadataList().get(i);
                        if (meta.getTableName().equals(connection.getUniqueName())) {
                            num = i;
                        }
                    }
                    newSource.getMetadataList().remove(num);
                    setSchemaToNotBuiltInNode(newSource, oldSource, oldMetadataTable);
                    if (oldSource.getJobletNode() != null) {
                        connection.setMetaName(oldSource.getJobletNode().getUniqueName());
                    } else
                        connection.setMetaName(oldSource.getUniqueName());
                }
                if ((builtInOldSource) && (builtInNewSource)) {
                    int num = 0;
                    for (int i = 0; i < newSource.getMetadataList().size(); i++) {
                        IMetadataTable meta = newSource.getMetadataList().get(i);
                        if (meta.getTableName().equals(oldMetadataTable.getTableName())) {
                            num = i;
                        }
                    }
                    newSource.getMetadataList().remove(num);
                    oldSource.getMetadataList().add(oldMetadataTable);
                }
            }
            if (newSourceSchemaType != null) {
                for (ChangeMetadataCommand cmd : metadataChanges) {
                    cmd.undo();
                }
                newSource.setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), newSourceSchemaType);
            }
            if (oldSourceSchemaType != null) {
                oldSource.setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), oldSourceSchemaType);
            }
        } else {
            if (oldSource.getJobletNode() != null) {
                connection.setMetaName(oldSource.getJobletNode().getUniqueName());
            } else
                connection.setMetaName(oldSource.getUniqueName());
        }
    } else if (newTarget != null) {
        INodeConnector connector = oldTarget.getConnectorFromType(oldLineStyle);
        connector.setCurLinkNbInput(connector.getCurLinkNbInput() + 1);
        connector = newTarget.getConnectorFromType(newLineStyle);
        connector.setCurLinkNbInput(connector.getCurLinkNbInput() - 1);
        if (newTargetSchemaType != null) {
            for (ChangeMetadataCommand cmd : metadataChanges) {
                cmd.undo();
            }
            newTarget.setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), newTargetSchemaType);
        }
    }
    connection.reconnect(oldSource, oldTarget, oldLineStyle);
    connection.updateName();
    ((Process) oldSource.getProcess()).checkStartNodes();
    ((Process) oldSource.getProcess()).checkProcess();
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) Process(org.talend.designer.core.ui.editor.process.Process) INodeConnector(org.talend.core.model.process.INodeConnector)

Example 22 with INodeConnector

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

the class JobletConnectionReconnectCommand method setSchemaToNotBuiltInNode.

private void setSchemaToNotBuiltInNode(INode oldNode, INode newNode, IMetadataTable newSchema) {
    if ((newNode.getMetadataList() != null) && newNode.getMetadataList().get(0).getListColumns().size() == 0) {
        // only override if there is no schema defined in the component
        if (oldMetadataTable == null) {
            return;
        }
        String sourceConnector = oldMetadataTable.getAttachedConnector();
        String baseConnector = oldNode.getConnectorFromName(sourceConnector).getBaseSchema();
        for (INodeConnector connector : newNode.getListConnector()) {
            if (connector.getBaseSchema().equals(baseConnector)) {
                IMetadataTable meta = newNode.getMetadataFromConnector(connector.getName());
                if (meta == null) {
                    continue;
                }
                if (newSchema != null) {
                    meta.setComment(newSchema.getComment());
                    MetadataToolHelper.copyTable(newSchema, meta);
                }
            }
        }
    }
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) INodeConnector(org.talend.core.model.process.INodeConnector)

Example 23 with INodeConnector

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

the class Component method createConnectors.

@Override
public List<INodeConnector> createConnectors(INode parentNode) {
    List<INodeConnector> listConnector = new ArrayList<>();
    ComponentProperties componentProperties = ComponentsUtils.getComponentProperties(getName());
    Set<? extends Connector> inputConnectors = componentProperties.getPossibleConnectors(false);
    if (inputConnectors.isEmpty()) {
        INodeConnector connector = null;
        connector = addStandardType(listConnector, EConnectionType.FLOW_MAIN, parentNode);
        connector.setMaxLinkInput(0);
        connector.setMaxLinkOutput(0);
    } else {
        for (Connector connector : inputConnectors) {
            addGenericType(listConnector, EConnectionType.FLOW_MAIN, connector.getName(), parentNode, componentProperties, false);
        }
    }
    Set<? extends Connector> outputConnectors = componentProperties.getPossibleConnectors(true);
    List<? extends Connector> sortedOutputConnectors = new ArrayList<>(outputConnectors);
    sortedOutputConnectors.sort(new Comparator<Connector>() {

        @Override
        public int compare(Connector o1, Connector o2) {
            if (Connector.MAIN_NAME.equals(o1.getName())) {
                return -1;
            }
            if (Connector.MAIN_NAME.equals(o2.getName())) {
                return 1;
            }
            return 0;
        }
    });
    for (Connector connector : sortedOutputConnectors) {
        EConnectionType type = EConnectionType.FLOW_MAIN;
        if (Connector.REJECT_NAME.equals(connector.getName())) {
            type = EConnectionType.REJECT;
        }
        addGenericType(listConnector, type, connector.getName(), parentNode, componentProperties, true);
    }
    addStandardType(listConnector, EConnectionType.RUN_IF, parentNode);
    addStandardType(listConnector, EConnectionType.ON_COMPONENT_OK, parentNode);
    addStandardType(listConnector, EConnectionType.ON_COMPONENT_ERROR, parentNode);
    addStandardType(listConnector, EConnectionType.ON_SUBJOB_OK, parentNode);
    addStandardType(listConnector, EConnectionType.ON_SUBJOB_ERROR, parentNode);
    Set<ConnectorTopology> topologies = componentDefinition.getSupportedConnectorTopologies();
    createIterateConnectors(topologies, listConnector, parentNode);
    for (int i = 0; i < EConnectionType.values().length; i++) {
        EConnectionType currentType = EConnectionType.values()[i];
        if ((currentType == EConnectionType.FLOW_REF) || (currentType == EConnectionType.FLOW_MERGE)) {
            continue;
        }
        boolean exists = false;
        for (INodeConnector curNodeConn : listConnector) {
            if (curNodeConn.getDefaultConnectionType().equals(currentType)) {
                exists = true;
                if (currentType == EConnectionType.FLOW_MAIN) {
                    curNodeConn.addConnectionProperty(EConnectionType.FLOW_REF, EConnectionType.FLOW_REF.getRGB(), EConnectionType.FLOW_REF.getDefaultLineStyle());
                    curNodeConn.addConnectionProperty(EConnectionType.FLOW_MERGE, EConnectionType.FLOW_MERGE.getRGB(), EConnectionType.FLOW_MERGE.getDefaultLineStyle());
                }
            }
        }
        if (!exists) {
            // will add by default all connectors not defined in
            NodeConnector nodeConnector = new NodeConnector(parentNode);
            nodeConnector.setDefaultConnectionType(currentType);
            nodeConnector.setName(currentType.getName());
            nodeConnector.setBaseSchema(currentType.getName());
            nodeConnector.addConnectionProperty(currentType, currentType.getRGB(), currentType.getDefaultLineStyle());
            nodeConnector.setLinkName(currentType.getDefaultLinkName());
            nodeConnector.setMenuName(currentType.getDefaultMenuName());
            if ((currentType == EConnectionType.PARALLELIZE) || (currentType == EConnectionType.SYNCHRONIZE)) {
                nodeConnector.setMaxLinkInput(1);
            } else {
                nodeConnector.setMaxLinkInput(0);
            }
            nodeConnector.setMaxLinkOutput(0);
            nodeConnector.setMinLinkInput(0);
            nodeConnector.setMinLinkOutput(0);
            listConnector.add(nodeConnector);
        }
    }
    return listConnector;
}
Also used : PropertyPathConnector(org.talend.components.api.component.PropertyPathConnector) INodeConnector(org.talend.core.model.process.INodeConnector) Connector(org.talend.components.api.component.Connector) NodeConnector(org.talend.designer.core.model.components.NodeConnector) ComponentProperties(org.talend.components.api.properties.ComponentProperties) INodeConnector(org.talend.core.model.process.INodeConnector) NodeConnector(org.talend.designer.core.model.components.NodeConnector) ArrayList(java.util.ArrayList) INodeConnector(org.talend.core.model.process.INodeConnector) EConnectionType(org.talend.core.model.process.EConnectionType) ConnectorTopology(org.talend.components.api.component.ConnectorTopology)

Example 24 with INodeConnector

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

the class ComponentChooseDialog method updateConnectionCommand.

private void updateConnectionCommand(org.talend.designer.core.ui.editor.connections.Connection connection, Node node, CompoundCommand command) {
    if (connection != null || node != null) {
        Node originalTarget = (Node) connection.getTarget();
        INodeConnector targetConnector = node.getConnectorFromType(EConnectionType.FLOW_MAIN);
        for (INodeConnector connector : node.getConnectorsFromType(EConnectionType.FLOW_MAIN)) {
            if (connector.getMaxLinkOutput() != 0) {
                targetConnector = connector;
                break;
            }
        }
        ConnectionCreateCommand.setCreatingConnection(true);
        EConnectionType reconnectNewInputStyle = connection.getLineStyle();
        if (ConnectionManager.canConnectToTarget(connection.getSource(), originalTarget, node, connection.getLineStyle(), connection.getName(), targetConnector.getName())) {
            reconnectNewInputStyle = ConnectionManager.getNewConnectionType();
        }
        if (reconnectNewInputStyle.equals(EConnectionType.FLOW_MAIN)) {
            connection.reconnect(connection.getSource(), node, EConnectionType.FLOW_MAIN);
        } else if (reconnectNewInputStyle.equals(EConnectionType.FLOW_MERGE)) {
            connection.reconnect(connection.getSource(), node, EConnectionType.FLOW_MERGE);
        } else if (reconnectNewInputStyle.equals(EConnectionType.FLOW_REF)) {
            connection.reconnect(connection.getSource(), node, EConnectionType.FLOW_REF);
        }
        INodeConnector nodeConnector = node.getConnectorFromName(targetConnector.getName());
        nodeConnector.setCurLinkNbInput(nodeConnector.getCurLinkNbInput() + 1);
        List<Object> nodeArgs = CreateComponentOnLinkHelper.getTargetArgs(connection, node);
        ConnectionCreateCommand nodeCmd = new ConnectionCreateCommand(node, targetConnector.getName(), nodeArgs, false);
        nodeCmd.setTarget(originalTarget);
        INodeConnector originalNodeConnector = originalTarget.getConnectorFromName(connection.getTargetNodeConnector().getName());
        originalNodeConnector.setCurLinkNbInput(originalNodeConnector.getCurLinkNbInput() - 1);
        command.add(nodeCmd);
    }
}
Also used : 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) ConnectionCreateCommand(org.talend.designer.core.ui.editor.cmd.ConnectionCreateCommand) 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) EConnectionType(org.talend.core.model.process.EConnectionType) INodeConnector(org.talend.core.model.process.INodeConnector)

Example 25 with INodeConnector

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

the class CreateComponentOnLinkHelper method canCreateNodeOnLink.

public static boolean canCreateNodeOnLink(org.talend.designer.core.ui.editor.connections.Connection connection, Node node) {
    if (connection != null && node != null) {
        if (GlobalServiceRegister.getDefault().isServiceRegistered(ICamelDesignerCoreService.class)) {
            ICamelDesignerCoreService camelService = (ICamelDesignerCoreService) GlobalServiceRegister.getDefault().getService(ICamelDesignerCoreService.class);
            if (camelService.isRouteBuilderNode(node)) {
                return camelService.canCreateNodeOnLink(connection, node);
            }
        }
        INode source = connection.getSource();
        INodeConnector sourceConnector = connection.getSourceNodeConnector();
        INode target = connection.getTarget();
        INodeConnector targetConnector = node.getConnectorFromType(EConnectionType.FLOW_MAIN);
        for (INodeConnector connector : node.getConnectorsFromType(EConnectionType.FLOW_MAIN)) {
            if (connector.getMaxLinkOutput() != 0) {
                targetConnector = connector;
                break;
            }
        }
        EConnectionType outputConnectionType = node.getConnectorFromName(targetConnector.getName()).getDefaultConnectionType();
        // only consider Flow connection
        EConnectionType connectionType = source.getConnectorFromName(sourceConnector.getName()).getDefaultConnectionType();
        if (connectionType.hasConnectionCategory(EConnectionType.FLOW)) {
            boolean b1 = ConnectionManager.canConnectToTarget(source, null, node, connectionType, sourceConnector.getName(), null);
            boolean b2 = ConnectionManager.canConnectToSource(source, node, target, outputConnectionType, targetConnector.getName(), null, true);
            return b1 && b2;
        }
    }
    return false;
}
Also used : INode(org.talend.core.model.process.INode) ICamelDesignerCoreService(org.talend.designer.core.ICamelDesignerCoreService) EConnectionType(org.talend.core.model.process.EConnectionType) INodeConnector(org.talend.core.model.process.INodeConnector)

Aggregations

INodeConnector (org.talend.core.model.process.INodeConnector)76 ArrayList (java.util.ArrayList)37 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)31 INode (org.talend.core.model.process.INode)31 Node (org.talend.designer.core.ui.editor.nodes.Node)31 IConnection (org.talend.core.model.process.IConnection)27 IElementParameter (org.talend.core.model.process.IElementParameter)22 Process (org.talend.designer.core.ui.editor.process.Process)21 List (java.util.List)20 Connection (org.talend.designer.core.ui.editor.connections.Connection)17 IJobletProviderService (org.talend.core.ui.IJobletProviderService)14 HashMap (java.util.HashMap)11 NodeConnector (org.talend.designer.core.model.components.NodeConnector)11 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)9 EConnectionType (org.talend.core.model.process.EConnectionType)9 Map (java.util.Map)8 IExternalNode (org.talend.core.model.process.IExternalNode)7 IProcess (org.talend.core.model.process.IProcess)7 RepositoryNode (org.talend.repository.model.RepositoryNode)7 Point (org.eclipse.draw2d.geometry.Point)6