Fix NullPointerException in command handlers
authorPatrick Tasse <patrick.tasse@gmail.com>
Wed, 9 Jan 2013 21:19:27 +0000 (16:19 -0500)
committerPatrick Tasse <patrick.tasse@gmail.com>
Thu, 10 Jan 2013 18:16:41 +0000 (13:16 -0500)
The active part can be null if all perspectives are closed. The handlers
isEnabled() method can then be invoked when using the workbench main
menu (e.g. File > Exit).

Change-Id: I76df9320238ef5e02aa0ee56a4b12dbb494cfe79
Reviewed-on: https://git.eclipse.org/r/9570
Tested-by: Hudson CI
Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
IP-Clean: Alexandre Montplaisir <alexmonthy@voxpopuli.im>

15 files changed:
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/CopyExperimentHandler.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/CopyTraceHandler.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DeleteExperimentHandler.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DeleteExperimentSupplementaryFilesHandler.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DeleteTraceHandler.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DeleteTraceSupplementaryFilesHandler.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/ImportTraceHandler.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/NewExperimentHandler.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/OpenExperimentHandler.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/OpenTraceHandler.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/RefreshHandler.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/RenameExperimentHandler.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/RenameTraceHandler.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/SelectTraceTypeHandler.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/SelectTracesHandler.java

index c1a0cdf259f1c0205469a408a9482954dd05e038..a9761986ceba752cc6fba88a7b84a9801fe90951 100644 (file)
@@ -1,11 +1,11 @@
 /*******************************************************************************
  * Copyright (c) 2009, 2010, 2011 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
  *******************************************************************************/
@@ -44,12 +44,16 @@ public class CopyExperimentHandler extends AbstractHandler {
 
         // Check if we are closing down
         IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
-        if (window == null)
+        if (window == null) {
             return false;
+        }
 
         // Get the selection
         IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
         IWorkbenchPart part = page.getActivePart();
+        if (part == null) {
+            return false;
+        }
         ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
         if (selectionProvider == null)
             return false;
index 3b834bfceffd32c5c5279606678df2a23d761be8..22bc49c41021ae6ccb5160e2c2b950db69919bd3 100644 (file)
@@ -1,11 +1,11 @@
 /*******************************************************************************
  * Copyright (c) 2011 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
  *******************************************************************************/
@@ -44,15 +44,20 @@ public class CopyTraceHandler extends AbstractHandler {
 
         // Check if we are closing down
         IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
-        if (window == null)
+        if (window == null) {
             return false;
+        }
 
         // Get the selection
         IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
         IWorkbenchPart part = page.getActivePart();
+        if (part == null) {
+            return false;
+        }
         ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
-        if (selectionProvider == null)
+        if (selectionProvider == null) {
             return false;
+        }
         ISelection selection = selectionProvider.getSelection();
 
         // Make sure a trace is selected
@@ -79,8 +84,9 @@ public class CopyTraceHandler extends AbstractHandler {
 
         // Check if we are closing down
         IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
-        if (window == null)
+        if (window == null) {
             return null;
+        }
 
         // Fire the Copy Experiment dialog
         Shell shell = window.getShell();
index 3dc939f479e0cd95f4e8f49fb694c9605dbbec22..959d00ca078c0898333126681900fe7a7ac432f8 100644 (file)
@@ -67,6 +67,9 @@ public class DeleteExperimentHandler extends AbstractHandler {
         // Get the selection
         IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
         IWorkbenchPart part = page.getActivePart();
+        if (part == null) {
+            return false;
+        }
         ISelection selection = part.getSite().getSelectionProvider().getSelection();
 
         if (selection instanceof TreeSelection) {
index 906ce4ba9da233b3654320f2353745d7e78f722a..e11fb31466d4a64dc74351ed8ad10c798bb9610f 100644 (file)
@@ -58,6 +58,9 @@ public class DeleteExperimentSupplementaryFilesHandler extends AbstractHandler {
         // Get the selection
         IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
         IWorkbenchPart part = page.getActivePart();
+        if (part == null) {
+            return false;
+        }
         ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
         if (selectionProvider == null) {
             return false;
index efc979929b0d549659727da179c74e7ddca6aeda..04f5b4aaaa6c279d185dc46cdb94e094ac1ba768 100644 (file)
@@ -69,6 +69,9 @@ public class DeleteTraceHandler extends AbstractHandler {
         // Get the selection
         IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
         IWorkbenchPart part = page.getActivePart();
+        if (part == null) {
+            return false;
+        }
         ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
         if (selectionProvider == null) {
             return false;
index 89bc5da5e7b5318b40d110a3d22667e878271d9c..89ddb01a42b10a4dbc921a024d5fa423a3e1b519 100644 (file)
@@ -52,6 +52,9 @@ public class DeleteTraceSupplementaryFilesHandler extends AbstractHandler {
         // Get the selection
         IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
         IWorkbenchPart part = page.getActivePart();
+        if (part == null) {
+            return false;
+        }
         ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
         if (selectionProvider == null) {
             return false;
index 703d6c8f5fc98301a1b5d28aa9f33f9f89e8ad5d..4106bb547059362829a2c95f7e4f2f2a4eb1e724 100644 (file)
@@ -52,6 +52,9 @@ public class ImportTraceHandler extends AbstractHandler {
        // Get the selection
         IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
         IWorkbenchPart part = page.getActivePart();
+        if (part == null) {
+            return false;
+        }
         ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
         if (selectionProvider == null) {
             return false;
index 9e41e9a65f8be9d9dbc41bcbbfc383727c589de5..827977e417bf988d1e1e950fc32beaea0cf7dbcc 100644 (file)
@@ -1,11 +1,11 @@
 /*******************************************************************************
  * Copyright (c) 2009, 2010, 2011 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
  *******************************************************************************/
@@ -40,12 +40,16 @@ public class NewExperimentHandler extends AbstractHandler {
 
         // Check if we are closing down
         IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
-        if (window == null)
+        if (window == null) {
             return null;
+        }
 
         // Get the selection
         IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
         IWorkbenchPart part = page.getActivePart();
+        if (part == null) {
+            return false;
+        }
         ISelection selection = part.getSite().getSelectionProvider().getSelection();
         TmfExperimentFolder experimentFolder = null;
         if (selection instanceof TreeSelection) {
index a69159309b1f8e04ba2bf606816be0d6c59c744f..6bc0d4d88d42d023f60d9bc13544db007e41e4ed 100644 (file)
@@ -68,6 +68,9 @@ public class OpenExperimentHandler extends AbstractHandler {
         // Get the selection
         final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
         final IWorkbenchPart part = page.getActivePart();
+        if (part == null) {
+            return false;
+        }
         final ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
         if (selectionProvider == null) {
             return false;
index 8fb9a3e69d2bcb0e27f8e646b1851e6bc56bec66..892bd051934e9461613da63185979c508553fe51 100644 (file)
@@ -70,6 +70,9 @@ public class OpenTraceHandler extends AbstractHandler {
         // Get the selection
         final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
         final IWorkbenchPart part = page.getActivePart();
+        if (part == null) {
+            return false;
+        }
         final ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
         if (selectionProvider == null) {
             return false;
index 2ce27229db831fa5313316c89b4ed8040ff2eb4d..b42439f9a22a5a5008fe2cc596d8b5e24c2207bd 100644 (file)
@@ -1,11 +1,11 @@
 /*******************************************************************************
  * Copyright (c) 2011 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
  *******************************************************************************/
@@ -44,12 +44,16 @@ public class RefreshHandler extends AbstractHandler {
 
        // Check if we are closing down
        IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
-       if (window == null)
-               return null;
+       if (window == null) {
+            return null;
+        }
 
         // Get the selection
         IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
         IWorkbenchPart part = page.getActivePart();
+        if (part == null) {
+            return false;
+        }
         ISelection selection = part.getSite().getSelectionProvider().getSelection();
         if (selection instanceof TreeSelection) {
             TreeSelection treeSelection = (TreeSelection) selection;
index 5ffc5a98be4573dbcb67d0ea7d68e70066ecdf6c..1078baf8f43934f53b21bfba0da12c7546c8937f 100644 (file)
@@ -1,11 +1,11 @@
 /*******************************************************************************
  * Copyright (c) 2011 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
  *******************************************************************************/
@@ -33,7 +33,7 @@ import org.eclipse.ui.PlatformUI;
 public class RenameExperimentHandler extends AbstractHandler {
 
        private TmfExperimentElement fExperiment = null;
-       
+
        // ------------------------------------------------------------------------
     // isEnabled
     // ------------------------------------------------------------------------
@@ -43,15 +43,20 @@ public class RenameExperimentHandler extends AbstractHandler {
 
         // Check if we are closing down
         IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
-        if (window == null)
+        if (window == null) {
             return false;
+        }
 
         // Get the selection
         IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
         IWorkbenchPart part = page.getActivePart();
+        if (part == null) {
+            return false;
+        }
         ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
-        if (selectionProvider == null)
+        if (selectionProvider == null) {
             return false;
+        }
         ISelection selection = selectionProvider.getSelection();
 
         // Make sure there is only selection and that it is an experiment
@@ -76,8 +81,9 @@ public class RenameExperimentHandler extends AbstractHandler {
 
         // Check if we are closing down
         IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
-        if (window == null)
+        if (window == null) {
             return null;
+        }
 
         // Fire the Rename Experiment dialog
         Shell shell = window.getShell();
index f7d3a13cc7ba0997e75e445b113b708d9a60e6bd..34993c41d9817dca76f45425564a5a3cc7f51b94 100644 (file)
@@ -69,6 +69,9 @@ public class RenameTraceHandler extends AbstractHandler {
         // Get the selection
         IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
         IWorkbenchPart part = page.getActivePart();
+        if (part == null) {
+            return false;
+        }
         ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
         if (selectionProvider == null) {
             return false;
index e549157e53cae95c68eeb3a34eccfb3dc16140ee..7cce3077b51f7cfcc43ba21b54a95e0cf48aa188 100644 (file)
@@ -73,6 +73,9 @@ public class SelectTraceTypeHandler extends AbstractHandler {
         // Get the selection
         IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
         IWorkbenchPart part = page.getActivePart();
+        if (part == null) {
+            return false;
+        }
         ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
         if (selectionProvider == null) {
             return false;
index 90d65c1e6c071994883faf852d1ef9772f1c75a8..125804bd21da840d95160c7b489f04bbf8e92d9f 100644 (file)
@@ -1,11 +1,11 @@
 /*******************************************************************************
  * Copyright (c) 2009, 2010, 2011 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
  *******************************************************************************/
@@ -47,15 +47,20 @@ public class SelectTracesHandler extends AbstractHandler {
 
         // Check if we are closing down
         IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
-        if (window == null)
+        if (window == null) {
             return false;
+        }
 
         // Get the selection
         IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
         IWorkbenchPart part = page.getActivePart();
+        if (part == null) {
+            return false;
+        }
         ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
-        if (selectionProvider == null)
+        if (selectionProvider == null) {
             return false;
+        }
         ISelection selection = selectionProvider.getSelection();
 
         // Make sure there is only one selection and that it is an experiment
@@ -81,8 +86,9 @@ public class SelectTracesHandler extends AbstractHandler {
 
         // Check if we are closing down
         IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
-        if (window == null)
+        if (window == null) {
             return null;
+        }
 
         // Fire the Select Traces Wizard
         IWorkbench workbench = PlatformUI.getWorkbench();
This page took 0.034666 seconds and 5 git commands to generate.