Search in sources :

Example 51 with INodeConnector

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

the class ConnectionManager method canConnectToTarget.

public static boolean canConnectToTarget(INode source, INode oldTarget, INode newTarget, EConnectionType lineStyle, String connectorName, String connectionName, boolean refactorJoblet) {
    newlineStyle = lineStyle;
    if (source.equals(newTarget)) {
        return false;
    }
    if (PluginChecker.isJobLetPluginLoaded()) {
        IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
        if (service != null) {
            if (service.isTriggerNode(newTarget) && !service.canConnectTriggerNode(newTarget, lineStyle)) {
                return false;
            }
            // can't connect from joblet's node, bug 21411
            if (service.isJobletComponent(source.getJobletNode())) {
                return false;
            }
        }
    }
    INode processStartNode = source.getProcessStartNode(true);
    // if the target is the start of the (source) process, then can't connect.
    if (processStartNode.equals(newTarget)) {
        return false;
    }
    // to avoid different db elt input link to map.
    if (newTarget.isELTComponent() && newTarget.getComponent().getName().endsWith("Map")) {
        //$NON-NLS-1$
        String targetName = newTarget.getComponent().getOriginalFamilyName();
        String sourceName = processStartNode.getComponent().getOriginalFamilyName();
        if (!targetName.equals(sourceName) && !(lineStyle.hasConnectionCategory(IConnectionCategory.DEPENDENCY))) {
            return false;
        }
    }
    // fix bug 0004935: Error on job save
    if (checkCircle(source, newTarget)) {
        return false;
    }
    if (newTarget.isFileScaleComponent()) {
        if (newlineStyle.hasConnectionCategory(IConnectionCategory.FLOW) && !connectorName.equals("FSCOMBINE")) {
            //$NON-NLS-1$
            return false;
        }
    }
    // Modify Connection Type depending old and new target.
    if (newlineStyle.hasConnectionCategory(IConnectionCategory.FLOW)) {
        // if the connection type is not the default one, then we don't change automatically.
        // && newlineStyle.getName().equals(newConnectionType)) {
        newlineStyle = EConnectionType.FLOW_MAIN;
        if (newTarget.getComponent().useLookup()) {
            int nbMain = 0;
            for (IConnection connec : newTarget.getIncomingConnections()) {
                if (connec.getLineStyle().equals(EConnectionType.FLOW_MAIN)) {
                    nbMain++;
                }
            }
            if (nbMain >= 1) {
                newlineStyle = EConnectionType.FLOW_REF;
            } else {
                newlineStyle = EConnectionType.FLOW_MAIN;
            }
        } else if (newTarget.getComponent().useMerge()) {
            newlineStyle = EConnectionType.FLOW_MERGE;
        }
    }
    boolean isJoblet = false;
    if (PluginChecker.isJobLetPluginLoaded()) {
        IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
        if (service != null && service.isJobletComponent(newTarget) && !lineStyle.hasConnectionCategory(IConnectionCategory.FLOW)) {
            List<INodeConnector> inputConnector = service.getFreeTriggerBuiltConnectors(newTarget, lineStyle, true);
            if (inputConnector.isEmpty()) {
                return false;
            }
            isJoblet = true;
        }
    }
    if (!isJoblet) {
        INodeConnector connectorFromType = newTarget.getConnectorFromType(newlineStyle);
        int maxInput = connectorFromType.getMaxLinkInput();
        if (maxInput != -1 && (connectorFromType.getCurLinkNbInput() >= maxInput)) {
            return false;
        }
    }
    if (!canConnect(source, newTarget, lineStyle, connectionName, refactorJoblet)) {
        return false;
    }
    return true;
}
Also used : IJobletProviderService(org.talend.core.ui.IJobletProviderService) INode(org.talend.core.model.process.INode) IConnection(org.talend.core.model.process.IConnection) INodeConnector(org.talend.core.model.process.INodeConnector)

Example 52 with INodeConnector

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

the class Connection method updateName.

@Override
public void updateName() {
    if (source == null) {
        return;
    }
    // IElementParameter labelParam = getElementParameter(EParameterName.LABEL.getName());
    String labelText = name;
    // if (labelParam != null) {
    // String value = (String) labelParam.getValue();
    // if (!"".equals(value)) {
    // labelText = value;
    // }
    // }
    int outputId = getOutputId();
    boolean updateName = false;
    INodeConnector sourceNodeConnector = getSourceNodeConnector();
    if (sourceNodeConnector == null) {
        return;
    }
    if (getLineStyle() == EConnectionType.TABLE || getLineStyle() == EConnectionType.TABLE_REF) {
        if (outputId >= 0) {
            //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            labelText += " (" + metaName + ", order:" + outputId + ")";
        } else {
            //$NON-NLS-1$ //$NON-NLS-2$
            labelText += " (" + sourceNodeConnector.getLinkName() + ")";
        }
        updateName = true;
    } else // }
    if (getLineStyle().equals(EConnectionType.FLOW_MAIN) || getLineStyle().equals(EConnectionType.FLOW_REF)) {
        if (sourceNodeConnector.getDefaultConnectionType().equals(getLineStyle())) {
            // link
            if (outputId >= 0) {
                //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                labelText += " (" + sourceNodeConnector.getLinkName() + " order:" + outputId + ")";
            } else {
                //$NON-NLS-1$ //$NON-NLS-2$
                labelText += " (" + sourceNodeConnector.getLinkName() + ")";
            }
        } else if (sourceNodeConnector.getBaseSchema().equals(EConnectionType.FLOW_MAIN.getName())) {
            // link
            if (outputId >= 0) {
                //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                labelText += " (" + getLineStyle().getDefaultLinkName() + " order:" + outputId + ")";
            } else {
                //$NON-NLS-1$ //$NON-NLS-2$
                labelText += " (" + getLineStyle().getDefaultLinkName() + ")";
            }
        } else {
            if (outputId >= 0) {
                labelText += //$NON-NLS-1$ //$NON-NLS-2$
                " (" + getLineStyle().getDefaultLinkName() + ", " + sourceNodeConnector.getLinkName() + " order:" + outputId + //$NON-NLS-1$ //$NON-NLS-2$
                ")";
            } else {
                //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                labelText += " (" + getLineStyle().getDefaultLinkName() + ", " + sourceNodeConnector.getLinkName() + ")";
            }
        }
        updateName = true;
    } else if (getLineStyle().equals(EConnectionType.FLOW_MERGE)) {
        int inputId = getInputId();
        if (outputId >= 0) {
            //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
            labelText += " (Main order:" + outputId + ", " + getLineStyle().getDefaultLinkName() + " order:" + inputId + ")";
        } else {
            //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            labelText += " (" + getLineStyle().getDefaultLinkName() + " order:" + inputId + ")";
        }
        updateName = true;
    } else if (getLineStyle().equals(EConnectionType.RUN_IF) && (!sourceNodeConnector.getLinkName().equals(name))) {
        // if "RunIf" got a custom name
        //$NON-NLS-1$ //$NON-NLS-2$
        labelText = sourceNodeConnector.getLinkName() + " (" + name + ")";
        // bug 8087
        if (outputId >= 0) {
            //$NON-NLS-1$ //$NON-NLS-2$
            labelText += " (order:" + outputId + ")";
        }
        updateName = true;
    } else if (getLineStyle().equals(EConnectionType.ROUTE_WHEN)) /*
                                                                     * &&
                                                                     * (!sourceNodeConnector.getLinkName().equals(name))
                                                                     */
    {
        if (getUniqueName() != null) {
            String linkName = getUniqueName();
            labelText = linkName;
            this.setName(linkName);
        }
        //labelText = labelText + " (" + name + ")"; //$NON-NLS-1$ //$NON-NLS-2$
        if (outputId >= 0) {
            //$NON-NLS-1$ //$NON-NLS-2$
            labelText += " (order:" + outputId + ")";
        }
        updateName = true;
    } else if (getLineStyle().equals(EConnectionType.ROUTE_CATCH)) /*
                                                                      * &&
                                                                      * (!sourceNodeConnector.getLinkName().equals(name
                                                                      * ))
                                                                      */
    {
        if (getUniqueName() != null) {
            String linkName = getUniqueName();
            labelText = linkName;
            this.setName(linkName);
        }
        //labelText = labelText + " (" + name + ")"; //$NON-NLS-1$ //$NON-NLS-2$
        if (outputId >= 0) {
            //$NON-NLS-1$ //$NON-NLS-2$
            labelText += " (order:" + outputId + ")";
        }
        updateName = true;
    } else if (getLineStyle().equals(EConnectionType.ROUTE)) /*
                                                                * if there are more than one ROUTE connections exist
                                                                * then show the orders of them &&
                                                                * (!sourceNodeConnector.getLinkName().equals(name ))
                                                                */
    {
        if (getUniqueName() != null) {
            String linkName = getUniqueName();
            labelText = linkName;
            this.setName(linkName);
        }
        //labelText = labelText + " (" + name + ")"; //$NON-NLS-1$ //$NON-NLS-2$
        if (outputId >= 0) {
            //$NON-NLS-1$ //$NON-NLS-2$
            labelText += " (order:" + outputId + ")";
        }
        updateName = true;
    } else if (getLineStyle().equals(EConnectionType.ITERATE)) {
        IElementParameter enableParam = this.getElementParameter(ENABLE_PARALLEL);
        IElementParameter numberParam = this.getElementParameter(NUMBER_PARALLEL);
        // for feature 4505
        boolean special = (outputId >= 0);
        String linkName = sourceNodeConnector.getLinkName();
        if (getUniqueName() != null && special) {
            linkName = getUniqueName();
        }
        if (enableParam != null && (Boolean) enableParam.getValue()) {
            //$NON-NLS-1$
            labelText = linkName + " (x " + (String) numberParam.getValue();
            if (special) {
                //$NON-NLS-1$
                labelText += " order:" + outputId;
            }
            //$NON-NLS-1$
            labelText += ")";
        } else if (special) {
            //$NON-NLS-1$ //$NON-NLS-2$
            labelText = linkName + " (order:" + outputId + ")";
        }
        updateName = true;
    } else if (getLineStyle().equals(EConnectionType.ROUTE_ENDBLOCK) || getLineStyle().equals(EConnectionType.ROUTE_TRY) || getLineStyle().equals(EConnectionType.ROUTE_FINALLY) || getLineStyle().equals(EConnectionType.ROUTE_OTHER)) {
        String linkName = sourceNodeConnector.getLinkName();
        if (getUniqueName() != null) {
            linkName = getUniqueName();
            labelText = linkName;
            this.setName(linkName);
        }
        updateName = true;
    } else if (getLineStyle().equals(EConnectionType.SYNCHRONIZE)) {
        //$NON-NLS-1$
        IElementParameter synchroType = this.getSource().getElementParameter("WAIT_FOR");
        if (synchroType != null) {
            if ("All".equals(synchroType.getValue())) {
                //$NON-NLS-1$
                //$NON-NLS-1$
                labelText += " (Wait for all)";
            } else if ("First".equals(synchroType.getValue())) {
                //$NON-NLS-1$
                //$NON-NLS-1$
                labelText += " (Wait for first)";
            }
        }
        updateName = true;
    } else {
        if (outputId >= 0 && !getLineStyle().equals(EConnectionType.PARALLELIZE)) {
            //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            labelText += " (" + "order:" + outputId + ")";
        }
        updateName = true;
    }
    if (updateName) {
        if (!label.getLabelText().equals(labelText)) {
            label.setLabelText(labelText);
        }
        firePropertyChange(NAME, null, name);
    }
}
Also used : IElementParameter(org.talend.core.model.process.IElementParameter) INodeConnector(org.talend.core.model.process.INodeConnector)

Example 53 with INodeConnector

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

the class Connection method disconnect.

/**
     * Disconnect the connection This function is used before delete or reconnect a connection.
     */
@Override
public void disconnect() {
    if (isConnected) {
        INodeConnector sourceNodeConnector = getSourceNodeConnector();
        if (source.getJobletNode() == null && sourceNodeConnector != null && !sourceNodeConnector.isMultiSchema()) {
            if (lineStyle.hasConnectionCategory(IConnectionCategory.CUSTOM_NAME) || isInTypes(lineStyle, EConnectionType.ITERATE, EConnectionType.ON_COMPONENT_OK, EConnectionType.ON_COMPONENT_ERROR, EConnectionType.ON_SUBJOB_OK, EConnectionType.ON_SUBJOB_ERROR, EConnectionType.RUN_IF, EConnectionType.ROUTE, EConnectionType.ROUTE_TRY, EConnectionType.ROUTE_CATCH, EConnectionType.ROUTE_FINALLY, EConnectionType.ROUTE_ENDBLOCK, EConnectionType.ROUTE_WHEN, EConnectionType.ROUTE_OTHER, EConnectionType.STARTS)) {
                source.getProcess().removeUniqueConnectionName(uniqueName);
            }
        }
        source.removeOutput(this);
        target.removeInput(this);
        updateAllId();
        isConnected = false;
        if (lineStyle.equals(EConnectionType.SYNCHRONIZE)) {
            for (IElementParameter param : target.getElementParameters()) {
                if (param.isBasedOnSubjobStarts()) {
                    TableController.updateSubjobStarts(target, param);
                }
            }
        }
    }
}
Also used : IElementParameter(org.talend.core.model.process.IElementParameter) INodeConnector(org.talend.core.model.process.INodeConnector)

Example 54 with INodeConnector

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

the class SchemaUtils method updateComponentSchema.

public static void updateComponentSchema(INode node, IMetadataTable metadataTable, Boolean askPropagate) {
    if (node == null || metadataTable == null || node.getComponentProperties() == null) {
        return;
    }
    Schema schema = convertTalendSchemaIntoComponentSchema(ConvertionHelper.convert(metadataTable));
    INodeConnector connector = node.getConnectorFromName(metadataTable.getAttachedConnector());
    if (connector != null) {
        if (connector instanceof GenericNodeConnector) {
            node.getComponentProperties().setConnectedSchema(((GenericNodeConnector) connector).getComponentConnector(), schema, true);
        }
        for (IElementParameter param : new ArrayList<IElementParameter>(node.getElementParameters())) {
            if (EParameterFieldType.SCHEMA_REFERENCE.equals(param.getFieldType()) && connector.getName().equals(param.getContext())) {
                if (param instanceof GenericElementParameter) {
                    ((GenericElementParameter) param).setAskPropagate(askPropagate);
                }
                param.setValue(schema);
            }
        }
    }
}
Also used : GenericNodeConnector(org.talend.designer.core.generic.model.GenericNodeConnector) Schema(org.apache.avro.Schema) ArrayList(java.util.ArrayList) GenericElementParameter(org.talend.designer.core.generic.model.GenericElementParameter) IElementParameter(org.talend.core.model.process.IElementParameter) INodeConnector(org.talend.core.model.process.INodeConnector)

Example 55 with INodeConnector

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

the class DesignerCoreService method removeConnection.

/**
     *
     * nrousseau Comment method "removeConnection".
     */
@Override
public void removeConnection(INode node, String schemaName) {
    for (IConnection connection : (List<IConnection>) node.getOutgoingConnections()) {
        if (connection.getMetaName().equals(schemaName)) {
            connection.disconnect();
            INode prevNode = connection.getSource();
            INodeConnector nodeConnectorSource, nodeConnectorTarget;
            nodeConnectorSource = prevNode.getConnectorFromType(connection.getLineStyle());
            nodeConnectorSource.setCurLinkNbOutput(nodeConnectorSource.getCurLinkNbOutput() - 1);
            INode nextNode = connection.getTarget();
            nodeConnectorTarget = nextNode.getConnectorFromType(connection.getLineStyle());
            nodeConnectorTarget.setCurLinkNbInput(nodeConnectorTarget.getCurLinkNbInput() - 1);
            break;
        }
    }
    node.getProcess().removeUniqueConnectionName(schemaName);
}
Also used : INode(org.talend.core.model.process.INode) IConnection(org.talend.core.model.process.IConnection) List(java.util.List) ArrayList(java.util.ArrayList) 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