01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal.ide.registry;
11:
12: import org.eclipse.core.runtime.IConfigurationElement;
13: import org.eclipse.core.runtime.IExtensionRegistry;
14: import org.eclipse.jface.resource.ImageDescriptor;
15: import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
16: import org.eclipse.ui.plugin.AbstractUIPlugin;
17:
18: /**
19: * A strategy to project nature image extensions from the registry.
20: */
21: public class ProjectImageRegistryReader extends IDERegistryReader {
22: private static final String TAG_IMAGE = "image";//$NON-NLS-1$
23:
24: private static final String ATT_ID = "id";//$NON-NLS-1$
25:
26: private static final String ATT_NATURE_ID = "natureId";//$NON-NLS-1$
27:
28: private static final String ATT_ICON = "icon";//$NON-NLS-1$
29:
30: private ProjectImageRegistry registry;
31:
32: /**
33: * Reads the contents of the given element
34: */
35: protected boolean readElement(IConfigurationElement element) {
36: if (!element.getName().equals(TAG_IMAGE)) {
37: return false;
38: }
39:
40: String id = element.getAttribute(ATT_ID);
41: if (id == null) {
42: logMissingAttribute(element, ATT_ID);
43: return true;
44: }
45:
46: String natureId = element.getAttribute(ATT_NATURE_ID);
47: if (natureId == null) {
48: logMissingAttribute(element, ATT_NATURE_ID);
49: return true;
50: }
51:
52: String icon = element.getAttribute(ATT_ICON);
53: if (icon == null) {
54: logMissingAttribute(element, ATT_ICON);
55: return true;
56: }
57: String extendingPluginId = element.getNamespace();
58: ImageDescriptor image = AbstractUIPlugin
59: .imageDescriptorFromPlugin(extendingPluginId, icon);
60:
61: if (image != null) {
62: registry.setNatureImage(natureId, image);
63: }
64:
65: return true;
66: }
67:
68: /**
69: * Read the project nature images within a registry.
70: */
71: public void readProjectNatureImages(IExtensionRegistry in,
72: ProjectImageRegistry out) {
73: registry = out;
74: readRegistry(in, IDEWorkbenchPlugin.IDE_WORKBENCH,
75: IDEWorkbenchPlugin.PL_PROJECT_NATURE_IMAGES);
76: }
77: }
|