KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.ui.WorkbenchException;
16 import org.eclipse.ui.internal.ide.Category;
17 import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
18
19 /**
20  * This class is used to read project capabilities and capability
21  * categories from the platform's plugin registry and store the results in
22  * a capability registry.
23  */

24 public class CapabilityRegistryReader extends IDERegistryReader {
25     private static final String JavaDoc TAG_CAPABILITY = "capability"; //$NON-NLS-1$
26

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

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

31     private static final String JavaDoc TAG_PERSPECTIVE_CHOICE = "perspectiveChoice"; //$NON-NLS-1$
32

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

35     private CapabilityRegistry capabilityRegistry;
36
37     private Capability currentCapability;
38
39     /**
40      * Reads an element of the plugin registry and adds it to the capability
41      * registry if it is a capability or category (or a handleUI element, a
42      * child of a capability. A handleUI element represents another capability
43      * for which this capability controls the user interface).
44      */

45     protected boolean readElement(IConfigurationElement element) {
46         String JavaDoc name = element.getName();
47         if (name.equals(TAG_CAPABILITY))
48             return readCapability(element);
49         if (name.equals(TAG_CATEGORY))
50             return readCategory(element);
51         if (name.equals(TAG_HANDLE_UI))
52             return readHandleUI(element);
53         if (name.equals(TAG_PERSPECTIVE_CHOICE))
54             return readPerspectiveChoice(element);
55         return false;
56     }
57
58     /**
59      * Reads a capability and adds it to the capability registry. Reads all
60      * children elements (which will be handleUI elements) as well and adds
61      * them to the capability.
62      */

63     private boolean readCapability(IConfigurationElement element) {
64         try {
65             Capability capability = new Capability(element, this);
66             capabilityRegistry.addCapability(capability);
67             currentCapability = capability;
68             readElementChildren(element);
69             currentCapability = null;
70             return true;
71         } catch (WorkbenchException e) {
72             currentCapability = null;
73             return false;
74         }
75     }
76
77     /**
78      * Reads a capability category and adds it to the capability registry.
79      */

80     private boolean readCategory(IConfigurationElement element) {
81         try {
82             Category category = new Category(element);
83             capabilityRegistry.addCategory(category);
84         } catch (WorkbenchException e) {
85             // log an error since its not safe to show a dialog here
86
IDEWorkbenchPlugin.log(
87                     "Unable to create capability category. ", e.getStatus()); //$NON-NLS-1$
88
}
89         return true;
90     }
91
92     /**
93      * Reads handleUI elements. These elements contain the ids of other
94      * capabilities. The capability that is the parent of the handleUI element
95      * controls the user interface for the capabilities whose ids are stored
96      * in the handleUI element.
97      */

98     private boolean readHandleUI(IConfigurationElement element) {
99         String JavaDoc capabilityId = element.getAttribute(ATT_ID);
100
101         if (capabilityId == null) {
102             logMissingAttribute(element, ATT_ID);
103         }
104
105         if (currentCapability != null)
106             currentCapability.addHandleUI(capabilityId);
107         return true;
108     }
109
110     /**
111      * Reads perspectiveChoice elements. These elements contain the ids of
112      * perspectives.
113      */

114     private boolean readPerspectiveChoice(IConfigurationElement element) {
115         String JavaDoc perspId = element.getAttribute(ATT_ID);
116
117         if (perspId == null) {
118             logMissingAttribute(element, ATT_ID);
119         }
120
121         if (currentCapability != null)
122             currentCapability.addPerspectiveChoice(perspId);
123         return true;
124     }
125
126     /**
127      * Reads project capabilities and capability categories from the provided
128      * plugin registry and stores them in the provided capability registry.
129      */

130     public void read(IExtensionRegistry registry, CapabilityRegistry out) {
131         capabilityRegistry = out;
132         readRegistry(registry, IDEWorkbenchPlugin.IDE_WORKBENCH,
133                 IDEWorkbenchPlugin.PL_CAPABILITIES);
134     }
135 }
136
Popular Tags