Search in sources :

Example 36 with Clipboard

use of org.eclipse.swt.dnd.Clipboard in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_custom_StyledText method test_copy.

@Test
public void test_copy() {
    if (SwtTestUtil.isCocoa) {
        // TODO Fix Cocoa failure.
        if (SwtTestUtil.verbose) {
            System.out.println("Excluded test_copy(org.eclipse.swt.tests.junit.Test_org_eclipse_swt_custom_StyledText).");
        }
        return;
    }
    Clipboard clipboard = new Clipboard(text.getDisplay());
    TextTransfer transfer = TextTransfer.getInstance();
    String clipboardText;
    String convertedText;
    String before = (String) clipboard.getContents(transfer);
    text.setSelectionRange(0, 0);
    text.copy();
    clipboardText = (String) clipboard.getContents(transfer);
    assertTrue(":a:", before == null ? clipboardText == null : before.equals(clipboardText));
    before = (String) clipboard.getContents(transfer);
    text.setText("0123456789");
    text.setSelectionRange(0, 0);
    text.copy();
    clipboardText = (String) clipboard.getContents(transfer);
    assertTrue(":c:", before == null ? clipboardText == null : before.equals(clipboardText));
    text.setSelectionRange(0, 1);
    text.copy();
    clipboardText = (String) clipboard.getContents(transfer);
    assertTrue(":d:", clipboardText != null && clipboardText.equals("0"));
    text.setSelectionRange(1, 2);
    text.copy();
    clipboardText = (String) clipboard.getContents(transfer);
    assertTrue(":e:", clipboardText != null && clipboardText.equals("12"));
    // test line delimiter conversion
    text.setText("\rLine1\nLine2\r\nLine3\n\rLine4\n");
    text.setSelectionRange(0, text.getCharCount());
    text.copy();
    clipboardText = (String) clipboard.getContents(transfer);
    if (SwtTestUtil.isWindowsOS) {
        convertedText = "\r\nLine1\r\nLine2\r\nLine3\r\n\r\nLine4\r\n";
    } else {
        convertedText = "\nLine1\nLine2\nLine3\n\nLine4\n";
    }
    assertTrue(":f:", clipboardText != null && clipboardText.equals(convertedText));
    // test line delimiter conversion
    text.setText("Line1\r\nLine2");
    text.setSelectionRange(0, text.getCharCount());
    text.copy();
    clipboardText = (String) clipboard.getContents(transfer);
    if (SwtTestUtil.isWindowsOS) {
        convertedText = "Line1\r\nLine2";
    } else {
        convertedText = "Line1\nLine2";
    }
    assertTrue(":g:", clipboardText != null && clipboardText.equals(convertedText));
    rtfCopy();
    clipboard.dispose();
}
Also used : Clipboard(org.eclipse.swt.dnd.Clipboard) TextTransfer(org.eclipse.swt.dnd.TextTransfer) Test(org.junit.Test)

Example 37 with Clipboard

use of org.eclipse.swt.dnd.Clipboard in project yamcs-studio by yamcs.

the class CopyCommandHistoryEntryDetailsHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection sel = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection();
    if (sel != null && sel instanceof IStructuredSelection) {
        IStructuredSelection selection = (IStructuredSelection) sel;
        String property = event.getParameter(CommandHistory.CMDPARAM_EVENT_PROPERTY);
        StringBuilder text = new StringBuilder();
        Iterator<?> it = selection.iterator();
        while (it.hasNext()) {
            CommandHistoryRecord rec = (CommandHistoryRecord) it.next();
            switch(property) {
                case PARAM_GENTIME:
                    text.append(rec.getGenerationTime());
                    break;
                case PARAM_COMMAND:
                    text.append(rec.getCommandString());
                    break;
                case PARAM_SOURCE:
                    text.append(rec.getUsername() + "@" + rec.getOrigin());
                    break;
                case PARAM_SEQNO:
                    text.append(rec.getSequenceNumber());
                    break;
                default:
                    throw new IllegalStateException("Unexpected property: " + property);
            }
            if (it.hasNext()) {
                text.append("\n");
            }
        }
        Display display = Display.getCurrent();
        Clipboard clipboard = new Clipboard(display);
        Transfer[] transfers = new Transfer[] { TextTransfer.getInstance() };
        clipboard.setContents(new Object[] { text.toString() }, transfers);
        clipboard.dispose();
    }
    return null;
}
Also used : ISelection(org.eclipse.jface.viewers.ISelection) TextTransfer(org.eclipse.swt.dnd.TextTransfer) Transfer(org.eclipse.swt.dnd.Transfer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Clipboard(org.eclipse.swt.dnd.Clipboard) Display(org.eclipse.swt.widgets.Display)

Example 38 with Clipboard

use of org.eclipse.swt.dnd.Clipboard in project yamcs-studio by yamcs.

the class CopyCommandHistoryEntryHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection sel = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection();
    if (sel != null && sel instanceof IStructuredSelection) {
        IStructuredSelection selection = (IStructuredSelection) sel;
        StringBuilder text = new StringBuilder("T\tCommand\tSource\tSequence Number\n");
        List<CommandHistoryRecord> recList = new ArrayList<>();
        Iterator<?> it = selection.iterator();
        while (it.hasNext()) {
            CommandHistoryRecord rec = (CommandHistoryRecord) it.next();
            recList.add(rec);
            text.append(rec.getGenerationTime()).append("\t").append(rec.getCommandString()).append("\t").append(rec.getUsername() + "@" + rec.getOrigin()).append("\t").append(rec.getSequenceNumber()).append("\n");
        }
        if (!recList.isEmpty()) {
            CommandClipboard.addCommandHistoryRecords(recList);
        }
        Display display = Display.getCurrent();
        Clipboard clipboard = new Clipboard(display);
        Transfer[] transfers = new Transfer[] { TextTransfer.getInstance() };
        clipboard.setContents(new Object[] { text.toString() }, transfers);
        clipboard.dispose();
    }
    return null;
}
Also used : ISelection(org.eclipse.jface.viewers.ISelection) ArrayList(java.util.ArrayList) Transfer(org.eclipse.swt.dnd.Transfer) TextTransfer(org.eclipse.swt.dnd.TextTransfer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Clipboard(org.eclipse.swt.dnd.Clipboard) CommandClipboard(org.yamcs.studio.commanding.stack.CommandClipboard) Display(org.eclipse.swt.widgets.Display)

Example 39 with Clipboard

use of org.eclipse.swt.dnd.Clipboard in project yamcs-studio by yamcs.

the class CommandClipboard method textToClipboard.

private static void textToClipboard(String text, Display display) {
    final Clipboard cb = new Clipboard(display);
    TextTransfer textTransfer = TextTransfer.getInstance();
    cb.setContents(new Object[] { text }, new Transfer[] { textTransfer });
}
Also used : Clipboard(org.eclipse.swt.dnd.Clipboard) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 40 with Clipboard

use of org.eclipse.swt.dnd.Clipboard in project yamcs-studio by yamcs.

the class RuntimePatchedSelectionTool method handleButtonDown.

/**
 * Intercept middle clicks and copy PV name to pastebuffer if available.
 * Change cursor to copy symbol.
 */
@Override
protected boolean handleButtonDown(int button) {
    if (button == 2) {
        EditPart editPart = getTargetEditPart();
        if (editPart instanceof AbstractPVWidgetEditPart) {
            AbstractPVWidgetEditPart apvwep = (AbstractPVWidgetEditPart) editPart;
            String pvName = ((AbstractPVWidgetModel) editPart.getModel()).getPVName();
            if (pvName != "" && pvName != null) {
                Display display = Display.getCurrent();
                Clipboard clipboard = new Clipboard(display);
                // Copies to middle button paste buffer,
                // to be pasted via another middle-button click
                clipboard.setContents(new Object[] { pvName }, new Transfer[] { TextTransfer.getInstance() }, DND.SELECTION_CLIPBOARD);
                // Copies to normal clipboard,
                // to be pasted via Ctrl-V or Edit/Paste
                clipboard.setContents(new String[] { pvName }, new Transfer[] { TextTransfer.getInstance() });
                clipboard.dispose();
                IFigure figure = apvwep.getFigure();
                oldCursor = figure.getCursor();
                figure.setCursor(ResourceUtil.getCopyPvCursor());
                cursorChanged = true;
            }
        }
        return true;
    } else {
        return super.handleButtonDown(button);
    }
}
Also used : AbstractPVWidgetEditPart(org.csstudio.opibuilder.editparts.AbstractPVWidgetEditPart) AbstractPVWidgetEditPart(org.csstudio.opibuilder.editparts.AbstractPVWidgetEditPart) EditPart(org.eclipse.gef.EditPart) AbstractPVWidgetModel(org.csstudio.opibuilder.model.AbstractPVWidgetModel) Clipboard(org.eclipse.swt.dnd.Clipboard) Display(org.eclipse.swt.widgets.Display) IFigure(org.eclipse.draw2d.IFigure)

Aggregations

Clipboard (org.eclipse.swt.dnd.Clipboard)73 TextTransfer (org.eclipse.swt.dnd.TextTransfer)50 Transfer (org.eclipse.swt.dnd.Transfer)19 Point (org.eclipse.swt.graphics.Point)12 StyledText (org.eclipse.swt.custom.StyledText)8 Composite (org.eclipse.swt.widgets.Composite)7 Display (org.eclipse.swt.widgets.Display)7 IAction (org.eclipse.jface.action.IAction)6 ISelection (org.eclipse.jface.viewers.ISelection)6 GridLayout (org.eclipse.swt.layout.GridLayout)6 Control (org.eclipse.swt.widgets.Control)6 TableItem (org.eclipse.swt.widgets.TableItem)6 ArrayList (java.util.ArrayList)5 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)5 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)5 SelectionEvent (org.eclipse.swt.events.SelectionEvent)5 GridData (org.eclipse.swt.layout.GridData)5 Event (org.eclipse.swt.widgets.Event)4 Shell (org.eclipse.swt.widgets.Shell)4 Rectangle (org.eclipse.swt.graphics.Rectangle)3