/** Returns an {@link Image} instance which is located at the indicated icon path. */ public static Image getImage( org.springframework.ide.eclipse.beans.core.model.INamespaceDefinition namespaceDefinition) { if (StringUtils.hasText(namespaceDefinition.getIconPath())) { synchronized (IMAGE_REGISTRY_LOCK) { Image image = BeansUIPlugin.getDefault().getImageRegistry().get(namespaceDefinition.getIconPath()); if (image == null) { InputStream is = namespaceDefinition.getIconStream(); if (is != null) { try { ImageDescriptor imageDescriptor = ImageDescriptor.createFromImageData(new ImageData(is)); BeansUIPlugin.getDefault() .getImageRegistry() .put(namespaceDefinition.getIconPath(), imageDescriptor); image = BeansUIPlugin.getDefault() .getImageRegistry() .get(namespaceDefinition.getIconPath()); } catch (Exception e) { BeansUIPlugin.log( String.format( "Error creating image resource for namespace definition '%s'", namespaceDefinition.getNamespaceUri()), e); return BeansUIImages.getImage(BeansUIImages.IMG_OBJS_XSD); } finally { if (is != null) { try { is.close(); } catch (IOException e) { } } } } else { BeansUIPlugin.getDefault() .getImageRegistry() .put( namespaceDefinition.getIconPath(), BeansUIImages.getImage(BeansUIImages.IMG_OBJS_XSD)); image = BeansUIPlugin.getDefault() .getImageRegistry() .get(namespaceDefinition.getIconPath()); } } return image; } } else { return BeansUIImages.getImage(BeansUIImages.IMG_OBJS_XSD); } }
/** Returns an {@link Image} instance which is located at the indicated icon path. */ private static Image getImage(String ns, String icon) { if (StringUtils.hasText(icon)) { synchronized (IMAGE_REGISTRY_LOCK) { Image image = BeansUIPlugin.getDefault().getImageRegistry().get(icon); if (image == null) { ImageDescriptor imageDescriptor = BeansUIPlugin.imageDescriptorFromPlugin(ns, icon); BeansUIPlugin.getDefault().getImageRegistry().put(icon, imageDescriptor); image = BeansUIPlugin.getDefault().getImageRegistry().get(icon); } return image; } } else { return BeansUIImages.getImage(BeansUIImages.IMG_OBJS_XSD); } }