Commit | Line | Data |
---|---|---|
d3de0920 | 1 | /******************************************************************************* |
53bae902 | 2 | * Copyright (c) 2013, 2014 Kalray, Ericsson |
d3de0920 XR |
3 | * |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * Xavier Raynaud - Initial API and implementation | |
53bae902 | 11 | * Bernd Hufmann - Adapted to new events table column API |
d3de0920 XR |
12 | *******************************************************************************/ |
13 | ||
2bdf0193 | 14 | package org.eclipse.tracecompass.internal.tmf.ui.commands; |
d3de0920 | 15 | |
53bae902 BH |
16 | import java.util.List; |
17 | ||
d3de0920 XR |
18 | import org.eclipse.core.commands.AbstractHandler; |
19 | import org.eclipse.core.commands.ExecutionEvent; | |
20 | import org.eclipse.core.commands.ExecutionException; | |
21 | import org.eclipse.core.expressions.IEvaluationContext; | |
22 | import org.eclipse.core.runtime.jobs.Job; | |
d3de0920 XR |
23 | import org.eclipse.swt.SWT; |
24 | import org.eclipse.swt.widgets.FileDialog; | |
2bdf0193 AM |
25 | import org.eclipse.tracecompass.tmf.core.filter.ITmfFilter; |
26 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; | |
27 | import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager; | |
28 | import org.eclipse.tracecompass.tmf.ui.viewers.events.columns.TmfEventTableColumn; | |
d3de0920 XR |
29 | import org.eclipse.ui.PlatformUI; |
30 | ||
31 | /** | |
32 | * This handler exports traces to text files. | |
33 | * @author Xavier Raynaud <xavier.raynaud@kalray.eu> | |
34 | */ | |
35 | public class ExportToTextCommandHandler extends AbstractHandler { | |
36 | ||
37 | /** Id of the export-to-text command */ | |
38 | public static final String COMMAND_ID = "org.eclipse.linuxtools.tmf.ui.exportToText"; //$NON-NLS-1$ | |
d3de0920 XR |
39 | /** |
40 | * Id used to retrieve the header (as a String) of the trace to export. | |
41 | * This header is from the application context of this handler. | |
42 | */ | |
53bae902 | 43 | public static final String TMF_EVENT_TABLE_COLUMNS_ID = "org.eclipse.linuxtools.tmf.ui.exportToText.columns"; //$NON-NLS-1$ |
d3de0920 XR |
44 | |
45 | /** | |
46 | * Constructor | |
47 | */ | |
48 | public ExportToTextCommandHandler() { | |
49 | } | |
50 | ||
51 | @Override | |
52 | public Object execute(ExecutionEvent event) throws ExecutionException { | |
53bae902 | 53 | List<TmfEventTableColumn> columns = getColumns(event.getApplicationContext()); |
d3de0920 | 54 | ITmfTrace trace = TmfTraceManager.getInstance().getActiveTrace(); |
21852dfa | 55 | ITmfFilter filter = TmfTraceManager.getInstance().getCurrentTraceContext().getFilter(); |
d3de0920 XR |
56 | if (trace != null) { |
57 | FileDialog fd = new FileDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.SAVE); | |
58 | fd.setFilterExtensions(new String[] { "*.csv", "*.*", "*" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
59 | fd.setOverwrite(true); | |
60 | final String s = fd.open(); | |
61 | if (s != null) { | |
53bae902 | 62 | Job j = new ExportToTextJob(trace, filter, columns, s); |
d3de0920 XR |
63 | j.setUser(true); |
64 | j.schedule(); | |
65 | } | |
66 | } | |
67 | return null; | |
68 | } | |
69 | ||
53bae902 BH |
70 | @SuppressWarnings("unchecked") |
71 | private static List<TmfEventTableColumn> getColumns(Object evaluationContext) { | |
d3de0920 | 72 | if (evaluationContext instanceof IEvaluationContext) { |
53bae902 BH |
73 | Object s = ((IEvaluationContext) evaluationContext).getVariable(TMF_EVENT_TABLE_COLUMNS_ID); |
74 | if (s instanceof List<?>) { | |
75 | return (List<TmfEventTableColumn>) s; | |
d3de0920 XR |
76 | } |
77 | } | |
78 | return null; | |
79 | } | |
80 | ||
81 | } |