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; | |
674c702f | 28 | import org.eclipse.tracecompass.tmf.ui.dialog.TmfFileDialogFactory; |
2bdf0193 | 29 | import org.eclipse.tracecompass.tmf.ui.viewers.events.columns.TmfEventTableColumn; |
d3de0920 XR |
30 | import org.eclipse.ui.PlatformUI; |
31 | ||
32 | /** | |
33 | * This handler exports traces to text files. | |
34 | * @author Xavier Raynaud <xavier.raynaud@kalray.eu> | |
35 | */ | |
36 | public class ExportToTextCommandHandler extends AbstractHandler { | |
37 | ||
38 | /** Id of the export-to-text command */ | |
39 | public static final String COMMAND_ID = "org.eclipse.linuxtools.tmf.ui.exportToText"; //$NON-NLS-1$ | |
d3de0920 XR |
40 | /** |
41 | * Id used to retrieve the header (as a String) of the trace to export. | |
42 | * This header is from the application context of this handler. | |
43 | */ | |
53bae902 | 44 | public static final String TMF_EVENT_TABLE_COLUMNS_ID = "org.eclipse.linuxtools.tmf.ui.exportToText.columns"; //$NON-NLS-1$ |
d3de0920 XR |
45 | |
46 | /** | |
47 | * Constructor | |
48 | */ | |
49 | public ExportToTextCommandHandler() { | |
50 | } | |
51 | ||
52 | @Override | |
53 | public Object execute(ExecutionEvent event) throws ExecutionException { | |
53bae902 | 54 | List<TmfEventTableColumn> columns = getColumns(event.getApplicationContext()); |
d3de0920 | 55 | ITmfTrace trace = TmfTraceManager.getInstance().getActiveTrace(); |
21852dfa | 56 | ITmfFilter filter = TmfTraceManager.getInstance().getCurrentTraceContext().getFilter(); |
d3de0920 | 57 | if (trace != null) { |
674c702f | 58 | FileDialog fd = TmfFileDialogFactory.create(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.SAVE); |
d3de0920 XR |
59 | fd.setFilterExtensions(new String[] { "*.csv", "*.*", "*" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
60 | fd.setOverwrite(true); | |
61 | final String s = fd.open(); | |
62 | if (s != null) { | |
53bae902 | 63 | Job j = new ExportToTextJob(trace, filter, columns, s); |
d3de0920 XR |
64 | j.setUser(true); |
65 | j.schedule(); | |
66 | } | |
67 | } | |
68 | return null; | |
69 | } | |
70 | ||
53bae902 BH |
71 | @SuppressWarnings("unchecked") |
72 | private static List<TmfEventTableColumn> getColumns(Object evaluationContext) { | |
d3de0920 | 73 | if (evaluationContext instanceof IEvaluationContext) { |
53bae902 BH |
74 | Object s = ((IEvaluationContext) evaluationContext).getVariable(TMF_EVENT_TABLE_COLUMNS_ID); |
75 | if (s instanceof List<?>) { | |
76 | return (List<TmfEventTableColumn>) s; | |
d3de0920 XR |
77 | } |
78 | } | |
79 | return null; | |
80 | } | |
81 | ||
82 | } |