1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 Kalray, Ericsson
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
10 * Xavier Raynaud - Initial API and implementation
11 * Bernd Hufmann - Adapted to new events table column API
12 *******************************************************************************/
14 package org
.eclipse
.tracecompass
.internal
.tmf
.ui
.commands
;
16 import java
.util
.List
;
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
;
23 import org
.eclipse
.swt
.SWT
;
24 import org
.eclipse
.swt
.widgets
.FileDialog
;
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
;
29 import org
.eclipse
.ui
.PlatformUI
;
32 * This handler exports traces to text files.
33 * @author Xavier Raynaud <xavier.raynaud@kalray.eu>
35 public class ExportToTextCommandHandler
extends AbstractHandler
{
37 /** Id of the export-to-text command */
38 public static final String COMMAND_ID
= "org.eclipse.linuxtools.tmf.ui.exportToText"; //$NON-NLS-1$
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.
43 public static final String TMF_EVENT_TABLE_COLUMNS_ID
= "org.eclipse.linuxtools.tmf.ui.exportToText.columns"; //$NON-NLS-1$
48 public ExportToTextCommandHandler() {
52 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
53 List
<TmfEventTableColumn
> columns
= getColumns(event
.getApplicationContext());
54 ITmfTrace trace
= TmfTraceManager
.getInstance().getActiveTrace();
55 ITmfFilter filter
= TmfTraceManager
.getInstance().getCurrentTraceContext().getFilter();
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();
62 Job j
= new ExportToTextJob(trace
, filter
, columns
, s
);
70 @SuppressWarnings("unchecked")
71 private static List
<TmfEventTableColumn
> getColumns(Object evaluationContext
) {
72 if (evaluationContext
instanceof IEvaluationContext
) {
73 Object s
= ((IEvaluationContext
) evaluationContext
).getVariable(TMF_EVENT_TABLE_COLUMNS_ID
);
74 if (s
instanceof List
<?
>) {
75 return (List
<TmfEventTableColumn
>) s
;