KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > registry > PropertyPagesRegistryReader


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.registry;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.Collection JavaDoc;
15 import java.util.Iterator JavaDoc;
16 import java.util.List JavaDoc;
17
18 import org.eclipse.core.runtime.IConfigurationElement;
19 import org.eclipse.core.runtime.IExtensionRegistry;
20 import org.eclipse.ui.PlatformUI;
21 import org.eclipse.ui.internal.dialogs.PropertyPageContributorManager;
22 import org.eclipse.ui.internal.dialogs.RegistryPageContributor;
23
24 /**
25  * This class loads property pages from the registry.
26  */

27 public class PropertyPagesRegistryReader extends CategorizedPageRegistryReader {
28
29     /**
30      * Value "<code>nameFilter</code>".
31      */

32     public static final String JavaDoc ATT_NAME_FILTER = "nameFilter";//$NON-NLS-1$
33

34     /**
35      * Value "<code>name</code>".
36      */

37     public static final String JavaDoc ATT_FILTER_NAME = "name";//$NON-NLS-1$
38

39     /**
40      * Value "<code>value</code>".
41      */

42     public static final String JavaDoc ATT_FILTER_VALUE = "value";//$NON-NLS-1$
43

44     private static final String JavaDoc TAG_PAGE = "page";//$NON-NLS-1$
45

46     /**
47      * Value "<code>filter</code>".
48      */

49     public static final String JavaDoc TAG_FILTER = "filter";//$NON-NLS-1$
50

51     /**
52      * Value "<code>keywordReference</code>".
53      */

54     public static final String JavaDoc TAG_KEYWORD_REFERENCE = "keywordReference";//$NON-NLS-1$
55

56     /**
57      * Value "<code>objectClass</code>".
58      */

59     public static final String JavaDoc ATT_OBJECTCLASS = "objectClass";//$NON-NLS-1$
60

61     /**
62      * Value "<code>adaptable</code>".
63      */

64     public static final String JavaDoc ATT_ADAPTABLE = "adaptable";//$NON-NLS-1$
65

66     private static final String JavaDoc CHILD_ENABLED_WHEN = "enabledWhen"; //$NON-NLS-1$;
67

68     private Collection JavaDoc pages = new ArrayList JavaDoc();
69
70     private PropertyPageContributorManager manager;
71
72     class PropertyCategoryNode extends CategoryNode {
73
74         RegistryPageContributor page;
75
76         /**
77          * Create a new category node on the given reader for the property page.
78          *
79          * @param reader
80          * @param propertyPage
81          */

82         PropertyCategoryNode(CategorizedPageRegistryReader reader,
83                 RegistryPageContributor propertyPage) {
84             super(reader);
85             page = propertyPage;
86         }
87
88         /*
89          * (non-Javadoc)
90          *
91          * @see org.eclipse.ui.internal.registry.CategorizedPageRegistryReader.CategoryNode#getLabelText()
92          */

93         String JavaDoc getLabelText() {
94             return page.getPageName();
95         }
96
97         /*
98          * (non-Javadoc)
99          *
100          * @see org.eclipse.ui.internal.registry.CategorizedPageRegistryReader.CategoryNode#getLabelText(java.lang.Object)
101          */

102         String JavaDoc getLabelText(Object JavaDoc element) {
103             return ((RegistryPageContributor) element).getPageName();
104         }
105
106         /*
107          * (non-Javadoc)
108          *
109          * @see org.eclipse.ui.internal.registry.CategorizedPageRegistryReader.CategoryNode#getNode()
110          */

111         Object JavaDoc getNode() {
112             return page;
113         }
114     }
115
116     /**
117      * The constructor.
118      *
119      * @param manager
120      * the manager
121      */

122     public PropertyPagesRegistryReader(PropertyPageContributorManager manager) {
123         this.manager = manager;
124     }
125
126     /**
127      * Reads static property page specification.
128      */

129     private void processPageElement(IConfigurationElement element) {
130         String JavaDoc pageId = element
131                 .getAttribute(IWorkbenchRegistryConstants.ATT_ID);
132
133         if (pageId == null) {
134             logMissingAttribute(element, IWorkbenchRegistryConstants.ATT_ID);
135             return;
136         }
137
138         RegistryPageContributor contributor = new RegistryPageContributor(
139                 pageId, element);
140
141         String JavaDoc pageClassName = getClassValue(element,
142                 IWorkbenchRegistryConstants.ATT_CLASS);
143         if (pageClassName == null) {
144             logMissingAttribute(element, IWorkbenchRegistryConstants.ATT_CLASS);
145             return;
146         }
147         if (element.getAttribute(ATT_OBJECTCLASS) == null) {
148             pages.add(contributor);
149             manager.registerContributor(contributor, Object JavaDoc.class.getName());
150         } else {
151             List JavaDoc objectClassNames = new ArrayList JavaDoc();
152             objectClassNames.add(element.getAttribute(ATT_OBJECTCLASS));
153             registerContributors(contributor, objectClassNames);
154         }
155     }
156
157     /**
158      * Register the contributor for all of the relevant classes.
159      *
160      * @param contributor
161      * @param objectClassNames
162      */

163     private void registerContributors(RegistryPageContributor contributor,
164             List JavaDoc objectClassNames) {
165
166         pages.add(contributor);
167         for (Iterator JavaDoc iter = objectClassNames.iterator(); iter.hasNext();) {
168             manager.registerContributor(contributor, (String JavaDoc) iter.next());
169         }
170
171     }
172
173
174     /**
175      * Reads the next contribution element.
176      *
177      * public for dynamic UI
178      */

179     public boolean readElement(IConfigurationElement element) {
180         if (element.getName().equals(TAG_PAGE)) {
181             processPageElement(element);
182             readElementChildren(element);
183             return true;
184         }
185         if (element.getName().equals(TAG_FILTER)) {
186             return true;
187         }
188
189         if (element.getName().equals(CHILD_ENABLED_WHEN)) {
190             return true;
191         }
192
193         if (element.getName().equals(TAG_KEYWORD_REFERENCE)) {
194             return true;
195         }
196
197         return false;
198     }
199
200     /**
201      * Reads all occurances of propertyPages extension in the registry.
202      *
203      * @param registry
204      * the registry
205      */

206     public void registerPropertyPages(IExtensionRegistry registry) {
207         readRegistry(registry, PlatformUI.PLUGIN_ID,
208                 IWorkbenchRegistryConstants.PL_PROPERTY_PAGES);
209         processNodes();
210     }
211
212     /*
213      * (non-Javadoc)
214      *
215      * @see org.eclipse.ui.internal.registry.CategorizedPageRegistryReader#add(java.lang.Object,
216      * java.lang.Object)
217      */

218     void add(Object JavaDoc parent, Object JavaDoc node) {
219         ((RegistryPageContributor) parent)
220                 .addSubPage((RegistryPageContributor) node);
221
222     }
223
224     /*
225      * (non-Javadoc)
226      *
227      * @see org.eclipse.ui.internal.registry.CategorizedPageRegistryReader#createCategoryNode(org.eclipse.ui.internal.registry.CategorizedPageRegistryReader,
228      * java.lang.Object)
229      */

230     CategoryNode createCategoryNode(CategorizedPageRegistryReader reader,
231             Object JavaDoc object) {
232         return new PropertyCategoryNode(reader,
233                 (RegistryPageContributor) object);
234     }
235
236     /*
237      * (non-Javadoc)
238      *
239      * @see org.eclipse.ui.internal.registry.CategorizedPageRegistryReader#findNode(java.lang.Object,
240      * java.lang.String)
241      */

242     Object JavaDoc findNode(Object JavaDoc parent, String JavaDoc currentToken) {
243         return ((RegistryPageContributor) parent).getChild(currentToken);
244     }
245
246     /*
247      * (non-Javadoc)
248      *
249      * @see org.eclipse.ui.internal.registry.CategorizedPageRegistryReader#findNode(java.lang.String)
250      */

251     Object JavaDoc findNode(String JavaDoc id) {
252         Iterator JavaDoc iterator = pages.iterator();
253         while (iterator.hasNext()) {
254             RegistryPageContributor next = (RegistryPageContributor) iterator
255                     .next();
256             if (next.getPageId().equals(id))
257                 return next;
258         }
259         return null;
260     }
261
262     /*
263      * (non-Javadoc)
264      *
265      * @see org.eclipse.ui.internal.registry.CategorizedPageRegistryReader#getCategory(java.lang.Object)
266      */

267     String JavaDoc getCategory(Object JavaDoc node) {
268         return ((RegistryPageContributor) node).getCategory();
269     }
270
271     /*
272      * (non-Javadoc)
273      *
274      * @see org.eclipse.ui.internal.registry.CategorizedPageRegistryReader#getFavoriteNodeId()
275      */

276     String JavaDoc getFavoriteNodeId() {
277         return null;// properties do not support favorites
278
}
279
280     /*
281      * (non-Javadoc)
282      *
283      * @see org.eclipse.ui.internal.registry.CategorizedPageRegistryReader#getNodes()
284      */

285     Collection JavaDoc getNodes() {
286         return pages;
287     }
288 }
289
Popular Tags