Search in sources :

Example 6 with INodeConnector

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

the class TalendEditorContextMenuProvider method buildContextMenu.

/**
     * Called when the context menu is about to show. Actions, whose state is enabled, will appear in the context menu.
     * 
     * @see org.eclipse.gef.ContextMenuProvider#buildContextMenu(org.eclipse.jface.action.IMenuManager)
     */
@Override
public void buildContextMenu(final IMenuManager menu) {
    if (!isEnableContextMenu()) {
        return;
    }
    // Add standard action groups to the menu
    menu.add(new Separator(GROUP_CONNECTIONS));
    menu.add(new Separator(GEFActionConstants.GROUP_UNDO));
    menu.add(new Separator(GEFActionConstants.GROUP_COPY));
    menu.add(new Separator(GEFActionConstants.GROUP_EDIT));
    menu.add(new Separator(GEFActionConstants.GROUP_REST));
    menu.add(new Separator(GROUP_OTHER));
    menu.add(new Separator(GEFActionConstants.GROUP_VIEW));
    menu.add(new Separator(GROUP_BREAKPOINT));
    IAction action;
    // target group id
    menu.appendToGroup(// target group id
    GEFActionConstants.GROUP_UNDO, // action to add
    getAction(ActionFactory.UNDO.getId()));
    menu.appendToGroup(GEFActionConstants.GROUP_UNDO, getAction(ActionFactory.REDO.getId()));
    if (part != null) {
        // new GEFCopyAction(part);
        action = getAction(ActionFactory.COPY.getId());
        if (action instanceof GEFCopyAction) {
            ((GEFCopyAction) action).update();
        }
        menu.appendToGroup(GEFActionConstants.GROUP_EDIT, action);
        // new GEFPasteAction(part);
        action = getAction(ActionFactory.PASTE.getId());
        GEFPasteAction pasteAction = (GEFPasteAction) action;
        Point p = Display.getCurrent().getCursorLocation();
        p = this.getViewer().getControl().toControl(p);
        // gcui see bug 7812:Copy/Paste component in Job designer.
        LayerManager layerManager = (LayerManager) this.getViewer().getEditPartRegistry().get(LayerManager.ID);
        IFigure contentLayer = layerManager.getLayer(LayerConstants.PRINTABLE_LAYERS);
        // System.out.println("X:" + contentLayer.getSize().width + "   Y:" + contentLayer.getSize().height);
        org.eclipse.draw2d.geometry.Point p1 = new org.eclipse.draw2d.geometry.Point(p.x, p.y);
        contentLayer.translateToAbsolute(p1);
        // System.out.println("relative:" + p);
        p.x = 2 * (p.x) - p1.x;
        p.y = 2 * (p.y) - p1.y;
        // System.out.println("absolute:" + p);
        pasteAction.setCursorLocation(p);
        menu.appendToGroup(GEFActionConstants.GROUP_EDIT, action);
        menu.appendToGroup(GEFActionConstants.GROUP_EDIT, getAction(ActionFactory.DELETE.getId()));
        menu.appendToGroup(GEFActionConstants.GROUP_EDIT, getAction(ActionFactory.SELECT_ALL.getId()));
        action = new ActivateElementAction(part);
        ((ActivateElementAction) action).update();
        if (action.isEnabled()) {
            menu.appendToGroup(GEFActionConstants.GROUP_REST, action);
        }
        action = new ActivateSubjobAction(part);
        ((ActivateSubjobAction) action).update();
        if (action.isEnabled()) {
            menu.appendToGroup(GEFActionConstants.GROUP_REST, action);
        }
        action = new ActivateSubjobOneComponentAction(part);
        ((ActivateSubjobOneComponentAction) action).update();
        if (action.isEnabled()) {
            menu.appendToGroup(GEFActionConstants.GROUP_REST, action);
        }
        action = getAction(ConnectionSetAsMainRef.ID);
        if (action.isEnabled()) {
            menu.appendToGroup(GEFActionConstants.GROUP_REST, action);
        }
        action = getAction(ModifyMergeOrderAction.ID);
        if (action.isEnabled()) {
            menu.appendToGroup(GEFActionConstants.GROUP_REST, action);
        }
        action = getAction(ModifyOutputOrderAction.ID);
        if (action.isEnabled()) {
            menu.appendToGroup(GEFActionConstants.GROUP_REST, action);
        }
        List<String> orderActionIDs = ModifyConnectionOrderAction.getOrderActionIDs();
        for (String id : orderActionIDs) {
            action = getAction(id);
            if (action != null && action.isEnabled()) {
                menu.appendToGroup(GEFActionConstants.GROUP_REST, action);
            }
        }
        //$NON-NLS-1$
        MenuManager subMenu = new MenuManager(Messages.getString("TalendEditorContextMenuProvider.Row"));
        menu.appendToGroup(GROUP_CONNECTIONS, subMenu);
        action = new ConnectionCreateAction(part, EConnectionType.FLOW_MAIN);
        ((ConnectionCreateAction) action).update();
        List<INodeConnector> connectors = ((ConnectionCreateAction) action).getConnectors();
        if (connectors.size() > 1) {
            for (INodeConnector connector : connectors) {
                if (connector.isMultiSchema()) {
                    action = new ConnectionCreateAction(part, connector);
                    ((ConnectionCreateAction) action).update();
                    if (action.isEnabled() && connector.isShow()) {
                        List<String> menuList = ((ConnectionCreateAction) action).getMenuList();
                        for (int i = 0; i < menuList.size(); i++) {
                            action = new ConnectionCreateAction(part, connector);
                            ((ConnectionCreateAction) action).update();
                            ((ConnectionCreateAction) action).setText(menuList.get(i));
                            subMenu.add(action);
                        }
                    }
                } else {
                    action = new ConnectionCreateAction(part, connector);
                    ((ConnectionCreateAction) action).update();
                    if (action.isEnabled() && connector.isShow()) {
                        ((ConnectionCreateAction) action).setText(connector.getMenuName());
                        subMenu.add(action);
                    }
                }
            }
        } else {
            if (connectors.size() == 1) {
                action = new ConnectionCreateAction(part, connectors.get(0));
                ((ConnectionCreateAction) action).update();
                if (action.isEnabled() && connectors.get(0).isShow()) {
                    List<String> menuList = ((ConnectionCreateAction) action).getMenuList();
                    for (int i = 0; i < menuList.size(); i++) {
                        action = new ConnectionCreateAction(part, connectors.get(0));
                        ((ConnectionCreateAction) action).update();
                        ((ConnectionCreateAction) action).setText(menuList.get(i));
                        subMenu.add(action);
                    }
                }
            }
        }
        retrieveConnectors(subMenu, EConnectionType.ITERATE);
        retrieveConnectors(subMenu, EConnectionType.ROUTE);
        retrieveConnectors(subMenu, EConnectionType.ROUTE_TRY);
        retrieveConnectors(subMenu, EConnectionType.ROUTE_CATCH);
        retrieveConnectors(subMenu, EConnectionType.ROUTE_FINALLY);
        retrieveConnectors(subMenu, EConnectionType.ROUTE_ENDBLOCK);
        //$NON-NLS-1$
        subMenu = new MenuManager("Link");
        menu.appendToGroup(GROUP_CONNECTIONS, subMenu);
        action = new ConnectionCreateAction(part, EConnectionType.TABLE);
        ((ConnectionCreateAction) action).update();
        if (action.isEnabled()) {
            List<String> menuList = ((ConnectionCreateAction) action).getMenuList();
            for (int i = 0; i < menuList.size(); i++) {
                action = new ConnectionCreateAction(part, EConnectionType.TABLE);
                ((ConnectionCreateAction) action).update();
                ((ConnectionCreateAction) action).setText(menuList.get(i));
                subMenu.add(action);
            }
        }
        //$NON-NLS-1$
        subMenu = new MenuManager("Move to joblet");
        menu.appendToGroup(GROUP_OTHER, subMenu);
        action = getMoveToJobletAction(part, null, null);
        if (action != null) {
            ((AddToJobletAction) action).update();
            List<Node> nodeList = ((AddToJobletAction) action).getJobletNodeList();
            Map<INode, IConnection> nodeMap = ((AddToJobletAction) action).getJobletNodeMap();
            if (nodeList != null) {
                for (Node jobletNode : nodeList) {
                    action = getMoveToJobletAction(part, jobletNode, nodeMap);
                    if (action != null) {
                        ((AddToJobletAction) action).update();
                        action.setText(jobletNode.getLabel());
                        subMenu.add(action);
                    }
                }
            }
        }
        action = getMoveToJobAction(part);
        if (action != null) {
            ((SelectionAction) action).update();
            if (action.isEnabled()) {
                menu.appendToGroup(GROUP_OTHER, action);
            }
        }
        //$NON-NLS-1$
        subMenu = new MenuManager(Messages.getString("TalendEditorContextMenuProvider.Trigger"));
        menu.appendToGroup(GROUP_CONNECTIONS, subMenu);
        /*
             * action = new ConnectionCreateAction(part, EConnectionType.RUN_BEFORE); ((ConnectionCreateAction)
             * action).update(); if (action.isEnabled()) { subMenu.add(action); }
             */
        retrieveConnectors(subMenu, EConnectionType.ON_SUBJOB_OK);
        retrieveConnectors(subMenu, EConnectionType.ON_SUBJOB_ERROR);
        subMenu.add(new Separator());
        retrieveConnectors(subMenu, EConnectionType.SYNCHRONIZE);
        retrieveConnectors(subMenu, EConnectionType.PARALLELIZE);
        subMenu.add(new Separator());
        retrieveConnectors(subMenu, EConnectionType.RUN_IF);
        retrieveConnectors(subMenu, EConnectionType.ROUTE_WHEN);
        retrieveConnectors(subMenu, EConnectionType.ROUTE_OTHER);
        retrieveConnectors(subMenu, EConnectionType.ON_COMPONENT_OK);
        retrieveConnectors(subMenu, EConnectionType.ON_COMPONENT_ERROR);
        retrieveConnectors(subMenu, EConnectionType.STARTS);
        action = new NodeBreakpointAction(part);
        ((NodeBreakpointAction) action).update();
        if (action.isEnabled()) {
            menu.appendToGroup(GEFActionConstants.GROUP_REST, action);
        }
        action = new ShowComponentSettingViewerAction(part);
        ((ShowComponentSettingViewerAction) action).update();
        if (action.isEnabled()) {
            menu.appendToGroup(GROUP_OTHER, action);
        }
        action = new DisplaySubjobAction(part);
        ((SelectionAction) action).update();
        if (action.isEnabled()) {
            menu.appendToGroup(GROUP_OTHER, action);
        }
        if (PluginChecker.isAutoParalelPluginLoaded()) {
            action = new SetParallelizationAction(part);
            ((SelectionAction) action).update();
            if (action.isEnabled()) {
                menu.appendToGroup(GROUP_OTHER, action);
            }
            action = new DisableParallelizationAction(part);
            ((SelectionAction) action).update();
            if (action.isEnabled()) {
                menu.appendToGroup(GROUP_OTHER, action);
            }
        }
        // see feature 5027
        action = new ParallelExecutionAction(part);
        ((SelectionAction) action).update();
        if (PluginChecker.isTeamEdition() && action.isEnabled()) {
            menu.appendToGroup(GROUP_OTHER, action);
        }
        action = new SearchComponentAction(part);
        ((SelectionAction) action).update();
        if (action.isEnabled()) {
            menu.appendToGroup(GROUP_OTHER, action);
        }
        action = new TraceEnableAction(part);
        ((SelectionAction) action).update();
        if (action.isEnabled()) {
            menu.appendToGroup(GROUP_BREAKPOINT, action);
        }
        action = new TraceDisableAction(part);
        ((SelectionAction) action).update();
        if (action.isEnabled()) {
            menu.appendToGroup(GROUP_BREAKPOINT, action);
        }
        action = new FilterTraceColumnAction(part);
        ((SelectionAction) action).update();
        if (action.isEnabled()) {
            menu.appendToGroup(GROUP_BREAKPOINT, action);
        }
        action = new ShowBreakpointAction(part);
        ((SelectionAction) action).update();
        if (action.isEnabled()) {
            menu.appendToGroup(GROUP_BREAKPOINT, action);
        }
        action = new OpenJobHierarchyAction(part);
        ((SelectionAction) action).update();
        if (action.isEnabled()) {
            menu.appendToGroup(GROUP_OTHER, action);
        }
        action = new OpentRunJobComponentAction(part);
        ((SelectionAction) action).update();
        if (action.isEnabled()) {
            menu.appendToGroup(GEFActionConstants.GROUP_VIEW, action);
        }
        action = new BringForwardAction(part);
        ((SelectionAction) action).update();
        if (action.isEnabled()) {
            menu.appendToGroup(GEFActionConstants.GROUP_VIEW, action);
        }
        action = new BringToFrontAction(part);
        ((SelectionAction) action).update();
        if (action.isEnabled()) {
            menu.appendToGroup(GEFActionConstants.GROUP_VIEW, action);
        }
        action = new SendBackwardAction(part);
        ((SelectionAction) action).update();
        if (action.isEnabled()) {
            menu.appendToGroup(GEFActionConstants.GROUP_VIEW, action);
        }
        action = new SendToBackAction(part);
        ((SelectionAction) action).update();
        if (action.isEnabled()) {
            menu.appendToGroup(GEFActionConstants.GROUP_VIEW, action);
        }
        List<SelectionAction> instances = CustomExternalActions.getInstances(part);
        for (SelectionAction selectionAction : instances) {
            selectionAction.update();
            if (selectionAction.isEnabled()) {
                menu.appendToGroup(GEFActionConstants.GROUP_VIEW, selectionAction);
            }
        }
    }
}
Also used : INode(org.talend.core.model.process.INode) GEFCopyAction(org.talend.designer.core.ui.action.GEFCopyAction) GEFPasteAction(org.talend.designer.core.ui.action.GEFPasteAction) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) SearchComponentAction(org.talend.designer.core.ui.action.SearchComponentAction) IConnection(org.talend.core.model.process.IConnection) DisableParallelizationAction(org.talend.designer.core.ui.action.DisableParallelizationAction) INodeConnector(org.talend.core.model.process.INodeConnector) NodeBreakpointAction(org.talend.designer.core.ui.action.NodeBreakpointAction) OpenJobHierarchyAction(org.talend.designer.core.ui.hierarchy.OpenJobHierarchyAction) ParallelExecutionAction(org.talend.designer.core.ui.action.ParallelExecutionAction) OpentRunJobComponentAction(org.talend.designer.core.ui.action.OpentRunJobComponentAction) FilterTraceColumnAction(org.talend.designer.core.ui.action.FilterTraceColumnAction) BringToFrontAction(org.talend.designer.core.ui.action.BringToFrontAction) LayerManager(org.eclipse.gef.editparts.LayerManager) IFigure(org.eclipse.draw2d.IFigure) ActivateSubjobOneComponentAction(org.talend.designer.core.ui.action.ActivateSubjobOneComponentAction) SetParallelizationAction(org.talend.designer.core.ui.action.SetParallelizationAction) ActivateElementAction(org.talend.designer.core.ui.action.ActivateElementAction) TraceDisableAction(org.talend.designer.core.ui.action.TraceDisableAction) IAction(org.eclipse.jface.action.IAction) Point(org.eclipse.swt.graphics.Point) SendToBackAction(org.talend.designer.core.ui.action.SendToBackAction) SelectionAction(org.eclipse.gef.ui.actions.SelectionAction) SendBackwardAction(org.talend.designer.core.ui.action.SendBackwardAction) Point(org.eclipse.swt.graphics.Point) BringForwardAction(org.talend.designer.core.ui.action.BringForwardAction) AddToJobletAction(org.talend.designer.core.ui.action.AddToJobletAction) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) ShowComponentSettingViewerAction(org.talend.designer.core.ui.action.ShowComponentSettingViewerAction) ShowBreakpointAction(org.talend.designer.core.ui.action.ShowBreakpointAction) ActivateSubjobAction(org.talend.designer.core.ui.action.ActivateSubjobAction) Separator(org.eclipse.jface.action.Separator) TraceEnableAction(org.talend.designer.core.ui.action.TraceEnableAction) ConnectionCreateAction(org.talend.designer.core.ui.action.ConnectionCreateAction) DisplaySubjobAction(org.talend.designer.core.ui.action.DisplaySubjobAction)

Example 7 with INodeConnector

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

the class TalendEditorContextMenuProvider method retrieveConnectors.

private void retrieveConnectors(MenuManager subMenu, EConnectionType connType) {
    if (connType != null) {
        ConnectionCreateAction action = new ConnectionCreateAction(part, connType);
        action.update();
        List<INodeConnector> connectors = action.getConnectors();
        for (INodeConnector connector : connectors) {
            action = new ConnectionCreateAction(part, connector);
            action.update();
            if (action.isEnabled()) {
                action.setText(connector.getMenuName());
                subMenu.add(action);
            }
        }
    }
}
Also used : INodeConnector(org.talend.core.model.process.INodeConnector) ConnectionCreateAction(org.talend.designer.core.ui.action.ConnectionCreateAction)

Example 8 with INodeConnector

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

the class ConnectionManager method canConnect.

private static boolean canConnect(INode source, INode target, EConnectionType connType, String connectionName, boolean refactorJoblet) {
    if (source.equals(target)) {
        return false;
    }
    if (!refactorJoblet && (!target.isActivate() || !source.isActivate())) {
        return false;
    }
    boolean skipSameProcessTest = false;
    if (newlineStyle.equals(EConnectionType.FLOW_MAIN)) {
        int nbMain = 0;
        for (IConnection connec : target.getIncomingConnections()) {
            if (connec.getLineStyle().equals(EConnectionType.FLOW_MAIN)) {
                nbMain++;
            }
        }
        int maxFlowInput = 0;
        if (target.getConnectorFromName(EConnectionType.FLOW_MAIN.getName()) != null) {
            maxFlowInput = target.getConnectorFromName(EConnectionType.FLOW_MAIN.getName()).getMaxLinkInput();
        }
        if (maxFlowInput > 1 && nbMain >= 1 && (nbMain <= maxFlowInput || maxFlowInput == -1)) {
            // if the component accept several connections on the input, all inputs must come from the same process
            boolean isExtensionComponent = false;
            AbstractProcessProvider findProcessProviderFromPID = AbstractProcessProvider.findProcessProviderFromPID(IComponent.JOBLET_PID);
            if (findProcessProviderFromPID != null) {
                isExtensionComponent = findProcessProviderFromPID.isExtensionComponent(target);
            }
            if (!isExtensionComponent && !source.sameProcessAs(target, false)) {
                return false;
            }
            skipSameProcessTest = true;
        }
    }
    if (!skipSameProcessTest && source.sameProcessAs(target, false)) {
        return false;
    }
    // limit the use of the tUnite, avoid a conflict in case source link is in a merge part, and target use merge.
    if (!source.getLinkedMergeInfo().isEmpty() && (!target.getLinkedMergeInfo().isEmpty() || target.getComponent().useMerge())) {
        return false;
    }
    // Check existing connections to avoid to have more than one link
    // no matter the type of the connection and the direction
    List<Connection> connections = new ArrayList<Connection>((List<Connection>) source.getOutgoingConnections());
    connections.removeAll(source.getOutgoingConnections(EConnectionType.FLOW_MAIN));
    // connections = source.getOutgoingConnections();
    for (int i = 0; i < connections.size(); i++) {
        if ((connections.get(i)).getTarget().equals(target)) {
            return false;
        }
    }
    connections = new ArrayList<Connection>((List<Connection>) source.getIncomingConnections());
    connections.removeAll(source.getIncomingConnections(EConnectionType.FLOW_MAIN));
    // connections = source.getIncomingConnections();
    for (int i = 0; i < connections.size(); i++) {
        if ((connections.get(i)).getSource().equals(target)) {
            return false;
        }
    }
    if (connType.hasConnectionCategory(IConnectionCategory.DEPENDENCY)) {
        if (!(Boolean) target.getPropertyValue(EParameterName.STARTABLE.getName())) {
            return false;
        }
        boolean isJoblet = false;
        if (PluginChecker.isJobLetPluginLoaded()) {
            IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
            if (service != null) {
                if (service.isJobletComponent(target) && !connType.hasConnectionCategory(IConnectionCategory.FLOW)) {
                    List<INodeConnector> freeTriggerBuiltConnectors = service.getFreeTriggerBuiltConnectors(target, connType, true);
                    if (freeTriggerBuiltConnectors.isEmpty()) {
                        return false;
                    }
                    isJoblet = true;
                }
                // for bug 10973
                if (service.isTriggerNode(target) && target.getIncomingConnections() != null && target.getIncomingConnections().size() >= 1) {
                    return false;
                }
            }
        }
        if (!isJoblet && !target.isELTComponent() && !target.isSubProcessStart()) {
            return false;
        }
    }
    connections = (List<Connection>) target.getIncomingConnections();
    for (int i = 0; i < connections.size(); i++) {
        if (connType == EConnectionType.TABLE || connType == EConnectionType.TABLE_REF) {
            if ((connections.get(i)).isActivate()) {
                if ((connections.get(i)).getName().equals(connectionName)) {
                    return false;
                }
            }
        }
    }
    boolean targetHasHashLinks = ((Process) target.getProcess()).isThereLinkWithHash(target) | newlineStyle.hasConnectionCategory(IConnectionCategory.USE_HASH);
    if (connType.hasConnectionCategory(IConnectionCategory.CONDITION)) {
        if (targetHasHashLinks) {
            return false;
        }
    }
    if (targetHasHashLinks && source.hasRunIfLink()) {
        return false;
    }
    return true;
}
Also used : IJobletProviderService(org.talend.core.ui.IJobletProviderService) ArrayList(java.util.ArrayList) IConnection(org.talend.core.model.process.IConnection) Connection(org.talend.designer.core.ui.editor.connections.Connection) IConnection(org.talend.core.model.process.IConnection) ArrayList(java.util.ArrayList) List(java.util.List) INodeConnector(org.talend.core.model.process.INodeConnector)

Example 9 with INodeConnector

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

the class ConnectionManager method canConnect.

/**
     * 
     * Will return true if the connection can connect or not between source & target.
     * 
     * @param source
     * @param target
     * @param connType
     * @param connectionName
     * @return
     */
private static boolean canConnect(INode source, INode target, EConnectionType connType, String connectionName) {
    if (source.equals(target)) {
        return false;
    }
    if (!target.isActivate() || !source.isActivate()) {
        return false;
    }
    boolean skipSameProcessTest = false;
    if (newlineStyle.equals(EConnectionType.FLOW_MAIN)) {
        int nbMain = 0;
        for (IConnection connec : target.getIncomingConnections()) {
            if (connec.getLineStyle().equals(EConnectionType.FLOW_MAIN)) {
                nbMain++;
            }
        }
        int maxFlowInput = 0;
        if (target.getConnectorFromName(EConnectionType.FLOW_MAIN.getName()) != null) {
            maxFlowInput = target.getConnectorFromName(EConnectionType.FLOW_MAIN.getName()).getMaxLinkInput();
        }
        if (maxFlowInput > 1 && nbMain >= 1 && (nbMain <= maxFlowInput || maxFlowInput == -1)) {
            // if the component accept several connections on the input, all inputs must come from the same process
            boolean isExtensionComponent = false;
            AbstractProcessProvider findProcessProviderFromPID = AbstractProcessProvider.findProcessProviderFromPID(IComponent.JOBLET_PID);
            if (findProcessProviderFromPID != null) {
                isExtensionComponent = findProcessProviderFromPID.isExtensionComponent(target);
            }
            if (!isExtensionComponent && !source.sameProcessAs(target, false)) {
                return false;
            }
            skipSameProcessTest = true;
        }
    }
    if (!skipSameProcessTest && source.sameProcessAs(target, false)) {
        return false;
    }
    // Check existing connections to avoid to have more than one link
    // no matter the type of the connection and the direction
    List<Connection> connections = new ArrayList<Connection>((List<Connection>) source.getOutgoingConnections());
    connections.removeAll(source.getOutgoingConnections(EConnectionType.FLOW_MAIN));
    // connections = source.getOutgoingConnections();
    for (int i = 0; i < connections.size(); i++) {
        if ((connections.get(i)).getTarget().equals(target)) {
            return false;
        }
    }
    connections = new ArrayList<Connection>((List<Connection>) source.getIncomingConnections());
    connections.removeAll(source.getIncomingConnections(EConnectionType.FLOW_MAIN));
    // connections = source.getIncomingConnections();
    for (int i = 0; i < connections.size(); i++) {
        if ((connections.get(i)).getSource().equals(target)) {
            return false;
        }
    }
    if (connType.hasConnectionCategory(IConnectionCategory.DEPENDENCY)) {
        if (!(Boolean) target.getPropertyValue(EParameterName.STARTABLE.getName())) {
            return false;
        }
        boolean isJoblet = false;
        if (PluginChecker.isJobLetPluginLoaded()) {
            IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
            if (service != null) {
                if (service.isJobletComponent(target) && !connType.hasConnectionCategory(IConnectionCategory.FLOW)) {
                    List<INodeConnector> freeTriggerBuiltConnectors = service.getFreeTriggerBuiltConnectors(target, connType, true);
                    if (freeTriggerBuiltConnectors.isEmpty()) {
                        return false;
                    }
                    isJoblet = true;
                }
                // for bug 10973
                if (service.isTriggerNode(target) && target.getIncomingConnections() != null && target.getIncomingConnections().size() >= 1) {
                    return false;
                }
            }
        }
        if (!isJoblet && !target.isELTComponent() && !target.isSubProcessStart()) {
            return false;
        }
    }
    connections = (List<Connection>) target.getIncomingConnections();
    for (int i = 0; i < connections.size(); i++) {
        if (connType == EConnectionType.TABLE || connType == EConnectionType.TABLE_REF) {
            if ((connections.get(i)).isActivate()) {
                if ((connections.get(i)).getName().equals(connectionName)) {
                    return false;
                }
            }
        }
    }
    boolean targetHasHashLinks = ((Process) target.getProcess()).isThereLinkWithHash(target) | newlineStyle.hasConnectionCategory(IConnectionCategory.USE_HASH);
    if (connType.hasConnectionCategory(IConnectionCategory.CONDITION)) {
        if (targetHasHashLinks) {
            return false;
        }
    }
    if (targetHasHashLinks && source.hasRunIfLink()) {
        return false;
    }
    return true;
}
Also used : IJobletProviderService(org.talend.core.ui.IJobletProviderService) ArrayList(java.util.ArrayList) IConnection(org.talend.core.model.process.IConnection) Connection(org.talend.designer.core.ui.editor.connections.Connection) IConnection(org.talend.core.model.process.IConnection) ArrayList(java.util.ArrayList) List(java.util.List) INodeConnector(org.talend.core.model.process.INodeConnector)

Example 10 with INodeConnector

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

the class ConnectionManager method canConnectToTarget.

/**
     * Will return true if the connection can connect or not between source & target.
     * 
     * @param source
     * @param oldTarget
     * @param newTarget
     * @param connType
     * @param connectionName
     * @return
     */
public static boolean canConnectToTarget(INode source, INode oldTarget, INode newTarget, EConnectionType lineStyle, String connectorName, String connectionName) {
    newlineStyle = lineStyle;
    boolean isMainConn = lineStyle == EConnectionType.FLOW_MAIN;
    if (source.equals(newTarget)) {
        return false;
    }
    final INode designSubjobStartNode = source.getDesignSubjobStartNode();
    if ((designSubjobStartNode.getOutgoingConnections(EConnectionType.ON_SUBJOB_OK).size() != 0 || designSubjobStartNode.getOutgoingConnections(EConnectionType.ON_SUBJOB_ERROR).size() != 0) && !newTarget.checkIfCanBeStart() && isMainConn && !((Node) newTarget).isJoblet()) {
        return false;
    }
    if ((designSubjobStartNode.getIncomingConnections(EConnectionType.ON_SUBJOB_OK).size() != 0 || designSubjobStartNode.getIncomingConnections(EConnectionType.ON_SUBJOB_ERROR).size() != 0) && !newTarget.checkIfCanBeStart() && isMainConn && !((Node) newTarget).isJoblet()) {
        return false;
    }
    if (newTarget.getJobletNode() != null) {
        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;
        }
        if (source.isELTComponent() && source.getComponent().getName().endsWith("Map")) {
            //$NON-NLS-1$
            List<? extends IConnection> tableLines = source.getOutgoingConnections(EConnectionType.TABLE);
            if (null != tableLines && 0 < tableLines.size()) {
                // node, so could not have table_ref out line
                return false;
            }
            newlineStyle = EConnectionType.TABLE_REF;
        }
    }
    // 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;
        }
    }
    // TDI-25765 : avoid any connection for components not accepting PIG
    if (newlineStyle.hasConnectionCategory(IConnectionCategory.FLOW) && "PIGCOMBINE".equals(connectorName)) {
        //$NON-NLS-1$
        if (!newTarget.getComponent().getName().startsWith("tPig")) {
            //$NON-NLS-1$
            return false;
        }
    }
    if (newTarget.getComponent() != null && newTarget.getComponent().getName().startsWith("tPig")) {
        //$NON-NLS-1$
        if (newlineStyle.hasConnectionCategory(IConnectionCategory.FLOW) && !"PIGCOMBINE".equals(connectorName)) {
            //$NON-NLS-1$
            return false;
        }
    }
    // TDI-29775 : avoid any connection for components not accepting SPARK
    if (newlineStyle.hasConnectionCategory(IConnectionCategory.FLOW) && "SPARKCOMBINE".equals(connectorName)) {
        //$NON-NLS-1$
        if (!newTarget.getComponent().getName().startsWith("tSpark")) {
            //$NON-NLS-1$
            return false;
        }
    }
    if (newTarget.getComponent() != null && newTarget.getComponent().getName().startsWith("tSpark")) {
        //$NON-NLS-1$
        if (newlineStyle.hasConnectionCategory(IConnectionCategory.FLOW) && !"SPARKCOMBINE".equals(connectorName)) {
            //$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)) {
        return false;
    }
    // if (!newConnectionType.equals(EConnectionType.LOOKUP)) {
    // INodeConnector nodeConnectorTarget;
    // nodeConnectorTarget = newTarget.getConnectorFromType(newConnectionType);
    // if (nodeConnectorTarget.getMaxLinkInput() != -1) {
    // if (nodeConnectorTarget.getCurLinkNbInput() >= nodeConnectorTarget.getMaxLinkInput()) {
    // return false;
    // }
    // }
    // }
    // check extensionPoints
    Set<IConnectionValidator> connectionValidators = ConnectionValidatorManager.getConnectionValidators();
    for (IConnectionValidator validator : connectionValidators) {
        boolean canConnectToTarget = validator.canConnectToTarget(source, oldTarget, newTarget, lineStyle, connectorName, connectionName);
        if (!canConnectToTarget) {
            return false;
        }
    }
    return true;
}
Also used : IJobletProviderService(org.talend.core.ui.IJobletProviderService) INode(org.talend.core.model.process.INode) IConnectionValidator(org.talend.designer.core.IConnectionValidator) INode(org.talend.core.model.process.INode) Node(org.talend.designer.core.ui.editor.nodes.Node) IConnection(org.talend.core.model.process.IConnection) 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