Search in sources :

Example 1 with NoteDirectEditManager

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

the class GEFCopyAction method run.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.action.Action#run()
     */
@Override
public void run() {
    List objects = GEFDeleteAction.filterSameObject(getSelectedObjects());
    if (!objects.isEmpty()) {
        Clipboard clipboard = Clipboard.getDefault();
        org.eclipse.swt.dnd.Clipboard systemClipboard = new org.eclipse.swt.dnd.Clipboard(Display.getCurrent());
        boolean noteTextActived = false;
        boolean connectionTextActived = false;
        boolean nodeLabelActived = false;
        Text text = null;
        if (objects.size() == 1) {
            if (objects.get(0) instanceof NoteEditPart) {
                NoteDirectEditManager directEditManager = ((NoteEditPart) objects.get(0)).getDirectEditManager();
                if (directEditManager != null && directEditManager.getCellEditor() != null) {
                    noteTextActived = true;
                }
            } else if (objects.get(0) instanceof ConnLabelEditPart) {
                ConnLabelEditPart connLabelEditPart = (ConnLabelEditPart) objects.get(0);
                if (connLabelEditPart.getDirectEditManager() != null && connLabelEditPart.getDirectEditManager().getTextControl() != null) {
                    connectionTextActived = true;
                }
            } else if (objects.get(0) instanceof NodeLabelEditPart) {
                NodeLabelEditPart nodeLabelEditPart = (NodeLabelEditPart) objects.get(0);
                if (nodeLabelEditPart.getDirectEditManager() != null && nodeLabelEditPart.getDirectEditManager().getCellEditor() != null) {
                    nodeLabelActived = true;
                }
            }
        }
        if (noteTextActived) {
            text = ((NoteEditPart) objects.get(0)).getDirectEditManager().getTextControl();
            clipboard.setContents(text.getSelectionText());
        } else if (connectionTextActived) {
            text = ((ConnLabelEditPart) objects.get(0)).getDirectEditManager().getTextControl();
            clipboard.setContents(text.getSelectionText());
        } else if (nodeLabelActived) {
            text = (Text) ((NodeLabelEditPart) objects.get(0)).getDirectEditManager().getCellEditor().getControl();
            clipboard.setContents(text.getSelectionText());
        } else {
            clipboard.setContents(objects);
        }
        if (text != null && !("").equals(text.getSelectionText())) {
            TextTransfer textTransfer = TextTransfer.getInstance();
            Transfer[] transfers = new Transfer[] { textTransfer };
            Object[] data = new Object[] { text.getSelectionText() };
            systemClipboard.setContents(data, transfers);
        }
    }
    // Refreshes the pasteAction's enable status.
    IWorkbenchPart part = getWorkbenchPart();
    if (part instanceof AbstractTalendEditor) {
        AbstractTalendEditor talendEditor = (AbstractTalendEditor) part;
        IAction action = talendEditor.getActionRegistry().getAction(ActionFactory.PASTE.getId());
        action.setEnabled(true);
    }
}
Also used : NoteDirectEditManager(org.talend.designer.core.ui.editor.notes.NoteDirectEditManager) IAction(org.eclipse.jface.action.IAction) NoteEditPart(org.talend.designer.core.ui.editor.notes.NoteEditPart) NodeLabelEditPart(org.talend.designer.core.ui.editor.nodes.NodeLabelEditPart) Text(org.eclipse.swt.widgets.Text) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) AbstractTalendEditor(org.talend.designer.core.ui.editor.AbstractTalendEditor) Transfer(org.eclipse.swt.dnd.Transfer) TextTransfer(org.eclipse.swt.dnd.TextTransfer) List(java.util.List) Clipboard(org.eclipse.gef.ui.actions.Clipboard) ConnLabelEditPart(org.talend.designer.core.ui.editor.connections.ConnLabelEditPart) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Aggregations

List (java.util.List)1 Clipboard (org.eclipse.gef.ui.actions.Clipboard)1 IAction (org.eclipse.jface.action.IAction)1 TextTransfer (org.eclipse.swt.dnd.TextTransfer)1 Transfer (org.eclipse.swt.dnd.Transfer)1 Text (org.eclipse.swt.widgets.Text)1 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)1 AbstractTalendEditor (org.talend.designer.core.ui.editor.AbstractTalendEditor)1 ConnLabelEditPart (org.talend.designer.core.ui.editor.connections.ConnLabelEditPart)1 NodeLabelEditPart (org.talend.designer.core.ui.editor.nodes.NodeLabelEditPart)1 NoteDirectEditManager (org.talend.designer.core.ui.editor.notes.NoteDirectEditManager)1 NoteEditPart (org.talend.designer.core.ui.editor.notes.NoteEditPart)1