tmf: API clean-up of sequence diagram framework
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / load / LoadersManager.java
old mode 100755 (executable)
new mode 100644 (file)
index 415cb44..713206d
@@ -1,16 +1,15 @@
 /**********************************************************************
- * Copyright (c) 2005, 2008 IBM Corporation and others.
- * Copyright (c) 2011, 2012 Ericsson.
- *
+ * Copyright (c) 2005, 2012 IBM Corporation, 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:
- * IBM - Initial API and implementation
- * Bernd Hufmann - Updated for TMF
+ *     IBM - Initial API and implementation
+ *     Bernd Hufmann - Updated for TMF
  **********************************************************************/
+
 package org.eclipse.linuxtools.tmf.ui.views.uml2sd.load;
 
 import java.util.ArrayList;
@@ -29,6 +28,8 @@ import org.eclipse.linuxtools.internal.tmf.ui.Activator;
 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDView;
 import org.eclipse.ui.IViewReference;
 import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
 
 /**
  * Manager class for the UML2SD extension point.
@@ -63,11 +64,11 @@ public class LoadersManager {
     /**
      * Map for caching information (view ID to loader class)
      */
-    protected Map<String, IUml2SDLoader> fViewLoaderMap = new HashMap<String, IUml2SDLoader>();
+    private Map<String, IUml2SDLoader> fViewLoaderMap = new HashMap<String, IUml2SDLoader>();
     /**
      * Map for caching information (view ID to list of configuration elements)
      */
-    protected Map<String, ArrayList<IConfigurationElement>> fViewLoadersList = new HashMap<String, ArrayList<IConfigurationElement>>();
+    private Map<String, ArrayList<IConfigurationElement>> fViewLoadersList = new HashMap<String, ArrayList<IConfigurationElement>>();
 
     // ------------------------------------------------------------------------
     // Constructor
@@ -132,7 +133,7 @@ public class LoadersManager {
      * @param viewId the id of the view
      */
     public void resetLoader(String viewId) {
-        IUml2SDLoader loader = (IUml2SDLoader) fViewLoaderMap.get(viewId);
+        IUml2SDLoader loader = fViewLoaderMap.get(viewId);
         if (loader != null) {
             loader.dispose();
         }
@@ -161,14 +162,20 @@ public class LoadersManager {
             return null;
         }
 
-        IWorkbenchPage persp = Activator.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
+        IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+        // During Eclipse shutdown the active workbench window is null
+        if (window == null) {
+            return null;
+        }
+
+        IWorkbenchPage persp = window.getActivePage();
 
         SDView sdView = view;
 
         try {
             // Search the view corresponding to the viewId
             if (sdView == null) {
-                IViewReference viewref = (IViewReference) persp.findViewReference(viewId);
+                IViewReference viewref = persp.findViewReference(viewId);
                 if (viewref != null) {
                     sdView = (SDView) viewref.getView(false);
                 }
@@ -233,11 +240,16 @@ public class LoadersManager {
 
         if ((currentLoader != null) && (currentLoader != loader)) {
             if (loader != null) {
-                IWorkbenchPage persp = Activator.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
+                IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+                // During Eclipse shutdown the active workbench window is null
+                if (window == null) {
+                    return;
+                }
+                IWorkbenchPage persp = window.getActivePage();
                 try {
                     // Search view corresponding to the viewId
                     SDView sdview = null;
-                    IViewReference viewref = (IViewReference) persp.findViewReference(id);
+                    IViewReference viewref = persp.findViewReference(id);
                     if (viewref != null) {
                         sdview = (SDView) viewref.getView(false);
                     }
@@ -293,7 +305,7 @@ public class LoadersManager {
      * @return List of extension point configuration elements.
      */
     private List<IConfigurationElement> getLoaderConfigurationElements(String viewId) {
-        List<IConfigurationElement> list = (List<IConfigurationElement>) fViewLoadersList.get(viewId);
+        List<IConfigurationElement> list = fViewLoadersList.get(viewId);
         if (list != null) {
             return list;
         }
@@ -329,11 +341,12 @@ public class LoadersManager {
      * @param loaderElements  The list of loader configuration elements
      * @return Extension point configuration element
      */
-    private IConfigurationElement getLoaderConfigurationElement(String loaderClassName, List<IConfigurationElement> loaderElements) {
+    private static IConfigurationElement getLoaderConfigurationElement(
+            String loaderClassName, List<IConfigurationElement> loaderElements) {
         if (loaderClassName != null && loaderClassName.length() > 0) {
             // Find configuration element corresponding to the saved loader
             for (Iterator<IConfigurationElement> i = loaderElements.iterator(); i.hasNext();) {
-                IConfigurationElement ce = (IConfigurationElement) i.next();
+                IConfigurationElement ce = i.next();
                 if (ce.getAttribute("class").equals(loaderClassName)) { //$NON-NLS-1$
                     return ce;
                 }
@@ -349,10 +362,11 @@ public class LoadersManager {
      * @param loaderElements The list of loader configuration elements
      * @return The default extension point configuration element.
      */
-    private IConfigurationElement getDefaultLoader(List<IConfigurationElement> loaderElements) {
+    private static IConfigurationElement getDefaultLoader(
+            List<IConfigurationElement> loaderElements) {
         // Look for a default loader
         for (Iterator<IConfigurationElement> i = loaderElements.iterator(); i.hasNext();) {
-            IConfigurationElement ce = (IConfigurationElement) i.next();
+            IConfigurationElement ce = i.next();
             if (Boolean.valueOf(ce.getAttribute("default")).booleanValue()) { //$NON-NLS-1$
                 return ce;
             }
This page took 0.027019 seconds and 5 git commands to generate.