tmf: Handle 'null' active pages in views
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Tue, 20 Nov 2012 18:05:28 +0000 (13:05 -0500)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Tue, 20 Nov 2012 18:21:42 +0000 (13:21 -0500)
There is a possible race condition when launching the program,
between the platform's window and the views' active page.

Use getSite() in views where possible instead of PlatformUI, and
add null checks where this is not possible.

Change-Id: I2f94a9eb44817ac9ea906ac93efcf6863511a6d8
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/8772
Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com>
IP-Clean: Patrick Tasse <patrick.tasse@gmail.com>

org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/controlflow/ControlFlowView.java
org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/resources/ResourcesView.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfProjectElement.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/environment/TmfEnvironmentView.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramView.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/statistics/TmfStatisticsView.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/uml2sd/loader/TmfUml2SDSyncLoader.java

index 6e8534a4d80e87bb27bb4f42642412538ff637e3..e1b8c25a056ddf22b6e0fbee153e794c4fa9de4e 100644 (file)
@@ -70,7 +70,6 @@ import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.TreeColumn;
 import org.eclipse.ui.IActionBars;
 import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.PlatformUI;
 
 /**
  * The Control Flow view main object
@@ -410,7 +409,7 @@ public class ControlFlowView extends TmfView {
         makeActions();
         contributeToActionBars();
 
-        IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
+        IEditorPart editor = getSite().getPage().getActiveEditor();
         if (editor instanceof ITmfTraceEditor) {
             ITmfTrace trace = ((ITmfTraceEditor) editor).getTrace();
             if (trace != null) {
index 0ed49350a8fdf3a1bf8dadb22dba866261cd16d5..ac6fd5932dd14b489dfa90daa482287a36788b84 100644 (file)
@@ -60,7 +60,6 @@ import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.ui.IActionBars;
 import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.PlatformUI;
 
 /**
  * Main implementation for the LTTng 2.0 kernel Resource view
@@ -349,7 +348,7 @@ public class ResourcesView extends TmfView {
         makeActions();
         contributeToActionBars();
 
-        IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
+        IEditorPart editor = getSite().getPage().getActiveEditor();
         if (editor instanceof ITmfTraceEditor) {
             ITmfTrace trace = ((ITmfTraceEditor) editor).getTrace();
             if (trace != null) {
index 652fab786e81e611a47db6854e751f710f0502e1..3410b80de70bf043458f0c6f0eafa8d2847aac70 100644 (file)
@@ -1,11 +1,11 @@
 /*******************************************************************************
  * Copyright (c) 2011, 2012 Ericsson
- * 
+ *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
  * accompanies this distribution, and is available at
  * http://www.eclipse.org/legal/epl-v10.html
- * 
+ *
  * Contributors:
  *   Francois Chouinard - Initial API and implementation
  *******************************************************************************/
@@ -25,8 +25,8 @@ import org.eclipse.ui.navigator.CommonNavigator;
 import org.eclipse.ui.navigator.CommonViewer;
 
 /**
- * The implementation of TMF project model element. 
- * 
+ * The implementation of TMF project model element.
+ *
  * @version 1.0
  * @author Francois Chouinard
  */
@@ -44,8 +44,8 @@ public class TmfProjectElement extends TmfProjectModelElement {
     // ------------------------------------------------------------------------
     /**
      * Constructor.
-     * 
-     * Creates the TMF project model element. 
+     *
+     * Creates the TMF project model element.
      * @param name The name of the project.
      * @param project The project reference.
      * @param parent The parent element
@@ -88,7 +88,7 @@ public class TmfProjectElement extends TmfProjectModelElement {
     // Accessors
     // ------------------------------------------------------------------------
     /**
-     * Returns the containing trace folder element. 
+     * Returns the containing trace folder element.
      * @return the TMF trace folder element.
      */
     public TmfTraceFolder getTracesFolder() {
@@ -122,6 +122,10 @@ public class TmfProjectElement extends TmfProjectModelElement {
                     return;
                 }
                 IWorkbenchPage activePage = wbWindow.getActivePage();
+                if (activePage == null) {
+                    return;
+                }
+
                 for (IViewReference viewReference : activePage.getViewReferences()) {
                     IViewPart viewPart = viewReference.getView(false);
                     if (viewPart instanceof CommonNavigator) {
index d392756dbcb348f03223f743150ba42c2b522718..921662ddfd84088f13ab4a03a61ce9f79aae413b 100644 (file)
@@ -27,7 +27,6 @@ import org.eclipse.swt.widgets.Table;
 import org.eclipse.swt.widgets.TableColumn;
 import org.eclipse.swt.widgets.TableItem;
 import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.PlatformUI;
 
 /**
  * Displays the CTF trace properties.
@@ -77,7 +76,7 @@ public class TmfEnvironmentView extends TmfView {
         nameCol.pack();
         valueCol.pack();
 
-        IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
+        IEditorPart editor = getSite().getPage().getActiveEditor();
         if (editor instanceof ITmfTraceEditor) {
             ITmfTrace trace = ((ITmfTraceEditor) editor).getTrace();
             if (trace != null) {
index 0e54bad32ef78a3a1b4abf386d2552240e1621db..f0cf9f98a40937cc1d8f1d64b6060bce6b7c2f0e 100644 (file)
@@ -40,7 +40,6 @@ import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.PlatformUI;
 
 /**
  * The purpose of this view is to provide graphical time distribution statistics about the trace events.
@@ -247,7 +246,7 @@ public class HistogramView extends TmfView {
         // Histogram
         fFullTraceHistogram = new FullTraceHistogram(this, fullRangeComposite);
 
-        IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
+        IEditorPart editor = getSite().getPage().getActiveEditor();
         if (editor instanceof ITmfTraceEditor) {
             ITmfTrace trace = ((ITmfTraceEditor) editor).getTrace();
             if (trace != null) {
index b9420dc180c41bd566e3b175ba0ae83625b3645a..122bdac1edc5f1cdff78726f74b4dc64444a0299 100755 (executable)
@@ -37,7 +37,6 @@ import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.PlatformUI;
 
 /**
  * The generic Statistics View displays statistics for any kind of traces.
@@ -107,7 +106,7 @@ public class TmfStatisticsView extends TmfView {
         fStatsViewers.setParent(parent);
         createStatisticsViewers();
 
-        IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
+        IEditorPart editor = getSite().getPage().getActiveEditor();
         if (editor instanceof ITmfTraceEditor) {
             ITmfTrace trace = ((ITmfTraceEditor) editor).getTrace();
             if (trace != null) {
index 85c32be609ca9815c3d34df437db8581a9d60f5b..ca3dd3a55e6c25d6f1e52d6bcef393b2e883f093 100644 (file)
@@ -499,7 +499,7 @@ public class TmfUml2SDSyncLoader extends TmfComponent implements IUml2SDLoader,
 
             resetLoader();
 
-            IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
+            IEditorPart editor = fView.getSite().getPage().getActiveEditor();
             if (editor instanceof ITmfTraceEditor) {
                 ITmfTrace trace = ((ITmfTraceEditor) editor).getTrace();
                 if (trace != null) {
This page took 0.032517 seconds and 5 git commands to generate.