tmf: Refactor bookmarks file handling
authorPatrick Tasse <patrick.tasse@gmail.com>
Wed, 2 Apr 2014 20:58:54 +0000 (16:58 -0400)
committerPatrick Tasse <patrick.tasse@gmail.com>
Tue, 8 Apr 2014 17:00:56 +0000 (13:00 -0400)
The interfaces used to set or get the bookmarks file from an editor or
experiment are removed as they are not necessary. The bookmarks file is
the file in the FileEditorInput of an opened trace editor.

A convenience method is added in the trace manager to get the editor
file for an opened trace.

Change-Id: Ia4bd1999a4015b0251f867d46d0bd2d732a8c4bd
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/24355
Tested-by: Hudson CI
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfExperimentTest.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/signal/TmfTraceOpenedSignal.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfExperiment.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTraceContext.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTraceManager.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/editors/ITmfTraceEditor.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/editors/TmfEventsEditor.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfOpenTraceHelper.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/timechart/TimeChartView.java

index 9083a430f61cdbcea93c6dbaaecd96578cc5c9f2..a8635e65922aff5b36cb711294487bb72c915668 100644 (file)
@@ -27,7 +27,6 @@ import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.Vector;
 
-import org.eclipse.core.resources.IFile;
 import org.eclipse.core.runtime.FileLocator;
 import org.eclipse.core.runtime.Path;
 import org.eclipse.linuxtools.internal.tmf.core.trace.TmfExperimentContext;
@@ -188,18 +187,6 @@ public class TmfExperimentTest {
         assertNull("getTimestamp", fExperiment.getTimestamp(10000));
     }
 
-    // ------------------------------------------------------------------------
-    // Bookmarks file handling
-    // ------------------------------------------------------------------------
-
-    @Test
-    public void testBookmarks() {
-        assertNull("GetBookmarksFile", fExperiment.getBookmarksFile());
-        IFile bookmarks = (IFile) fTestTraces[0].getResource();
-        fExperiment.setBookmarksFile(bookmarks);
-        assertEquals("GetBookmarksFile", bookmarks, fExperiment.getBookmarksFile());
-    }
-
     // ------------------------------------------------------------------------
     // State system, statistics and modules methods
     // ------------------------------------------------------------------------
index 0f08eec84cc654a08aa868851cfc13eaac373514..962b9af6b95bc6c983b4331d507ffe102de438d4 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2012 Ericsson
+ * Copyright (c) 2012, 2014 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -28,7 +28,7 @@ import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
 public class TmfTraceOpenedSignal extends TmfSignal {
 
     private final ITmfTrace fTrace;
-    private final IFile fBookmarksFile;
+    private final IFile fEditorFile;
 
     /**
      * Constructor for a new signal.
@@ -37,13 +37,13 @@ public class TmfTraceOpenedSignal extends TmfSignal {
      *            The object sending this signal
      * @param trace
      *            The trace that has been opened
-     * @param bookmarksFile
-     *            Pointer to the bookmark file
+     * @param editorFile
+     *            Pointer to the editor file
      */
-    public TmfTraceOpenedSignal(Object source, ITmfTrace trace, IFile bookmarksFile) {
+    public TmfTraceOpenedSignal(Object source, ITmfTrace trace, IFile editorFile) {
         super(source);
         fTrace = trace;
-        fBookmarksFile = bookmarksFile;
+        fEditorFile = editorFile;
     }
 
     /**
@@ -56,12 +56,13 @@ public class TmfTraceOpenedSignal extends TmfSignal {
     }
 
     /**
-     * Get a pointer to the bookmark file of this trace
+     * Get a pointer to the editor file for this trace
      *
      * @return The IFile object
+     * @since 3.0
      */
-    public IFile getBookmarksFile() {
-        return fBookmarksFile;
+    public IFile getEditorFile() {
+        return fEditorFile;
     }
 
     @Override
index 1e75cfe154e5d37fa55c8eee35278e5231a47f7b..b30c124a729dc55923d81dd10f43bdf162197f20 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2009, 2013 Ericsson, École Polytechnique de Montréal
+ * Copyright (c) 2009, 2014 Ericsson, École Polytechnique de Montréal
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -21,7 +21,6 @@ import java.io.File;
 import java.nio.ByteBuffer;
 import java.util.Arrays;
 
-import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.runtime.CoreException;
@@ -89,11 +88,6 @@ public class TmfExperiment extends TmfTrace implements ITmfEventParser, ITmfPers
      */
     private boolean fInitialized = false;
 
-    /**
-     * The experiment bookmarks file
-     */
-    private IFile fBookmarksFile;
-
     // ------------------------------------------------------------------------
     // Construction
     // ------------------------------------------------------------------------
@@ -279,25 +273,6 @@ public class TmfExperiment extends TmfTrace implements ITmfEventParser, ITmfPers
         return (event != null) ? event.getTimestamp() : null;
     }
 
-    /**
-     * Set the file to be used for bookmarks on this experiment
-     *
-     * @param file
-     *            the bookmarks file
-     */
-    public void setBookmarksFile(final IFile file) {
-        fBookmarksFile = file;
-    }
-
-    /**
-     * Get the file used for bookmarks on this experiment
-     *
-     * @return the bookmarks file or null if none is set
-     */
-    public IFile getBookmarksFile() {
-        return fBookmarksFile;
-    }
-
     // ------------------------------------------------------------------------
     // Request management
     // ------------------------------------------------------------------------
index 58f99b0abc482c0393c6f126b41084c43bc2e1be..b2a3e689f21b9256d0c1371c292d8f44bdd99748 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2013 Ericsson
+ * Copyright (c) 2013, 2014 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -14,6 +14,7 @@
 
 package org.eclipse.linuxtools.tmf.core.trace;
 
+import org.eclipse.core.resources.IFile;
 import org.eclipse.linuxtools.tmf.core.filter.ITmfFilter;
 import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
@@ -31,27 +32,31 @@ import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
 final class TmfTraceContext {
 
     static final TmfTraceContext NULL_CONTEXT =
-            new TmfTraceContext(TmfTimestamp.BIG_CRUNCH, TmfTimestamp.BIG_CRUNCH, TmfTimeRange.NULL_RANGE);
+            new TmfTraceContext(TmfTimestamp.BIG_CRUNCH, TmfTimestamp.BIG_CRUNCH, TmfTimeRange.NULL_RANGE, null);
 
     private final TmfTimeRange fSelection;
     private final TmfTimeRange fWindowRange;
+    private final IFile fEditorFile;
     private final ITmfFilter fFilter;
 
-    public TmfTraceContext(ITmfTimestamp beginTs, ITmfTimestamp endTs, TmfTimeRange tr) {
+    public TmfTraceContext(ITmfTimestamp beginTs, ITmfTimestamp endTs, TmfTimeRange tr, IFile editorFile) {
         fSelection = new TmfTimeRange(beginTs, endTs);
         fWindowRange = tr;
+        fEditorFile = editorFile;
         fFilter = null;
     }
 
     public TmfTraceContext(TmfTraceContext prevCtx, ITmfTimestamp beginTs, ITmfTimestamp endTs) {
         fSelection = new TmfTimeRange(beginTs, endTs);
         fWindowRange = prevCtx.fWindowRange;
+        fEditorFile = prevCtx.fEditorFile;
         fFilter = prevCtx.fFilter;
     }
 
     public TmfTraceContext(TmfTraceContext prevCtx, TmfTimeRange tr) {
         fSelection = prevCtx.fSelection;
         fWindowRange = tr;
+        fEditorFile = prevCtx.fEditorFile;
         fFilter = prevCtx.fFilter;
     }
 
@@ -65,6 +70,7 @@ final class TmfTraceContext {
     public TmfTraceContext(TmfTraceContext prevCtx, ITmfFilter filter) {
         fSelection = prevCtx.fSelection;
         fWindowRange = prevCtx.fWindowRange;
+        fEditorFile = prevCtx.fEditorFile;
         fFilter = filter;
     }
 
@@ -80,6 +86,10 @@ final class TmfTraceContext {
         return fWindowRange;
     }
 
+    public IFile getEditorFile() {
+        return fEditorFile;
+    }
+
     /**
      * @return the current filter applied to the trace
      * @since 2.2
index 412ebc93e6ca0d05ed51fde646ef4631a053b459..89e81ca45cfe61fe1dbc4d4190bd8f9ec06fd5fa 100644 (file)
@@ -20,6 +20,7 @@ import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.Set;
 
+import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.linuxtools.tmf.core.TmfCommonConstants;
@@ -152,6 +153,22 @@ public final class TmfTraceManager {
         return Collections.unmodifiableSet(fTraces.keySet());
     }
 
+    /**
+     * Get the editor file for an opened trace.
+     *
+     * @param trace
+     *            the trace
+     * @return the editor file or null if the trace is not opened
+     * @since 3.0
+     */
+    public synchronized IFile getTraceEditorFile(ITmfTrace trace) {
+        TmfTraceContext ctx = fTraces.get(trace);
+        if (ctx != null) {
+            return ctx.getEditorFile();
+        }
+        return null;
+    }
+
     private TmfTraceContext getCurrentTraceContext() {
         TmfTraceContext curCtx = fTraces.get(fCurrentTrace);
         if (curCtx == null) {
@@ -224,6 +241,7 @@ public final class TmfTraceManager {
     @TmfSignalHandler
     public synchronized void traceOpened(final TmfTraceOpenedSignal signal) {
         final ITmfTrace trace = signal.getTrace();
+        final IFile editorFile = signal.getEditorFile();
         final ITmfTimestamp startTs = trace.getStartTime();
 
         /* Calculate the initial time range */
@@ -232,7 +250,7 @@ public final class TmfTraceManager {
         long endTime = startTs.normalize(0, SCALE).getValue() + offset;
         final TmfTimeRange startTr = new TmfTimeRange(startTs, new TmfTimestamp(endTime, SCALE));
 
-        final TmfTraceContext startCtx = new TmfTraceContext(startTs, startTs, startTr);
+        final TmfTraceContext startCtx = new TmfTraceContext(startTs, startTs, startTr, editorFile);
 
         fTraces.put(trace, startCtx);
 
index 7a9f402104475da9b19265d9df0ecfe55d1318c7..a8c5726eb551e3c4c09150c5992f4c766845fa66 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2013 Ericsson
+ * Copyright (c) 2010, 2014 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -12,7 +12,6 @@
 
 package org.eclipse.linuxtools.tmf.ui.editors;
 
-import org.eclipse.core.resources.IFile;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
 
 /**
@@ -29,11 +28,4 @@ public interface ITmfTraceEditor {
      * @return The trace
      */
     ITmfTrace getTrace();
-
-    /**
-     * Get the bookmark file associated to this trace
-     *
-     * @return The IFile object pointing to the bookmark file
-     */
-    IFile getBookmarksFile();
 }
index 296ea20c96143e67ea16eafd274b7cb4337e298b..d993fa50ff9b3aee848ff82983d5d70143eb4d47 100644 (file)
@@ -450,11 +450,6 @@ public class TmfEventsEditor extends TmfEditor implements ITmfTraceEditor, IReus
         return fTrace;
     }
 
-    @Override
-    public IFile getBookmarksFile() {
-        return fFile;
-    }
-
     @Override
     public void setFocus() {
         fEventsTable.setFocus();
index b08fa2d7c59552993777baca4e55fbccc85f90ec..2c66cd80bf0875d0e373fe912b5a65326b507d02 100644 (file)
@@ -234,7 +234,7 @@ public class TmfOpenTraceHelper {
         return trace;
     }
 
-    private static ITmfTrace openExperimentElement(final TmfExperimentElement experimentElement, IFile bookmarkFile) {
+    private static ITmfTrace openExperimentElement(final TmfExperimentElement experimentElement) {
         /* Experiment element now has an experiment type associated with it */
         final TmfExperiment experiment = experimentElement.instantiateTrace();
         if (experiment == null) {
@@ -269,17 +269,16 @@ public class TmfOpenTraceHelper {
 
         // Create the experiment
         experiment.initExperiment(ITmfEvent.class, experimentElement.getName(), traces, cacheSize, experimentElement.getResource());
-        experiment.setBookmarksFile(bookmarkFile);
 
         return experiment;
     }
 
-    private static ITmfTrace openProjectElement(final TmfCommonProjectElement element, IFile bookmarkFile) {
+    private static ITmfTrace openProjectElement(final TmfCommonProjectElement element) {
         ITmfTrace trace = null;
         if (element instanceof TmfTraceElement) {
             trace = openTraceElement((TmfTraceElement) element);
         } else if (element instanceof TmfExperimentElement) {
-            trace = openExperimentElement((TmfExperimentElement) element, bookmarkFile);
+            trace = openExperimentElement((TmfExperimentElement) element);
         }
         return trace;
     }
@@ -316,7 +315,7 @@ public class TmfOpenTraceHelper {
             @Override
             public void run() {
 
-                final ITmfTrace trace = openProjectElement(traceElement, file);
+                final ITmfTrace trace = openProjectElement(traceElement);
                 if (trace == null) {
                     return;
                 }
@@ -398,7 +397,7 @@ public class TmfOpenTraceHelper {
             @Override
             public void run() {
 
-                final ITmfTrace trace = openProjectElement(traceElement, file);
+                final ITmfTrace trace = openProjectElement(traceElement);
                 if (trace == null) {
                     return;
                 }
index 0d9edf98911a15e514870292b26cf8025eb5abb7..46a41d88225800b33681b8ca433cda776ded0451 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2013 Ericsson
+ * Copyright (c) 2010, 2014 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -40,7 +40,7 @@ import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
-import org.eclipse.linuxtools.tmf.ui.editors.ITmfTraceEditor;
+import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager;
 import org.eclipse.linuxtools.tmf.ui.views.TmfView;
 import org.eclipse.linuxtools.tmf.ui.views.colors.ColorSetting;
 import org.eclipse.linuxtools.tmf.ui.views.colors.ColorSettingsManager;
@@ -60,8 +60,6 @@ import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.TimeFormat;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IEditorReference;
 
 /**
  * Generic Time Chart view, which is similar to a Gantt chart for trace analysis
@@ -112,20 +110,13 @@ public class TimeChartView extends TmfView implements ITimeGraphRangeListener, I
         IStatusLineManager statusLineManager = getViewSite().getActionBars().getStatusLineManager();
         fViewer.getTimeGraphControl().setStatusLineManager(statusLineManager);
 
-        IEditorReference[] editorReferences = getSite().getPage().getEditorReferences();
-        for (IEditorReference editorReference : editorReferences) {
-            IEditorPart editor = editorReference.getEditor(false);
-            if (editor instanceof ITmfTraceEditor) {
-                ITmfTrace trace = ((ITmfTraceEditor) editor).getTrace();
-                if (trace != null) {
-                    IFile bookmarksFile = ((ITmfTraceEditor) editor).getBookmarksFile();
-                    TimeChartAnalysisEntry timeAnalysisEntry = new TimeChartAnalysisEntry(trace, fDisplayWidth * 2);
-                    fTimeAnalysisEntries.add(timeAnalysisEntry);
-                    fDecorationProviders.put(trace, new TimeChartDecorationProvider(bookmarksFile));
-                    Thread thread = new ProcessTraceThread(timeAnalysisEntry);
-                    thread.start();
-                }
-            }
+        for (ITmfTrace trace : TmfTraceManager.getInstance().getOpenedTraces()) {
+            IFile bookmarksFile = TmfTraceManager.getInstance().getTraceEditorFile(trace);
+            TimeChartAnalysisEntry timeAnalysisEntry = new TimeChartAnalysisEntry(trace, fDisplayWidth * 2);
+            fTimeAnalysisEntries.add(timeAnalysisEntry);
+            fDecorationProviders.put(trace, new TimeChartDecorationProvider(bookmarksFile));
+            Thread thread = new ProcessTraceThread(timeAnalysisEntry);
+            thread.start();
         }
         fViewer.setInput(fTimeAnalysisEntries.toArray(new TimeChartAnalysisEntry[0]));
 
@@ -587,7 +578,7 @@ public class TimeChartView extends TmfView implements ITimeGraphRangeListener, I
     @TmfSignalHandler
     public void traceOpened(TmfTraceOpenedSignal signal) {
         final ITmfTrace trace = signal.getTrace();
-        final IFile bookmarksFile = signal.getBookmarksFile();
+        final IFile bookmarksFile = signal.getEditorFile();
         TimeChartAnalysisEntry timeAnalysisEntry = null;
         for (int i = 0; i < fTimeAnalysisEntries.size(); i++) {
             if (fTimeAnalysisEntries.get(i).getTrace().equals(trace)) {
This page took 0.034934 seconds and 5 git commands to generate.