Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Tasse2015-06-09 19:07:04 +0000
committerPatrick Tasse2015-06-11 19:47:46 +0000
commit9ba0a108c20342909431ee83201746e44b80916b (patch)
tree01a03a0d845a66b8775f4b20bdc938075fd55132 /org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui
parenta87f89437ba7f966a3a2ea75b73d3eae3a3280db (diff)
downloadorg.eclipse.tracecompass-9ba0a108c20342909431ee83201746e44b80916b.tar.gz
org.eclipse.tracecompass-9ba0a108c20342909431ee83201746e44b80916b.tar.xz
org.eclipse.tracecompass-9ba0a108c20342909431ee83201746e44b80916b.zip
tmf: Add Copy to Clipboard in TmfEventsTable
Change-Id: Ic2ca73787e294ba69fcaa4b111e5a21ff66bb9a1 Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com> Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com> Reviewed-on: https://git.eclipse.org/r/49834 Reviewed-by: Hudson CI
Diffstat (limited to 'org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui')
-rw-r--r--org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/Messages.java5
-rw-r--r--org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/commands/CopyToClipboardOperation.java163
-rw-r--r--org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/messages.properties5
3 files changed, 173 insertions, 0 deletions
diff --git a/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/Messages.java b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/Messages.java
index 513534af75..177174cfca 100644
--- a/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/Messages.java
+++ b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/Messages.java
@@ -41,6 +41,7 @@ public class Messages extends NLS {
public static String TmfEventsTable_ClearFiltersActionText;
public static String TmfEventsTable_CollapseFilterMenuName;
public static String TmfEventsTable_ContentColumnHeader;
+ public static String TmfEventsTable_CopyToClipboardActionText;
public static String TmfEventsTable_Export_to_text;
public static String TmfEventsTable_FilterHint;
public static String TmfEventsTable_HideRawActionText;
@@ -304,6 +305,10 @@ public class Messages extends NLS {
public static String CallStackView_ImportBinaryFileButtonTooltip;
public static String CallStackView_ImportBinaryFileDialogTitle;
+ public static String CopyToClipboardOperation_TaskName;
+ public static String CopyToClipboardOperation_OutOfMemoryErrorTitle;
+ public static String CopyToClipboardOperation_OutOfMemoryErrorMessage;
+
public static String ExportToTextJob_Export_to;
public static String ExportToTextJob_Export_trace_to;
public static String ExportToTextJob_Unable_to_export_trace;
diff --git a/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/commands/CopyToClipboardOperation.java b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/commands/CopyToClipboardOperation.java
new file mode 100644
index 0000000000..2aca2e7efa
--- /dev/null
+++ b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/commands/CopyToClipboardOperation.java
@@ -0,0 +1,163 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.tmf.ui.commands;
+
+import java.util.List;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.dnd.TextTransfer;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.MessageBox;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.tracecompass.internal.tmf.ui.Activator;
+import org.eclipse.tracecompass.internal.tmf.ui.Messages;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+import org.eclipse.tracecompass.tmf.core.filter.ITmfFilter;
+import org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest;
+import org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest.ExecutionType;
+import org.eclipse.tracecompass.tmf.core.request.TmfEventRequest;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
+import org.eclipse.tracecompass.tmf.ui.viewers.events.columns.TmfEventTableColumn;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * This operation copies the text of selected trace events to the clipboard.
+ */
+public class CopyToClipboardOperation implements IRunnableWithProgress {
+
+ private static final String LINE_SEPARATOR = System.getProperty("line.separator"); //$NON-NLS-1$
+ private final ITmfTrace fTrace;
+ private final ITmfFilter fFilter;
+ private final List<TmfEventTableColumn> fColumns;
+ private final long fStartRank;
+ private final long fEndRank;
+
+ /**
+ * Constructor.
+ *
+ * @param trace
+ * the trace to copy events from
+ * @param filter
+ * the filter to apply to trace events, or null
+ * @param columns
+ * the list of event table columns
+ * @param start
+ * the start rank of the selection
+ * @param end
+ * the end rank of the selection
+ */
+ public CopyToClipboardOperation(ITmfTrace trace, ITmfFilter filter, List<TmfEventTableColumn> columns, long start, long end) {
+ fTrace = trace;
+ fFilter = filter;
+ fColumns = columns;
+ fStartRank = start;
+ fEndRank = end;
+ }
+
+ @Override
+ public void run(IProgressMonitor monitor) {
+ final StringBuilder sb = new StringBuilder();
+ monitor.beginTask(Messages.CopyToClipboardOperation_TaskName, (int) (fEndRank - fStartRank + 1));
+
+ boolean needTab = false;
+ for (TmfEventTableColumn column : fColumns) {
+ if (needTab) {
+ sb.append('\t');
+ }
+ sb.append(column.getHeaderName());
+ needTab = true;
+ }
+ sb.append(LINE_SEPARATOR);
+
+ copy(sb, monitor);
+
+ Display.getDefault().syncExec(new Runnable() {
+ @Override
+ public void run() {
+ if (sb.length() == 0) {
+ return;
+ }
+ try {
+ Clipboard clipboard = new Clipboard(Display.getDefault());
+ clipboard.setContents(new Object[] { sb.toString() },
+ new Transfer[] { TextTransfer.getInstance() });
+ } catch (OutOfMemoryError e) {
+ sb.setLength(0);
+ sb.trimToSize();
+ showErrorDialog();
+ }
+ }
+ });
+
+ monitor.done();
+ }
+
+ private IStatus copy(final StringBuilder sb, final IProgressMonitor monitor) {
+ ITmfEventRequest request = new TmfEventRequest(ITmfEvent.class, TmfTimeRange.ETERNITY, fStartRank, (int) (fEndRank - fStartRank + 1), ExecutionType.FOREGROUND) {
+ @Override
+ public void handleData(ITmfEvent event) {
+ super.handleData(event);
+ if (monitor.isCanceled()) {
+ cancel();
+ return;
+ }
+ monitor.worked(1);
+ if (fFilter == null || fFilter.matches(event)) {
+ try {
+ boolean needTab = false;
+ for (TmfEventTableColumn column : fColumns) {
+ if (needTab) {
+ sb.append('\t');
+ }
+ sb.append(column.getItemString(event));
+ needTab = true;
+ }
+ sb.append(LINE_SEPARATOR);
+ } catch (OutOfMemoryError e) {
+ sb.setLength(0);
+ sb.trimToSize();
+ showErrorDialog();
+ cancel();
+ }
+ }
+ }
+ };
+ fTrace.sendRequest(request);
+ try {
+ request.waitForCompletion();
+ } catch (InterruptedException e) {
+ Activator.getDefault().logError("Wait for completion interrupted for copy to clipboard ", e); //$NON-NLS-1$
+ }
+ return Status.OK_STATUS;
+ }
+
+ private static void showErrorDialog() {
+ Display.getDefault().syncExec(new Runnable() {
+ @Override
+ public void run() {
+ Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+ MessageBox confirmOperation = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
+ confirmOperation.setText(Messages.CopyToClipboardOperation_OutOfMemoryErrorTitle);
+ confirmOperation.setMessage(Messages.CopyToClipboardOperation_OutOfMemoryErrorMessage);
+ confirmOperation.open();
+ }
+ });
+ }
+}
diff --git a/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/messages.properties b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/messages.properties
index c1c42847fa..7d91c60fd0 100644
--- a/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/messages.properties
+++ b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/messages.properties
@@ -34,6 +34,7 @@ TmfEventsTable_ApplyPresetFilterMenuName=Apply Preset Filter...
TmfEventsTable_ClearFiltersActionText=Clear Filters
TmfEventsTable_CollapseFilterMenuName=Collapse Events
TmfEventsTable_ContentColumnHeader=Content
+TmfEventsTable_CopyToClipboardActionText=Copy to Clipboard
TmfEventsTable_Export_to_text=Export To Text...
TmfEventsTable_FilterHint=<filter>
TmfEventsTable_HideRawActionText=Hide Raw
@@ -303,6 +304,10 @@ CallStackView_ImportBinaryFileButtonText=Import binary file...
CallStackView_ImportBinaryFileButtonTooltip=Import a binary file containing debugging symbols
CallStackView_ImportBinaryFileDialogTitle=Select Binary File
+CopyToClipboardOperation_TaskName=Copying to Clipboard
+CopyToClipboardOperation_OutOfMemoryErrorTitle=Out Of Memory Error
+CopyToClipboardOperation_OutOfMemoryErrorMessage=The full selection cannot be copied to the clipboard. Press OK to abort.
+
ExportToTextJob_Export_to=Export to {0}...
ExportToTextJob_Export_trace_to=Export trace to {0}
ExportToTextJob_Unable_to_export_trace=Unable to export trace to {0}

Back to the top