org.eclipse.ui.plugin.AbstractUIPlugin
public static ImageDescriptor imageDescriptorFromPlugin(String pluginId,
String imageFilePath) {
if (pluginId == null || imageFilePath == null) {
throw new IllegalArgumentException();
}
IWorkbench workbench = PlatformUI.isWorkbenchRunning() ? PlatformUI.getWorkbench() : null;
ImageDescriptor imageDescriptor = workbench == null ? null : workbench
.getSharedImages().getImageDescriptor(imageFilePath);
if (imageDescriptor != null)
return imageDescriptor; // found in the shared images
// if the bundle is not ready then there is no image
Bundle bundle = Platform.getBundle(pluginId);
if (!BundleUtility.isReady(bundle)) {
return null;
}
// look for the image (this will check both the plugin and fragment folders
URL fullPathString = BundleUtility.find(bundle, imageFilePath);
if (fullPathString == null) {
try {
fullPathString = new URL(imageFilePath);
} catch (MalformedURLException e) {
return null;
}
}
return ImageDescriptor.createFromURL(fullPathString);
}
org.eclipse.jface.resource.ImageDescriptor
public static ImageDescriptor createFromURL(URL url) {
if (url == null) {
return getMissingImageDescriptor();
}
return new URLImageDescriptor(url);
}
public static ImageDescriptor createFromFile(Class location, String filename) { return new FileImageDescriptor(location, filename); }
public static ImageDescriptor createFromImageData(ImageData data) { return new ImageDataImageDescriptor(data); }