Bug 564082 - Use deferred image API

Change-Id: I36d688b97daaacc21fe08fdf8a9db7eb3be53aca
diff --git a/org.eclipse.debug.ui/META-INF/MANIFEST.MF b/org.eclipse.debug.ui/META-INF/MANIFEST.MF
index 1e44df9..e389441 100644
--- a/org.eclipse.debug.ui/META-INF/MANIFEST.MF
+++ b/org.eclipse.debug.ui/META-INF/MANIFEST.MF
@@ -83,6 +83,7 @@
  org.eclipse.ui.console;bundle-version="[3.5.300,4.0.0)",
  org.eclipse.help;bundle-version="[3.4.0,4.0.0)",
  org.eclipse.debug.core;bundle-version="[3.9.0,4.0.0)";visibility:=reexport,
+ org.eclipse.jface;bundle-version="[3.21.0,4.0.0)",
  org.eclipse.jface.text;bundle-version="[3.5.0,4.0.0)",
  org.eclipse.ui.workbench.texteditor;bundle-version="[3.5.0,4.0.0)",
  org.eclipse.ui.ide;bundle-version="[3.5.0,4.0.0)",
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugPluginImages.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugPluginImages.java
index f900621..a7ca3d1 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugPluginImages.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugPluginImages.java
@@ -20,8 +20,6 @@
 package org.eclipse.debug.internal.ui;
 
 
-import java.net.URL;
-
 import org.eclipse.core.runtime.FileLocator;
 import org.eclipse.core.runtime.IConfigurationElement;
 import org.eclipse.core.runtime.IExtensionPoint;
@@ -33,6 +31,7 @@
 import org.eclipse.jface.resource.ImageRegistry;
 import org.eclipse.swt.graphics.Image;
 import org.osgi.framework.Bundle;
+import org.osgi.framework.FrameworkUtil;
 
 /**
  * The images provided by the debug plugin.
@@ -292,16 +291,13 @@
 	 *				this plugin class is found (i.e. typically the packages directory)
 	 */
 	private final static void declareRegistryImage(String key, String path) {
-		ImageDescriptor desc = ImageDescriptor.getMissingImageDescriptor();
-		Bundle bundle = Platform.getBundle(DebugUIPlugin.getUniqueIdentifier());
-		URL url = null;
-		if (bundle != null){
-			url = FileLocator.find(bundle, new Path(path), null);
-			if(url != null) {
-				desc = ImageDescriptor.createFromURL(url);
-			}
+		Bundle bundle = FrameworkUtil.getBundle(DebugPluginImages.class);
+		if (bundle == null) {
+			imageRegistry.put(key, ImageDescriptor.getMissingImageDescriptor());
+		} else {
+			imageRegistry.put(key,
+					ImageDescriptor.createFromURLSupplier(true, () -> FileLocator.find(bundle, new Path(path), null)));
 		}
-		imageRegistry.put(key, desc);
 	}
 
 	/**
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIPlugin.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIPlugin.java
index 9dc8f62..d0ea7f2 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIPlugin.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIPlugin.java
@@ -1339,22 +1339,22 @@
 	 * @return image descriptor or <code>null</code>
 	 */
 	public static ImageDescriptor getImageDescriptor(IConfigurationElement element, String attr) {
-		Bundle bundle = Platform.getBundle(element.getContributor().getName());
 		String iconPath = element.getAttribute(attr);
 		if (iconPath != null) {
-			URL iconURL = FileLocator.find(bundle , new Path(iconPath), null);
-			if (iconURL != null) {
-				return ImageDescriptor.createFromURL(iconURL);
-			} else { // try to search as a URL in case it is absolute path
-				try {
-					iconURL = FileLocator.find(new URL(iconPath));
-					if (iconURL != null) {
-						return ImageDescriptor.createFromURL(iconURL);
+			Bundle bundle = Platform.getBundle(element.getContributor().getName());
+			return ImageDescriptor.createFromURLSupplier(true, () -> {
+				URL iconURL = FileLocator.find(bundle, new Path(iconPath), null);
+				if (iconURL != null) {
+					return iconURL;
+				} else { // try to search as a URL in case it is absolute path
+					try {
+						return FileLocator.find(new URL(iconPath));
+					} catch (MalformedURLException e) {
+						// return null
 					}
-				} catch (MalformedURLException e) {
-					// return null
 				}
-			}
+				return null;
+			});
 		}
 		return null;
 	}
@@ -1369,12 +1369,9 @@
 	 * @since 3.3
 	 */
 	public static ImageDescriptor getImageDescriptor(String bundleName, String path) {
-		Bundle bundle = Platform.getBundle(bundleName);
 		if (path != null) {
-			URL iconURL = FileLocator.find(bundle , new Path(path), null);
-			if (iconURL != null) {
-				return ImageDescriptor.createFromURL(iconURL);
-			}
+			Bundle bundle = Platform.getBundle(bundleName);
+			return ImageDescriptor.createFromURLSupplier(true, () -> FileLocator.find(bundle, new Path(path), null));
 		}
 		return null;
 	}