Bug 549441 - Rework usages of AbstractUIPlugin#imageDescriptorFromPlugin

Use ResourceLocator#imageDescriptorFromBundle

Change-Id: I4b145baadab370283e2700f52e2d3af135678e58
Signed-off-by: Alexander Fedorov <alexander.fedorov@arsysop.ru>
diff --git a/examples/packaging_p2_product/org.example.mail/META-INF/MANIFEST.MF b/examples/packaging_p2_product/org.example.mail/META-INF/MANIFEST.MF
index 57e0330..339cb42 100644
--- a/examples/packaging_p2_product/org.example.mail/META-INF/MANIFEST.MF
+++ b/examples/packaging_p2_product/org.example.mail/META-INF/MANIFEST.MF
@@ -2,10 +2,10 @@
 Bundle-ManifestVersion: 2
 Bundle-Name: Mail Plug-in
 Bundle-SymbolicName: org.example.mail; singleton:=true
-Bundle-Version: 1.0.100.qualifier
-Bundle-Activator: org.example.mail.Activator
+Bundle-Version: 1.1.0.qualifier
 Require-Bundle: org.eclipse.ui,
  org.eclipse.core.runtime
 Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Export-Package: org.example.mail
 Bundle-ActivationPolicy: lazy
 Automatic-Module-Name: org.example.mail
diff --git a/examples/packaging_p2_product/org.example.mail/src/org/example/mail/Activator.java b/examples/packaging_p2_product/org.example.mail/src/org/example/mail/Activator.java
deleted file mode 100644
index b19d6d0..0000000
--- a/examples/packaging_p2_product/org.example.mail/src/org/example/mail/Activator.java
+++ /dev/null
@@ -1,61 +0,0 @@
-package org.example.mail;
-
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.ui.plugin.AbstractUIPlugin;
-import org.osgi.framework.BundleContext;
-
-/**
- * The activator class controls the plug-in life cycle
- */
-public class Activator extends AbstractUIPlugin {
-
-	// The plug-in ID
-	public static final String PLUGIN_ID = "org.example.mail";
-
-	// The shared instance
-	private static Activator plugin;
-	
-	/**
-	 * The constructor
-	 */
-	public Activator() {
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
-	 */
-	public void start(BundleContext context) throws Exception {
-		super.start(context);
-		plugin = this;
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
-	 */
-	public void stop(BundleContext context) throws Exception {
-		plugin = null;
-		super.stop(context);
-	}
-
-	/**
-	 * Returns the shared instance
-	 *
-	 * @return the shared instance
-	 */
-	public static Activator getDefault() {
-		return plugin;
-	}
-
-	/**
-	 * Returns an image descriptor for the image file at the given
-	 * plug-in relative path
-	 *
-	 * @param path the path
-	 * @return the image descriptor
-	 */
-	public static ImageDescriptor getImageDescriptor(String path) {
-		return imageDescriptorFromPlugin(PLUGIN_ID, path);
-	}
-}
diff --git a/examples/packaging_p2_product/org.example.mail/src/org/example/mail/MessagePopupAction.java b/examples/packaging_p2_product/org.example.mail/src/org/example/mail/MessagePopupAction.java
index 2f4adfd..f5a63a7 100644
--- a/examples/packaging_p2_product/org.example.mail/src/org/example/mail/MessagePopupAction.java
+++ b/examples/packaging_p2_product/org.example.mail/src/org/example/mail/MessagePopupAction.java
@@ -1,7 +1,11 @@
 package org.example.mail;
 
+import java.util.Optional;
+
 import org.eclipse.jface.action.Action;
 import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.resource.ResourceLocator;
 import org.eclipse.ui.IWorkbenchWindow;
 
 
@@ -16,7 +20,10 @@
         setId(ICommandIds.CMD_OPEN_MESSAGE);
         // Associate the action with a pre-defined command, to allow key bindings.
         setActionDefinitionId(ICommandIds.CMD_OPEN_MESSAGE);
-        setImageDescriptor(org.example.mail.Activator.getImageDescriptor("/icons/sample3.gif"));
+        Optional<ImageDescriptor> imageDescriptor = ResourceLocator.imageDescriptorFromBundle(getClass(), "/icons/sample3.gif");
+        if (imageDescriptor.isPresent()) {
+        	setImageDescriptor(imageDescriptor.get());
+		}
     }
 
     public void run() {
diff --git a/examples/packaging_p2_product/org.example.mail/src/org/example/mail/NavigationView.java b/examples/packaging_p2_product/org.example.mail/src/org/example/mail/NavigationView.java
index 4a71b96..4695180 100644
--- a/examples/packaging_p2_product/org.example.mail/src/org/example/mail/NavigationView.java
+++ b/examples/packaging_p2_product/org.example.mail/src/org/example/mail/NavigationView.java
@@ -40,10 +40,10 @@
 	}
 	
 	class TreeParent extends TreeObject {
-		private ArrayList children;
+		private ArrayList<TreeObject> children;
 		public TreeParent(String name) {
 			super(name);
-			children = new ArrayList();
+			children = new ArrayList<TreeObject>();
 		}
 		public void addChild(TreeObject child) {
 			children.add(child);
diff --git a/examples/packaging_p2_product/org.example.mail/src/org/example/mail/OpenViewAction.java b/examples/packaging_p2_product/org.example.mail/src/org/example/mail/OpenViewAction.java
index df9bc10..0f3d1f5 100644
--- a/examples/packaging_p2_product/org.example.mail/src/org/example/mail/OpenViewAction.java
+++ b/examples/packaging_p2_product/org.example.mail/src/org/example/mail/OpenViewAction.java
@@ -1,7 +1,11 @@
 package org.example.mail;
 
+import java.util.Optional;
+
 import org.eclipse.jface.action.Action;
 import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.resource.ResourceLocator;
 import org.eclipse.ui.IWorkbenchPage;
 import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.PartInitException;
@@ -21,7 +25,10 @@
 		setId(ICommandIds.CMD_OPEN);
         // Associate the action with a pre-defined command, to allow key bindings.
 		setActionDefinitionId(ICommandIds.CMD_OPEN);
-		setImageDescriptor(org.example.mail.Activator.getImageDescriptor("/icons/sample2.gif"));
+        Optional<ImageDescriptor> imageDescriptor = ResourceLocator.imageDescriptorFromBundle(getClass(), "/icons/sample2.gif");
+        if (imageDescriptor.isPresent()) {
+        	setImageDescriptor(imageDescriptor.get());
+		}
 	}
 	
 	public void run() {
diff --git a/org.eclipse.pde.build.tests/resources/237922/rcp/src/rcp/Activator.java b/org.eclipse.pde.build.tests/resources/237922/rcp/src/rcp/Activator.java
index 3f8003f..75ff0c7 100644
--- a/org.eclipse.pde.build.tests/resources/237922/rcp/src/rcp/Activator.java
+++ b/org.eclipse.pde.build.tests/resources/237922/rcp/src/rcp/Activator.java
@@ -1,6 +1,7 @@
 package rcp;
 
 import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.resource.ResourceLocator;
 import org.eclipse.ui.plugin.AbstractUIPlugin;
 import org.osgi.framework.BundleContext;
 
@@ -48,6 +49,6 @@
 	 * @return the image descriptor
 	 */
 	public static ImageDescriptor getImageDescriptor(String path) {
-		return imageDescriptorFromPlugin(PLUGIN_ID, path);
+		return ResourceLocator.imageDescriptorFromBundle(PLUGIN_ID, path).orElse(null);
 	}
 }
diff --git a/org.eclipse.pde.build.tests/resources/309572/plugins/test.flex.root/src/my/view/Activator.java b/org.eclipse.pde.build.tests/resources/309572/plugins/test.flex.root/src/my/view/Activator.java
index 68be61c..6120e62 100644
--- a/org.eclipse.pde.build.tests/resources/309572/plugins/test.flex.root/src/my/view/Activator.java
+++ b/org.eclipse.pde.build.tests/resources/309572/plugins/test.flex.root/src/my/view/Activator.java
@@ -1,6 +1,7 @@
 package my.view;
 
 import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.resource.ResourceLocator;
 import org.eclipse.ui.plugin.AbstractUIPlugin;
 import org.osgi.framework.BundleContext;
 
@@ -48,6 +49,6 @@
 	 * @return the image descriptor
 	 */
 	public static ImageDescriptor getImageDescriptor(String path) {
-		return imageDescriptorFromPlugin(PLUGIN_ID, path);
+		return ResourceLocator.imageDescriptorFromBundle(PLUGIN_ID, path).orElse(null);
 	}
 }