Search in sources :

Example 46 with Transfer

use of org.eclipse.swt.dnd.Transfer 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 47 with Transfer

use of org.eclipse.swt.dnd.Transfer 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

Transfer (org.eclipse.swt.dnd.Transfer)47 TextTransfer (org.eclipse.swt.dnd.TextTransfer)39 Clipboard (org.eclipse.swt.dnd.Clipboard)23 Point (org.eclipse.swt.graphics.Point)19 Display (org.eclipse.swt.widgets.Display)13 FileTransfer (org.eclipse.swt.dnd.FileTransfer)12 Text (org.eclipse.swt.widgets.Text)12 StyledText (org.eclipse.swt.custom.StyledText)11 HTMLTransfer (org.eclipse.swt.dnd.HTMLTransfer)11 RTFTransfer (org.eclipse.swt.dnd.RTFTransfer)11 GridData (org.eclipse.swt.layout.GridData)11 GridLayout (org.eclipse.swt.layout.GridLayout)11 Button (org.eclipse.swt.widgets.Button)11 Shell (org.eclipse.swt.widgets.Shell)11 Table (org.eclipse.swt.widgets.Table)11 DragSourceEvent (org.eclipse.swt.dnd.DragSourceEvent)10 DropTarget (org.eclipse.swt.dnd.DropTarget)10 DropTargetEvent (org.eclipse.swt.dnd.DropTargetEvent)10 Composite (org.eclipse.swt.widgets.Composite)10 Label (org.eclipse.swt.widgets.Label)10