tmf: Adapted ExportToText feature to new events table column API
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / internal / tmf / ui / commands / ExportToTextCommandHandler.java
index a63d81900bf1e4e00a293e317167e7d3ec330380..f8f4a8230054fac8e0907ac1ee31dae59e85d701 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2013 Kalray
+ * Copyright (c) 2013, 2014 Kalray, Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -8,10 +8,13 @@
  *
  * Contributors:
  *   Xavier Raynaud - Initial API and implementation
+ *   Bernd Hufmann - Adapted to new events table column API
  *******************************************************************************/
 
 package org.eclipse.linuxtools.internal.tmf.ui.commands;
 
+import java.util.List;
+
 import org.eclipse.core.commands.AbstractHandler;
 import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
@@ -20,7 +23,7 @@ import org.eclipse.core.runtime.jobs.Job;
 import org.eclipse.linuxtools.tmf.core.filter.ITmfFilter;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
 import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager;
-import org.eclipse.linuxtools.tmf.ui.viewers.events.TmfEventsTable;
+import org.eclipse.linuxtools.tmf.ui.viewers.events.columns.TmfEventTableColumn;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.FileDialog;
 import org.eclipse.ui.PlatformUI;
@@ -33,16 +36,11 @@ public class ExportToTextCommandHandler extends AbstractHandler {
 
     /** Id of the export-to-text command */
     public static final String COMMAND_ID = "org.eclipse.linuxtools.tmf.ui.exportToText"; //$NON-NLS-1$
-    /**
-     * Id used to retrieve the TmfEventsTable that launched this command.
-     * This TmfEventsTable is taken from the application context of this handler.
-     */
-    public static final String TMF_EVENT_TABLE_PARAMETER_ID = "org.eclipse.linuxtools.tmf.ui.exportToText.table"; //$NON-NLS-1$
     /**
      * Id used to retrieve the header (as a String) of the trace to export.
      * This header is from the application context of this handler.
      */
-    public static final String TMF_EVENT_TABLE_HEADER_ID = "org.eclipse.linuxtools.tmf.ui.exportToText.header"; //$NON-NLS-1$
+    public static final String TMF_EVENT_TABLE_COLUMNS_ID = "org.eclipse.linuxtools.tmf.ui.exportToText.columns"; //$NON-NLS-1$
 
     /**
      * Constructor
@@ -52,8 +50,7 @@ public class ExportToTextCommandHandler extends AbstractHandler {
 
     @Override
     public Object execute(ExecutionEvent event) throws ExecutionException {
-        String header = getHeader(event.getApplicationContext());
-        TmfEventsTable table = getTable(event.getApplicationContext());
+        List<TmfEventTableColumn> columns = getColumns(event.getApplicationContext());
         ITmfTrace trace = TmfTraceManager.getInstance().getActiveTrace();
         ITmfFilter filter = TmfTraceManager.getInstance().getCurrentFilter();
         if (trace != null) {
@@ -62,7 +59,7 @@ public class ExportToTextCommandHandler extends AbstractHandler {
             fd.setOverwrite(true);
             final String s = fd.open();
             if (s != null) {
-                Job j = new ExportToTextJob(trace, filter, table, header, s);
+                Job j = new ExportToTextJob(trace, filter, columns, s);
                 j.setUser(true);
                 j.schedule();
             }
@@ -70,21 +67,12 @@ public class ExportToTextCommandHandler extends AbstractHandler {
         return null;
     }
 
-    private static String getHeader(Object evaluationContext) {
-        if (evaluationContext instanceof IEvaluationContext) {
-            Object s = ((IEvaluationContext) evaluationContext).getVariable(TMF_EVENT_TABLE_HEADER_ID);
-            if (s instanceof String) {
-                return s.toString();
-            }
-        }
-        return null;
-    }
-
-    private static TmfEventsTable getTable(Object evaluationContext) {
+    @SuppressWarnings("unchecked")
+    private static List<TmfEventTableColumn> getColumns(Object evaluationContext) {
         if (evaluationContext instanceof IEvaluationContext) {
-            Object o = ((IEvaluationContext) evaluationContext).getVariable(TMF_EVENT_TABLE_PARAMETER_ID);
-            if (o instanceof TmfEventsTable) {
-                return (TmfEventsTable) o;
+            Object s = ((IEvaluationContext) evaluationContext).getVariable(TMF_EVENT_TABLE_COLUMNS_ID);
+            if (s instanceof List<?>) {
+                return (List<TmfEventTableColumn>) s;
             }
         }
         return null;
This page took 0.025101 seconds and 5 git commands to generate.