Search in sources :

Example 71 with Clipboard

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

the class ExceptionDetailsErrorDialog method copyToClipboard.

/**
 * Copy the contents of the statuses to the clipboard.
 */
private void copyToClipboard() {
    if (clipboard != null) {
        clipboard.dispose();
    }
    StringBuffer statusBuffer = new StringBuffer();
    // populateCopyBuffer(status, statusBuffer, 0);
    statusBuffer.append(text.getText());
    clipboard = new Clipboard(text.getDisplay());
    clipboard.setContents(new Object[] { statusBuffer.toString() }, new Transfer[] { TextTransfer.getInstance() });
}
Also used : Clipboard(org.eclipse.swt.dnd.Clipboard)

Example 72 with Clipboard

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

the class CopyEventDetailsHandler 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(EventLog.CMDPARAM_EVENT_PROPERTY);
        StringBuilder text = new StringBuilder();
        Iterator<?> it = selection.iterator();
        while (it.hasNext()) {
            Event rec = (Event) it.next();
            switch(property) {
                case PARAM_MESSAGE:
                    text.append(rec.getMessage());
                    break;
                case PARAM_SOURCE:
                    text.append(rec.getSource());
                    break;
                case PARAM_TYPE:
                    text.append(rec.getSource());
                    break;
                case PARAM_GENTIME:
                    text.append(rec.getGenerationTimeUTC());
                    break;
                case PARAM_RECTIME:
                    text.append(rec.getReceptionTimeUTC());
                    break;
                case PARAM_SEQNO:
                    text.append(rec.getSeqNumber());
                    break;
                case PARAM_SEVERITY:
                    text.append(rec.getSeverity());
                    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) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) Event(org.yamcs.protobuf.Yamcs.Event) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Clipboard(org.eclipse.swt.dnd.Clipboard) Display(org.eclipse.swt.widgets.Display)

Example 73 with Clipboard

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

the class CopyEventHandler 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("Severity\tMessage\tType\tSource\tGeneration\tReception\tSequence Number\n");
        Iterator<?> it = selection.iterator();
        while (it.hasNext()) {
            Event rec = (Event) it.next();
            text.append(rec.getSeverity()).append("\t").append(rec.getMessage()).append("\t").append(rec.getType()).append("\t").append(rec.getSource()).append("\t").append(rec.getGenerationTimeUTC()).append("\t").append(rec.getReceptionTimeUTC()).append("\t").append(rec.getSeqNumber()).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) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) Event(org.yamcs.protobuf.Yamcs.Event) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Clipboard(org.eclipse.swt.dnd.Clipboard) Display(org.eclipse.swt.widgets.Display)

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