KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > ide > registry > ProjectImageRegistryReader


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.ide.registry;
12
13 import org.eclipse.core.runtime.IConfigurationElement;
14 import org.eclipse.core.runtime.IExtensionRegistry;
15 import org.eclipse.jface.resource.ImageDescriptor;
16 import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
17 import org.eclipse.ui.plugin.AbstractUIPlugin;
18
19 /**
20  * A strategy to project nature image extensions from the registry.
21  */

22 public class ProjectImageRegistryReader extends IDERegistryReader {
23     private static final String JavaDoc TAG_IMAGE = "image";//$NON-NLS-1$
24

25     private static final String JavaDoc ATT_ID = "id";//$NON-NLS-1$
26

27     private static final String JavaDoc ATT_NATURE_ID = "natureId";//$NON-NLS-1$
28

29     private static final String JavaDoc ATT_ICON = "icon";//$NON-NLS-1$
30

31     private ProjectImageRegistry registry;
32
33     /**
34      * Reads the contents of the given element
35      */

36     protected boolean readElement(IConfigurationElement element) {
37         if (!element.getName().equals(TAG_IMAGE)) {
38             return false;
39         }
40
41         String JavaDoc id = element.getAttribute(ATT_ID);
42         if (id == null) {
43             logMissingAttribute(element, ATT_ID);
44             return true;
45         }
46
47         String JavaDoc natureId = element.getAttribute(ATT_NATURE_ID);
48         if (natureId == null) {
49             logMissingAttribute(element, ATT_NATURE_ID);
50             return true;
51         }
52
53         String JavaDoc icon = element.getAttribute(ATT_ICON);
54         if (icon == null) {
55             logMissingAttribute(element, ATT_ICON);
56             return true;
57         }
58         String JavaDoc extendingPluginId = element.getNamespace();
59         ImageDescriptor image = AbstractUIPlugin.imageDescriptorFromPlugin(
60                 extendingPluginId, icon);
61
62         if (image != null) {
63             registry.setNatureImage(natureId, image);
64         }
65
66         return true;
67     }
68
69     /**
70      * Read the project nature images within a registry.
71      */

72     public void readProjectNatureImages(IExtensionRegistry in,
73             ProjectImageRegistry out) {
74         registry = out;
75         readRegistry(in, IDEWorkbenchPlugin.IDE_WORKBENCH,
76                 IDEWorkbenchPlugin.PL_PROJECT_NATURE_IMAGES);
77     }
78 }
79
Popular Tags