1 11 package org.eclipse.ui.internal.activities.ws; 12 13 import org.eclipse.core.runtime.IConfigurationElement; 14 import org.eclipse.core.runtime.IExtension; 15 import org.eclipse.core.runtime.IExtensionPoint; 16 import org.eclipse.core.runtime.Platform; 17 import org.eclipse.core.runtime.dynamichelpers.IExtensionChangeHandler; 18 import org.eclipse.core.runtime.dynamichelpers.IExtensionTracker; 19 import org.eclipse.jface.resource.ImageDescriptor; 20 import org.eclipse.jface.resource.ImageRegistry; 21 import org.eclipse.ui.PlatformUI; 22 import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants; 23 import org.eclipse.ui.plugin.AbstractUIPlugin; 24 25 28 public class ImageBindingRegistry implements IExtensionChangeHandler { 29 private String tag; 30 private ImageRegistry registry = new ImageRegistry(); 31 32 36 public ImageBindingRegistry(String tag) { 37 super(); 38 this.tag = tag; 39 IExtension [] extensions = getExtensionPointFilter().getExtensions(); 40 for (int i = 0; i < extensions.length; i++) { 41 addExtension(PlatformUI.getWorkbench().getExtensionTracker(), extensions[i]); 42 } 43 } 44 45 48 public void addExtension(IExtensionTracker tracker, IExtension extension) { 49 IConfigurationElement [] elements = extension.getConfigurationElements(); 50 for (int i = 0; i < elements.length; i++) { 51 IConfigurationElement element = elements[i]; 52 if (element.getName().equals(tag)) { 53 String id = element.getAttribute(IWorkbenchRegistryConstants.ATT_ID); 54 String file = element.getAttribute(IWorkbenchRegistryConstants.ATT_ICON); 55 if (file == null || id == null) { 56 continue; } 58 if (registry.getDescriptor(id) == null) { ImageDescriptor descriptor = AbstractUIPlugin.imageDescriptorFromPlugin(element.getNamespace(), file); 60 if (descriptor != null) { 61 registry.put(id, descriptor); 62 tracker.registerObject(extension, id, IExtensionTracker.REF_WEAK); 63 } 64 } 65 } 66 } 67 68 } 69 70 75 public IExtensionPoint getExtensionPointFilter() { 76 return Platform.getExtensionRegistry().getExtensionPoint( 77 PlatformUI.PLUGIN_ID, IWorkbenchRegistryConstants.PL_ACTIVITYSUPPORT); 78 } 79 80 83 public void removeExtension(IExtension extension, Object [] objects) { 84 for (int i = 0; i < objects.length; i++) { 85 if (objects[i] instanceof String ) { 86 registry.remove((String ) objects[i]); 87 } 88 } 89 } 90 91 97 public ImageDescriptor getImageDescriptor(String id) { 98 return registry.getDescriptor(id); 99 } 100 101 104 void dispose() { 105 registry.dispose(); 106 } 107 108 } 109 | Popular Tags |