Search in sources :

Example 1 with CamelTalendEditor

use of org.talend.camel.designer.ui.editor.CamelTalendEditor in project tesb-studio-se by Talend.

the class RoutePasteAction method run.

@SuppressWarnings("unchecked")
@Override
public void run() {
    Object clipBoardContent;
    try {
        clipBoardContent = Clipboard.getDefault().getContents();
    } catch (RuntimeException e) {
        return;
    }
    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>();
        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);
            }
        }
        CamelTalendEditor editor = (CamelTalendEditor) this.getWorkbenchPart();
        org.eclipse.draw2d.geometry.Point gefPoint = getCursorLocation();
        AbstractProcessProvider findProcessProviderFromPID = AbstractProcessProvider.findProcessProviderFromPID(IComponent.JOBLET_PID);
        if (findProcessProviderFromPID != null) {
            boolean isDuplicateRoutelet = false;
            String duplicateRouteletName = "";
            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)) {
                    // Check if is copying routelet in itself
                    if (editorProcessId != null && editorProcessId.equals(copideNodeId)) {
                        return;
                    }
                    // Check if is duplicate routelet
                    if (editor.getProcess().getNodesOfType(copiedNode.getComponent().getName()).size() > 0) {
                        isDuplicateRoutelet = true;
                        // $NON-NLS-1$
                        duplicateRouteletName += " ," + copiedNode.getComponent().getName();
                    }
                }
                // Check if it's Camel component
                if (!ComponentCategory.CATEGORY_4_CAMEL.getName().equals(copiedNode.getComponent().getType())) {
                    return;
                }
            }
            if (isDuplicateRoutelet) {
                MessageDialog.openInformation(editor.getEditorSite().getShell(), // $NON-NLS-1$
                "Copying Routelet", // $NON-NLS-1$
                "Do not allow duplicate Routelets\nRoutelet \"" + duplicateRouteletName.substring(2) + "\" already exist.");
                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(new ArrayList<SubjobContainerPart>());
            execute(mpc);
        } else if (nodeParts.size() != 0) {
            NodesPasteCommand cmd = new NodesPasteCommand(nodeParts, (org.talend.designer.core.ui.editor.process.Process) editor.getProcess(), gefPoint);
            cmd.setSelectedSubjobs(new ArrayList<SubjobContainerPart>());
            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 : Node(org.talend.designer.core.ui.editor.nodes.Node) ArrayList(java.util.ArrayList) NodeLabelEditPart(org.talend.designer.core.ui.editor.nodes.NodeLabelEditPart) 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) IElementParameter(org.talend.core.model.process.IElementParameter) ArrayList(java.util.ArrayList) List(java.util.List) NodesPasteCommand(org.talend.designer.core.ui.editor.cmd.NodesPasteCommand) CamelTalendEditor(org.talend.camel.designer.ui.editor.CamelTalendEditor) 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) Text(org.eclipse.swt.widgets.Text) Clipboard(org.eclipse.gef.ui.actions.Clipboard) NodePart(org.talend.designer.core.ui.editor.nodes.NodePart) Map(java.util.Map) ConnLabelEditPart(org.talend.designer.core.ui.editor.connections.ConnLabelEditPart)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 EditPart (org.eclipse.gef.EditPart)1 Clipboard (org.eclipse.gef.ui.actions.Clipboard)1 Text (org.eclipse.swt.widgets.Text)1 CamelTalendEditor (org.talend.camel.designer.ui.editor.CamelTalendEditor)1 EComponentType (org.talend.core.model.components.EComponentType)1 IElementParameter (org.talend.core.model.process.IElementParameter)1 AbstractProcessProvider (org.talend.designer.core.model.process.AbstractProcessProvider)1 MultiplePasteCommand (org.talend.designer.core.ui.editor.cmd.MultiplePasteCommand)1 NodesPasteCommand (org.talend.designer.core.ui.editor.cmd.NodesPasteCommand)1 NotesPasteCommand (org.talend.designer.core.ui.editor.cmd.NotesPasteCommand)1 ConnLabelEditPart (org.talend.designer.core.ui.editor.connections.ConnLabelEditPart)1 Node (org.talend.designer.core.ui.editor.nodes.Node)1 NodeLabelEditPart (org.talend.designer.core.ui.editor.nodes.NodeLabelEditPart)1 NodePart (org.talend.designer.core.ui.editor.nodes.NodePart)1 NoteEditPart (org.talend.designer.core.ui.editor.notes.NoteEditPart)1 SubjobContainerPart (org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainerPart)1