ss: Move plugins to Trace Compass namespace
[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 e19a13d..6afa542
@@ -1,16 +1,15 @@
 /**********************************************************************
- * Copyright (c) 2005, 2008 IBM Corporation and others.
- * Copyright (c) 2011, 2012 Ericsson.
- * 
+ * Copyright (c) 2005, 2013 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
+ *
+ * Contributors:
+ *     IBM - Initial API and implementation
+ *     Bernd Hufmann - Updated for TMF
  **********************************************************************/
+
 package org.eclipse.linuxtools.tmf.ui.views.uml2sd.load;
 
 import java.util.ArrayList;
@@ -23,18 +22,18 @@ import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IConfigurationElement;
 import org.eclipse.core.runtime.IExtension;
 import org.eclipse.core.runtime.IExtensionPoint;
-import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.Status;
 import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.linuxtools.internal.tmf.ui.TmfUiPlugin;
+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.
- * 
+ *
  * @version 1.0
  * @author sveyrier
  * @author Bernd Hufmann
@@ -65,12 +64,12 @@ 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<>();
     /**
      * 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<>();
+
     // ------------------------------------------------------------------------
     // Constructor
     // ------------------------------------------------------------------------
@@ -85,20 +84,20 @@ public class LoadersManager {
     // ------------------------------------------------------------------------
     /**
      * A static method to get the manager instance.
-     * 
+     *
      * @return the manager instance
      */
-    public synchronized static LoadersManager getInstance() {
+    public static synchronized LoadersManager getInstance() {
         if (fLoadersManager == null) {
             fLoadersManager = new LoadersManager();
         }
         return fLoadersManager;
     }
-    
+
     /**
      * Creates a loader instance and associate it to the view. It requires
      * that the loader-view-association was created by an eclipse extension.
-     * 
+     *
      * @param className The name of the class to create an instance from
      * @param view The UML2 Sequence Diagram view instance
      * @return The created loader
@@ -125,16 +124,16 @@ public class LoadersManager {
                 return loader;
             }
         }
-        return null; 
+        return null;
     }
 
     /**
      * Sets the loader to null for this view, a kind of clean-up while disposing.
-     * 
+     *
      * @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();
         }
@@ -143,7 +142,7 @@ public class LoadersManager {
 
     /**
      * Returns the loader in use in given Sequence Diagram View
-     * 
+     *
      * @param viewId The Sequence Diagram viewId.
      * @return the current loader if any - null otherwise
      */
@@ -153,7 +152,7 @@ public class LoadersManager {
 
     /**
      * Returns the loader in use in this Sequence Diagram View
-     * 
+     *
      * @param viewId The Sequence Diagram viewId
      * @param view The Sequence Diagram view (if known). Use null to reference the primary SD View.
      * @return the current loader if any - null otherwise
@@ -163,18 +162,24 @@ public class LoadersManager {
             return null;
         }
 
-        IWorkbenchPage persp = TmfUiPlugin.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);
                 }
-                
+
                 if (sdView == null) {
                     // no corresponding view exists -> return null for the loader
                     return null;
@@ -190,33 +195,38 @@ public class LoadersManager {
 
             return loader;
         } catch (Exception e) {
-            TmfUiPlugin.getDefault().logError("Error getting loader class", e); //$NON-NLS-1$
+            Activator.getDefault().logError("Error getting loader class", e); //$NON-NLS-1$
         }
         return null;
     }
 
     /**
      * Returns the loader class name that have been saved last time.
-     * 
+     *
      * @param viewId The view this loader belongs to
      * @return the class name of the saved loader
      */
     public String getSavedLoader(String viewId) {
-        IPreferenceStore p = TmfUiPlugin.getDefault().getPreferenceStore();
+        IPreferenceStore p = Activator.getDefault().getPreferenceStore();
         return p.getString(LOADER_PREFIX + viewId);
     }
 
     /**
      * Saves the last loader in order to reload it on next session.
+     *
+     * @param id
+     *            Standalone ID of the loader
+     * @param id2
+     *            Suffix ID of the loader
      */
     public void saveLastLoader(String id, String id2) {
-        IPreferenceStore p = TmfUiPlugin.getDefault().getPreferenceStore();
+        IPreferenceStore p = Activator.getDefault().getPreferenceStore();
         p.setValue(LOADER_PREFIX + id2, id);
     }
 
     /**
      * Changes the current unique loader to the given secondary viewId.
-     * 
+     *
      * @param loader The current loader
      * @param id the view secondary id or null
      */
@@ -230,11 +240,16 @@ public class LoadersManager {
 
         if ((currentLoader != null) && (currentLoader != loader)) {
             if (loader != null) {
-                IWorkbenchPage persp = TmfUiPlugin.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);
                     }
@@ -245,7 +260,7 @@ public class LoadersManager {
                     }
 
                 } catch (Exception e) {
-                    TmfUiPlugin.getDefault().logError("Error setting current loader class", e); //$NON-NLS-1$
+                    Activator.getDefault().logError("Error setting current loader class", e); //$NON-NLS-1$
                 }
             }
             // The old loader is going to be kicked
@@ -260,11 +275,11 @@ public class LoadersManager {
             saveLastLoader(loader.getClass().getName(), id);
         }
     }
-    
+
     /**
      * Creates the last loader and saves it. If not last is not available, it creates
      * and saves the default loader, else no loader is created.
-     * 
+     *
      * @param viewId The view ID.
      */
     private void createLastLoaderIfAny(String viewId) {
@@ -290,17 +305,17 @@ 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;
         }
 
-        ArrayList<IConfigurationElement> ret = new ArrayList<IConfigurationElement>();
-        IExtensionPoint iep = Platform.getExtensionRegistry().getExtensionPoint(TmfUiPlugin.PLUGIN_ID, LOADER_TAG);
+        ArrayList<IConfigurationElement> ret = new ArrayList<>();
+        IExtensionPoint iep = Platform.getExtensionRegistry().getExtensionPoint(Activator.PLUGIN_ID, LOADER_TAG);
         if (iep == null) {
             return ret;
         }
-        
+
         IExtension[] ie = iep.getExtensions();
         if (ie == null) {
             return ret;
@@ -319,18 +334,19 @@ public class LoadersManager {
     }
 
     /**
-     * Returns the loader configuration element for given loader class name and for the given 
+     * Returns the loader configuration element for given loader class name and for the given
      * list of configuration elements, if available else null.
-     * 
+     *
      * @param loaderClassName The loader class name.
      * @param loaderElements  The list of loader configuration elements
-     * @return Extension point configuration element 
+     * @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;
                 }
@@ -340,16 +356,17 @@ public class LoadersManager {
     }
 
     /**
-     * Returns the loader configuration element for the given list of configuration elements, if available else null. 
+     * Returns the loader configuration element for the given list of configuration elements, if available else null.
      * Note that if multiple default loaders are defined it selects the first one
 
      * @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;
             }
@@ -360,7 +377,7 @@ public class LoadersManager {
     /**
      * Creates an instance of the loader class for a given extension point configuration element and
      * also sets it as current loader for the given view.
-     * 
+     *
      * @param viewId The view ID.
      * @param ce The extension point configuration element
      */
@@ -372,9 +389,9 @@ public class LoadersManager {
                 setCurrentLoader(l, viewId);
             }
         } catch (CoreException e4) {
-            TmfUiPlugin.getDefault().logError("Error 'uml2SDLoader' Extension point", e4); //$NON-NLS-1$
+            Activator.getDefault().logError("Error 'uml2SDLoader' Extension point", e4); //$NON-NLS-1$
         } catch (Exception e5) {
-            TmfUiPlugin.getDefault().logError("Error 'uml2SDLoader' Extension point", e5); //$NON-NLS-1$
+            Activator.getDefault().logError("Error 'uml2SDLoader' Extension point", e5); //$NON-NLS-1$
         }
     }
 }
This page took 0.057296 seconds and 5 git commands to generate.