Search in sources :

Example 1 with ConnLabelEditPart

use of org.talend.designer.core.ui.editor.connections.ConnLabelEditPart in project tdi-studio-se by Talend.

the class GEFPasteAction method run.

@Override
@SuppressWarnings("unchecked")
public void run() {
    Object clipBoardContent;
    try {
        clipBoardContent = Clipboard.getDefault().getContents();
    } catch (RuntimeException e) {
        return;
    }
    AbstractTalendEditor editor = (AbstractTalendEditor) this.getWorkbenchPart();
    org.eclipse.swt.dnd.Clipboard systemClipboard = new org.eclipse.swt.dnd.Clipboard(Display.getCurrent());
    Object systemObject = systemClipboard.getContents(TextTransfer.getInstance());
    if (clipBoardContent instanceof List) {
        List<EditPart> partsList = (List<EditPart>) clipBoardContent;
        if (partsList == null || partsList.isEmpty()) {
            return;
        }
        List<NodePart> nodeParts = new ArrayList<NodePart>();
        List<NoteEditPart> noteParts = new ArrayList<NoteEditPart>();
        List<SubjobContainerPart> subjobParts = new ArrayList<SubjobContainerPart>();
        for (Object o : partsList) {
            if (o instanceof NodePart) {
                if (!nodeParts.contains(o)) {
                    nodeParts.add((NodePart) o);
                }
            } else if (o instanceof NoteEditPart) {
                noteParts.add((NoteEditPart) o);
            } else if (o instanceof SubjobContainerPart) {
                SubjobContainerPart subjob = (SubjobContainerPart) o;
                for (Iterator iterator = subjob.getChildren().iterator(); iterator.hasNext(); ) {
                    NodeContainerPart nodeContainerPart = (NodeContainerPart) iterator.next();
                    // add for bug TDI-20206
                    if (nodeContainerPart instanceof JobletContainerPart) {
                        for (Object obj : nodeContainerPart.getChildren()) {
                            if (obj instanceof NodePart && !nodeParts.contains(obj)) {
                                nodeParts.add((NodePart) obj);
                            }
                        }
                    }
                    NodePart nodePart = nodeContainerPart.getNodePart();
                    if (nodePart != null) {
                        if (!nodeParts.contains(nodePart)) {
                            nodeParts.add(nodePart);
                        }
                        subjobParts.add(subjob);
                    }
                }
            }
        }
        Map<JobletContainerPart, List<NodePart>> jobletMap = new HashMap<JobletContainerPart, List<NodePart>>();
        for (NodePart nodePart : nodeParts) {
            boolean isCollapsedNode = false;
            if (editor.getProcess().getGraphicalNodes().contains(nodePart.getModel())) {
                isCollapsedNode = true;
            }
            if (!isCollapsedNode && nodePart.getParent() instanceof JobletContainerPart) {
                JobletContainerPart jobletContainer = (JobletContainerPart) nodePart.getParent();
                List<NodePart> jobletNodeParts = jobletMap.get(jobletContainer);
                if (jobletNodeParts == null) {
                    jobletNodeParts = new ArrayList<NodePart>();
                    jobletMap.put(jobletContainer, jobletNodeParts);
                }
                jobletNodeParts.add(nodePart);
            }
        }
        List<NodePart> expandedJobletNodes = new ArrayList<NodePart>();
        for (JobletContainerPart jobletContainer : jobletMap.keySet()) {
            boolean copyJobletNode = true;
            List<NodePart> list = jobletMap.get(jobletContainer);
            for (Object obj : jobletContainer.getChildren()) {
                if (obj instanceof NodePart) {
                    if (!list.contains(obj)) {
                        copyJobletNode = false;
                        break;
                    }
                }
            }
            if (copyJobletNode) {
                nodeParts.removeAll(list);
                PartFactory factory = new PartFactory();
                NodePart createEditPart = (NodePart) factory.createEditPart(jobletContainer, ((NodeContainer) jobletContainer.getModel()).getNode());
                createEditPart.setParent(jobletContainer);
                nodeParts.add(createEditPart);
                expandedJobletNodes.add(createEditPart);
            }
        }
        org.eclipse.draw2d.geometry.Point gefPoint = getCursorLocation();
        // qli comment
        // if the components instanceof JobletInputOutputComponent and current process instanceof not
        // JobletGEFProcess,just create a messageBox and return.
        AbstractProcessProvider findProcessProviderFromPID = AbstractProcessProvider.findProcessProviderFromPID(IComponent.JOBLET_PID);
        if (findProcessProviderFromPID != null) {
            for (NodePart copiedNodePart : nodeParts) {
                Node copiedNode = (Node) copiedNodePart.getModel();
                // add for bug TDI-20207.if copy joblet/job to itself,then return.
                EComponentType componentType = null;
                String copideNodeId = null;
                String editorProcessId = null;
                if (copiedNode.getComponent() != null) {
                    componentType = copiedNode.getComponent().getComponentType();
                    if (copiedNode.getComponent().getProcess() != null) {
                        copideNodeId = copiedNode.getComponent().getProcess().getId();
                    }
                }
                if (editor.getProcess() != null) {
                    editorProcessId = editor.getProcess().getId();
                }
                for (IElementParameter element : copiedNode.getElementParametersFromField(EParameterFieldType.PROCESS_TYPE)) {
                    for (Map.Entry<String, IElementParameter> entry : element.getChildParameters().entrySet()) {
                        if (("PROCESS_TYPE_PROCESS").equals(entry.getKey())) {
                            if (editorProcessId != null && editorProcessId.equals(entry.getValue().getValue())) {
                                return;
                            }
                        }
                    }
                }
                if ((EComponentType.JOBLET).equals(componentType)) {
                    if (editorProcessId != null && editorProcessId.equals(copideNodeId)) {
                        return;
                    }
                }
                if (findProcessProviderFromPID.isJobletInputOrOutputComponent(copiedNode)) {
                    if (!findProcessProviderFromPID.isExtensionProcess(editor.getProcess())) {
                        MessageBox messagebox = new MessageBox(PlatformUI.getWorkbench().getDisplay().getActiveShell(), SWT.ICON_WARNING);
                        //$NON-NLS-1$
                        messagebox.setText(Messages.getString("GEFPasteAction.textWarning"));
                        //$NON-NLS-1$
                        messagebox.setMessage(Messages.getString("GEFPasteAction.warningMessages"));
                        messagebox.open();
                        return;
                    }
                }
                if (copiedNode.getJobletNode() != null) {
                    boolean canP = canPasteJobletNode(editor.getProcess(), copiedNode);
                    if (!canP) {
                        return;
                    }
                }
            }
        }
        if (nodeParts.size() != 0 && noteParts.size() != 0) {
            MultiplePasteCommand mpc = new MultiplePasteCommand(nodeParts, noteParts, (org.talend.designer.core.ui.editor.process.Process) editor.getProcess(), gefPoint);
            mpc.setSelectedSubjobs(subjobParts);
            mpc.setSelectedExpandedJoblet(expandedJobletNodes);
            execute(mpc);
        } else if (nodeParts.size() != 0) {
            NodesPasteCommand cmd = new NodesPasteCommand(nodeParts, editor.getProcess(), gefPoint);
            cmd.setSelectedSubjobs(subjobParts);
            cmd.setSelectedExpandedJoblet(expandedJobletNodes);
            execute(cmd);
        } else if (noteParts.size() != 0) {
            NotesPasteCommand cmd = new NotesPasteCommand(noteParts, (org.talend.designer.core.ui.editor.process.Process) editor.getProcess(), gefPoint, false, null);
            execute(cmd);
        }
        setCursorLocation(null);
    } else if (clipBoardContent instanceof String) {
        List objects = getSelectedObjects();
        if (objects.size() == 1) {
            String content = (String) clipBoardContent;
            if (objects.get(0) instanceof NoteEditPart && ((NoteEditPart) objects.get(0)).getDirectEditManager() != null) {
                Text text = ((NoteEditPart) objects.get(0)).getDirectEditManager().getTextControl();
                if (text != null) {
                    text.insert(content);
                }
            } else if (objects.get(0) instanceof ConnLabelEditPart && ((ConnLabelEditPart) objects.get(0)).getDirectEditManager() != null) {
                Text text = ((ConnLabelEditPart) objects.get(0)).getDirectEditManager().getTextControl();
                if (text != null) {
                    text.insert(content);
                }
            } else if (objects.get(0) instanceof NodeLabelEditPart && ((NodeLabelEditPart) objects.get(0)).getDirectEditManager() != null) {
                {
                    Text text = (Text) ((NodeLabelEditPart) objects.get(0)).getDirectEditManager().getCellEditor().getControl();
                    if (text != null) {
                        text.insert(content);
                    }
                }
            }
        }
    } else if (systemObject != null && systemObject instanceof String) {
        List objects = getSelectedObjects();
        if (objects.size() == 1) {
            String content = (String) systemObject;
            if (objects.get(0) instanceof NoteEditPart && ((NoteEditPart) objects.get(0)).getDirectEditManager() != null) {
                Text text = ((NoteEditPart) objects.get(0)).getDirectEditManager().getTextControl();
                if (text != null) {
                    text.insert(content);
                }
            } else if (objects.get(0) instanceof ConnLabelEditPart && ((ConnLabelEditPart) objects.get(0)).getDirectEditManager() != null) {
                Text text = ((ConnLabelEditPart) objects.get(0)).getDirectEditManager().getTextControl();
                if (text != null) {
                    text.insert(content);
                }
            } else if (objects.get(0) instanceof NodeLabelEditPart && ((NodeLabelEditPart) objects.get(0)).getDirectEditManager() != null) {
                {
                    Text text = (Text) ((NodeLabelEditPart) objects.get(0)).getDirectEditManager().getCellEditor().getControl();
                    if (text != null) {
                        text.insert(content);
                    }
                }
            }
        }
    }
}
Also used : NodeContainerPart(org.talend.designer.core.ui.editor.nodecontainer.NodeContainerPart) HashMap(java.util.HashMap) PartFactory(org.talend.designer.core.ui.editor.PartFactory) Node(org.talend.designer.core.ui.editor.nodes.Node) ArrayList(java.util.ArrayList) NodeLabelEditPart(org.talend.designer.core.ui.editor.nodes.NodeLabelEditPart) NodeContainer(org.talend.designer.core.ui.editor.nodecontainer.NodeContainer) SubjobContainerPart(org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainerPart) MultiplePasteCommand(org.talend.designer.core.ui.editor.cmd.MultiplePasteCommand) AbstractProcessProvider(org.talend.designer.core.model.process.AbstractProcessProvider) EComponentType(org.talend.core.model.components.EComponentType) NotesPasteCommand(org.talend.designer.core.ui.editor.cmd.NotesPasteCommand) AbstractTalendEditor(org.talend.designer.core.ui.editor.AbstractTalendEditor) Iterator(java.util.Iterator) IElementParameter(org.talend.core.model.process.IElementParameter) ArrayList(java.util.ArrayList) List(java.util.List) NodesPasteCommand(org.talend.designer.core.ui.editor.cmd.NodesPasteCommand) NodeLabelEditPart(org.talend.designer.core.ui.editor.nodes.NodeLabelEditPart) NoteEditPart(org.talend.designer.core.ui.editor.notes.NoteEditPart) EditPart(org.eclipse.gef.EditPart) ConnLabelEditPart(org.talend.designer.core.ui.editor.connections.ConnLabelEditPart) NoteEditPart(org.talend.designer.core.ui.editor.notes.NoteEditPart) JobletContainerPart(org.talend.designer.core.ui.editor.jobletcontainer.JobletContainerPart) Text(org.eclipse.swt.widgets.Text) MessageBox(org.eclipse.swt.widgets.MessageBox) Clipboard(org.eclipse.gef.ui.actions.Clipboard) NodePart(org.talend.designer.core.ui.editor.nodes.NodePart) HashMap(java.util.HashMap) Map(java.util.Map) ConnLabelEditPart(org.talend.designer.core.ui.editor.connections.ConnLabelEditPart)

Example 2 with ConnLabelEditPart

use of org.talend.designer.core.ui.editor.connections.ConnLabelEditPart in project tdi-studio-se by Talend.

the class ModifyMergeOrderAction method calculateEnabled.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.gef.ui.actions.WorkbenchPartAction#calculateEnabled()
     */
@Override
protected boolean calculateEnabled() {
    if (getSelectedObjects().isEmpty()) {
        return false;
    }
    List parts = getSelectedObjects();
    if (parts.size() != 1) {
        return false;
    }
    Object o = parts.get(0);
    INode node = null;
    if (o instanceof ConnectionPart) {
        ConnectionPart part = (ConnectionPart) o;
        IConnection connection = (IConnection) part.getModel();
        node = connection.getTarget();
    } else if (o instanceof ConnLabelEditPart) {
        ConnectionPart part = (ConnectionPart) ((ConnLabelEditPart) o).getParent();
        Connection connection = (Connection) part.getModel();
        node = connection.getTarget();
    } else if (o instanceof NodePart) {
        node = (Node) ((NodePart) o).getModel();
    }
    if ((node == null) || (!node.getComponent().useMerge())) {
        return false;
    }
    mergeComponent = node;
    setText(TEXT_MERGE_ORDER);
    return true;
}
Also used : INode(org.talend.core.model.process.INode) IConnection(org.talend.core.model.process.IConnection) Connection(org.talend.designer.core.ui.editor.connections.Connection) List(java.util.List) IConnection(org.talend.core.model.process.IConnection) ConnectionPart(org.talend.designer.core.ui.editor.connections.ConnectionPart) NodePart(org.talend.designer.core.ui.editor.nodes.NodePart) ConnLabelEditPart(org.talend.designer.core.ui.editor.connections.ConnLabelEditPart)

Example 3 with ConnLabelEditPart

use of org.talend.designer.core.ui.editor.connections.ConnLabelEditPart in project tdi-studio-se by Talend.

the class ModifyOutputOrderAction method calculateEnabled.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.gef.ui.actions.WorkbenchPartAction#calculateEnabled()
     */
@Override
protected boolean calculateEnabled() {
    if (getSelectedObjects().isEmpty()) {
        return false;
    }
    List parts = getSelectedObjects();
    if (parts.size() != 1) {
        return false;
    }
    Object o = parts.get(0);
    EConnectionType tmpConnType = null;
    INode node = null;
    if (o instanceof ConnectionPart) {
        ConnectionPart part = (ConnectionPart) o;
        Connection connection = (Connection) part.getModel();
        node = connection.getSource();
        tmpConnType = connection.getLineStyle();
    } else if (o instanceof ConnLabelEditPart) {
        ConnectionPart part = (ConnectionPart) ((ConnLabelEditPart) o).getParent();
        Connection connection = (Connection) part.getModel();
        node = connection.getSource();
        tmpConnType = connection.getLineStyle();
    } else if (o instanceof NodePart) {
        node = (Node) ((NodePart) o).getModel();
    }
    if (node == null) {
        return false;
    }
    usedConnType = false;
    //$NON-NLS-1$
    String midStr = "output";
    int nb = 0;
    for (Connection connection : (List<Connection>) node.getOutgoingConnections()) {
        if (getConnectionCategory() != null && connection.getLineStyle().hasConnectionCategory(getConnectionCategory())) {
            // avoid the not useful action, on connection.
            if (tmpConnType == null || tmpConnType != null && tmpConnType.hasConnectionCategory(getConnectionCategory())) {
                nb++;
            }
        } else // feature 4505 & 8087
        if (getConnectionType() != null && connection.getLineStyle() == getConnectionType()) {
            midStr = getConnectionType().getDefaultLinkName();
            usedConnType = true;
            // avoid the not useful action, on connection.
            if (tmpConnType == null || tmpConnType != null && tmpConnType == getConnectionType()) {
                nb++;
            }
        }
    }
    if (nb < 2) {
        return false;
    }
    multipleOutputNode = node;
    //$NON-NLS-1$
    setText(Messages.getString("ModifyOutputOrderAction.text", midStr));
    return true;
}
Also used : INode(org.talend.core.model.process.INode) Connection(org.talend.designer.core.ui.editor.connections.Connection) List(java.util.List) ConnectionPart(org.talend.designer.core.ui.editor.connections.ConnectionPart) NodePart(org.talend.designer.core.ui.editor.nodes.NodePart) EConnectionType(org.talend.core.model.process.EConnectionType) ConnLabelEditPart(org.talend.designer.core.ui.editor.connections.ConnLabelEditPart)

Example 4 with ConnLabelEditPart

use of org.talend.designer.core.ui.editor.connections.ConnLabelEditPart in project tdi-studio-se by Talend.

the class FilterTraceColumnAction method calculateEnabled.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.gef.ui.actions.WorkbenchPartAction#calculateEnabled()
     */
@Override
protected boolean calculateEnabled() {
    List parts = getSelectedObjects();
    if (parts.size() != 1) {
        return false;
    }
    Object input = parts.get(0);
    if (input instanceof ConnectionPart) {
        ConnectionPart connPart = (ConnectionPart) input;
        List childParts = connPart.getChildren();
        for (Object part : childParts) {
            if (part != null && part instanceof ConnectionTraceEditPart) {
                connection = (Connection) connPart.getModel();
                return connection.enableTraces() && connection.checkTraceShowEnable();
            }
        }
    }
    if (input instanceof ConnLabelEditPart) {
        ConnLabelEditPart labelPart = (ConnLabelEditPart) input;
        ConnectionPart connPart = (ConnectionPart) labelPart.getParent();
        List childParts = connPart.getChildren();
        for (Object part : childParts) {
            if (part != null && part instanceof ConnectionTraceEditPart) {
                connection = (Connection) connPart.getModel();
                return connection.enableTraces() && connection.checkTraceShowEnable();
            }
        }
    }
    if (input instanceof ConnectionTraceEditPart) {
        ConnectionTraceEditPart connTrace = (ConnectionTraceEditPart) input;
        if (connTrace.getParent() instanceof ConnectionPart) {
            ConnectionPart connPart = (ConnectionPart) connTrace.getParent();
            connection = (Connection) connPart.getModel();
            return connection.enableTraces() && connection.checkTraceShowEnable();
        }
    }
    return false;
}
Also used : ConnectionTraceEditPart(org.talend.designer.core.ui.editor.connections.ConnectionTraceEditPart) List(java.util.List) ConnectionPart(org.talend.designer.core.ui.editor.connections.ConnectionPart) ConnLabelEditPart(org.talend.designer.core.ui.editor.connections.ConnLabelEditPart)

Example 5 with ConnLabelEditPart

use of org.talend.designer.core.ui.editor.connections.ConnLabelEditPart in project tdi-studio-se by Talend.

the class AbstractTraceAction method calculateEnabled.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.gef.ui.actions.WorkbenchPartAction#calculateEnabled()
     */
@Override
protected boolean calculateEnabled() {
    List parts = getSelectedObjects();
    if (parts.size() != 1) {
        return false;
    }
    Object input = parts.get(0);
    if (input instanceof ConnectionPart) {
        ConnectionPart connPart = (ConnectionPart) input;
        List childParts = connPart.getChildren();
        for (Object part : childParts) {
            if (part != null && part instanceof ConnectionTraceEditPart) {
                Connection conn = (Connection) connPart.getModel();
                if (conn.enableTraces() && conn.checkTraceShowEnable()) {
                    IElementParameter element = conn.getElementParameter(EParameterName.TRACES_CONNECTION_ENABLE.getName());
                    Boolean flag = (Boolean) element.getValue();
                    if (flag != isEnableAction()) {
                        return true;
                    }
                }
            }
        }
    }
    if (input instanceof ConnLabelEditPart) {
        ConnLabelEditPart labelPart = (ConnLabelEditPart) input;
        ConnectionPart connPart = (ConnectionPart) labelPart.getParent();
        List childParts = connPart.getChildren();
        for (Object part : childParts) {
            if (part != null && part instanceof ConnectionTraceEditPart) {
                Connection conn = (Connection) connPart.getModel();
                if (conn.enableTraces() && conn.checkTraceShowEnable()) {
                    IElementParameter element = conn.getElementParameter(EParameterName.TRACES_CONNECTION_ENABLE.getName());
                    Boolean flag = (Boolean) element.getValue();
                    if (flag != isEnableAction()) {
                        return true;
                    }
                }
            }
        }
    }
    if (input instanceof ConnectionTraceEditPart) {
        ConnectionTraceEditPart tracePart = (ConnectionTraceEditPart) input;
        ConnectionPart connPart = (ConnectionPart) tracePart.getParent();
        Connection conn = (Connection) connPart.getModel();
        if (conn.enableTraces() && conn.checkTraceShowEnable()) {
            IElementParameter element = conn.getElementParameter(EParameterName.TRACES_CONNECTION_ENABLE.getName());
            Boolean flag = (Boolean) element.getValue();
            if (flag != isEnableAction()) {
                return true;
            }
        }
    }
    return false;
}
Also used : ConnectionTraceEditPart(org.talend.designer.core.ui.editor.connections.ConnectionTraceEditPart) Connection(org.talend.designer.core.ui.editor.connections.Connection) IElementParameter(org.talend.core.model.process.IElementParameter) List(java.util.List) ConnectionPart(org.talend.designer.core.ui.editor.connections.ConnectionPart) ConnLabelEditPart(org.talend.designer.core.ui.editor.connections.ConnLabelEditPart)

Aggregations

ConnLabelEditPart (org.talend.designer.core.ui.editor.connections.ConnLabelEditPart)20 ConnectionPart (org.talend.designer.core.ui.editor.connections.ConnectionPart)16 List (java.util.List)15 NodePart (org.talend.designer.core.ui.editor.nodes.NodePart)12 NoteEditPart (org.talend.designer.core.ui.editor.notes.NoteEditPart)10 Connection (org.talend.designer.core.ui.editor.connections.Connection)9 Node (org.talend.designer.core.ui.editor.nodes.Node)8 NodeLabelEditPart (org.talend.designer.core.ui.editor.nodes.NodeLabelEditPart)8 ArrayList (java.util.ArrayList)7 EditPart (org.eclipse.gef.EditPart)7 SubjobContainerPart (org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainerPart)7 ProcessPart (org.talend.designer.core.ui.editor.process.ProcessPart)6 Clipboard (org.eclipse.gef.ui.actions.Clipboard)4 ConnectionTraceEditPart (org.talend.designer.core.ui.editor.connections.ConnectionTraceEditPart)4 NodeContainerPart (org.talend.designer.core.ui.editor.nodecontainer.NodeContainerPart)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 Text (org.eclipse.swt.widgets.Text)3 IElementParameter (org.talend.core.model.process.IElementParameter)3 INode (org.talend.core.model.process.INode)3 AbstractProcessProvider (org.talend.designer.core.model.process.AbstractProcessProvider)3