KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > activities > ws > ImageBindingRegistry


1 /*******************************************************************************
2  * Copyright (c) 2004, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 /**
26  * @since 3.1
27  */

28 public class ImageBindingRegistry implements IExtensionChangeHandler {
29     private String JavaDoc tag;
30     private ImageRegistry registry = new ImageRegistry();
31     
32     /**
33      * @param tag
34      *
35      */

36     public ImageBindingRegistry(String JavaDoc 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     /* (non-Javadoc)
46      * @see org.eclipse.core.runtime.dynamicHelpers.IExtensionChangeHandler#addExtension(org.eclipse.core.runtime.dynamicHelpers.IExtensionTracker, org.eclipse.core.runtime.IExtension)
47      */

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 JavaDoc id = element.getAttribute(IWorkbenchRegistryConstants.ATT_ID);
54                 String JavaDoc file = element.getAttribute(IWorkbenchRegistryConstants.ATT_ICON);
55                 if (file == null || id == null) {
56                     continue; //ignore - malformed
57
}
58                 if (registry.getDescriptor(id) == null) { // first come, first serve
59
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     /**
71      * Return the activity support extension point that this registry is interested in.
72      *
73      * @return the extension point
74      */

75     public IExtensionPoint getExtensionPointFilter() {
76         return Platform.getExtensionRegistry().getExtensionPoint(
77                 PlatformUI.PLUGIN_ID, IWorkbenchRegistryConstants.PL_ACTIVITYSUPPORT);
78     }
79
80     /* (non-Javadoc)
81      * @see org.eclipse.core.runtime.dynamicHelpers.IExtensionChangeHandler#removeExtension(org.eclipse.core.runtime.IExtension, java.lang.Object[])
82      */

83     public void removeExtension(IExtension extension, Object JavaDoc[] objects) {
84         for (int i = 0; i < objects.length; i++) {
85             if (objects[i] instanceof String JavaDoc) {
86                 registry.remove((String JavaDoc) objects[i]);
87             }
88         }
89     }
90     
91     /**
92      * Get the ImageDescriptor for the given id.
93      *
94      * @param id the id
95      * @return the descriptor
96      */

97     public ImageDescriptor getImageDescriptor(String JavaDoc id) {
98         return registry.getDescriptor(id);
99     }
100     
101     /**
102      * Dispose of this registry.
103      */

104     void dispose() {
105         registry.dispose();
106     }
107
108 }
109
Popular Tags