001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.internal.registry;
011:
012: import java.util.ArrayList;
013: import java.util.Collection;
014: import java.util.Iterator;
015: import java.util.List;
016:
017: import org.eclipse.core.runtime.IConfigurationElement;
018: import org.eclipse.core.runtime.IExtensionRegistry;
019: import org.eclipse.ui.PlatformUI;
020: import org.eclipse.ui.internal.dialogs.PropertyPageContributorManager;
021: import org.eclipse.ui.internal.dialogs.RegistryPageContributor;
022:
023: /**
024: * This class loads property pages from the registry.
025: */
026: public class PropertyPagesRegistryReader extends
027: CategorizedPageRegistryReader {
028:
029: /**
030: * Value "<code>nameFilter</code>".
031: */
032: public static final String ATT_NAME_FILTER = "nameFilter";//$NON-NLS-1$
033:
034: /**
035: * Value "<code>name</code>".
036: */
037: public static final String ATT_FILTER_NAME = "name";//$NON-NLS-1$
038:
039: /**
040: * Value "<code>value</code>".
041: */
042: public static final String ATT_FILTER_VALUE = "value";//$NON-NLS-1$
043:
044: private static final String TAG_PAGE = "page";//$NON-NLS-1$
045:
046: /**
047: * Value "<code>filter</code>".
048: */
049: public static final String TAG_FILTER = "filter";//$NON-NLS-1$
050:
051: /**
052: * Value "<code>keywordReference</code>".
053: */
054: public static final String TAG_KEYWORD_REFERENCE = "keywordReference";//$NON-NLS-1$
055:
056: /**
057: * Value "<code>objectClass</code>".
058: */
059: public static final String ATT_OBJECTCLASS = "objectClass";//$NON-NLS-1$
060:
061: /**
062: * Value "<code>adaptable</code>".
063: */
064: public static final String ATT_ADAPTABLE = "adaptable";//$NON-NLS-1$
065:
066: private static final String CHILD_ENABLED_WHEN = "enabledWhen"; //$NON-NLS-1$;
067:
068: private Collection pages = new ArrayList();
069:
070: private PropertyPageContributorManager manager;
071:
072: class PropertyCategoryNode extends CategoryNode {
073:
074: RegistryPageContributor page;
075:
076: /**
077: * Create a new category node on the given reader for the property page.
078: *
079: * @param reader
080: * @param propertyPage
081: */
082: PropertyCategoryNode(CategorizedPageRegistryReader reader,
083: RegistryPageContributor propertyPage) {
084: super (reader);
085: page = propertyPage;
086: }
087:
088: /*
089: * (non-Javadoc)
090: *
091: * @see org.eclipse.ui.internal.registry.CategorizedPageRegistryReader.CategoryNode#getLabelText()
092: */
093: String getLabelText() {
094: return page.getPageName();
095: }
096:
097: /*
098: * (non-Javadoc)
099: *
100: * @see org.eclipse.ui.internal.registry.CategorizedPageRegistryReader.CategoryNode#getLabelText(java.lang.Object)
101: */
102: String getLabelText(Object 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 getNode() {
112: return page;
113: }
114: }
115:
116: /**
117: * The constructor.
118: *
119: * @param manager
120: * the manager
121: */
122: public PropertyPagesRegistryReader(
123: PropertyPageContributorManager manager) {
124: this .manager = manager;
125: }
126:
127: /**
128: * Reads static property page specification.
129: */
130: private void processPageElement(IConfigurationElement element) {
131: String pageId = element
132: .getAttribute(IWorkbenchRegistryConstants.ATT_ID);
133:
134: if (pageId == null) {
135: logMissingAttribute(element,
136: IWorkbenchRegistryConstants.ATT_ID);
137: return;
138: }
139:
140: RegistryPageContributor contributor = new RegistryPageContributor(
141: pageId, element);
142:
143: String pageClassName = getClassValue(element,
144: IWorkbenchRegistryConstants.ATT_CLASS);
145: if (pageClassName == null) {
146: logMissingAttribute(element,
147: IWorkbenchRegistryConstants.ATT_CLASS);
148: return;
149: }
150: if (element.getAttribute(ATT_OBJECTCLASS) == null) {
151: pages.add(contributor);
152: manager.registerContributor(contributor, Object.class
153: .getName());
154: } else {
155: List objectClassNames = new ArrayList();
156: objectClassNames.add(element.getAttribute(ATT_OBJECTCLASS));
157: registerContributors(contributor, objectClassNames);
158: }
159: }
160:
161: /**
162: * Register the contributor for all of the relevant classes.
163: *
164: * @param contributor
165: * @param objectClassNames
166: */
167: private void registerContributors(
168: RegistryPageContributor contributor, List objectClassNames) {
169:
170: pages.add(contributor);
171: for (Iterator iter = objectClassNames.iterator(); iter
172: .hasNext();) {
173: manager.registerContributor(contributor, (String) iter
174: .next());
175: }
176:
177: }
178:
179: /**
180: * Reads the next contribution element.
181: *
182: * public for dynamic UI
183: */
184: public boolean readElement(IConfigurationElement element) {
185: if (element.getName().equals(TAG_PAGE)) {
186: processPageElement(element);
187: readElementChildren(element);
188: return true;
189: }
190: if (element.getName().equals(TAG_FILTER)) {
191: return true;
192: }
193:
194: if (element.getName().equals(CHILD_ENABLED_WHEN)) {
195: return true;
196: }
197:
198: if (element.getName().equals(TAG_KEYWORD_REFERENCE)) {
199: return true;
200: }
201:
202: return false;
203: }
204:
205: /**
206: * Reads all occurances of propertyPages extension in the registry.
207: *
208: * @param registry
209: * the registry
210: */
211: public void registerPropertyPages(IExtensionRegistry registry) {
212: readRegistry(registry, PlatformUI.PLUGIN_ID,
213: IWorkbenchRegistryConstants.PL_PROPERTY_PAGES);
214: processNodes();
215: }
216:
217: /*
218: * (non-Javadoc)
219: *
220: * @see org.eclipse.ui.internal.registry.CategorizedPageRegistryReader#add(java.lang.Object,
221: * java.lang.Object)
222: */
223: void add(Object parent, Object node) {
224: ((RegistryPageContributor) parent)
225: .addSubPage((RegistryPageContributor) node);
226:
227: }
228:
229: /*
230: * (non-Javadoc)
231: *
232: * @see org.eclipse.ui.internal.registry.CategorizedPageRegistryReader#createCategoryNode(org.eclipse.ui.internal.registry.CategorizedPageRegistryReader,
233: * java.lang.Object)
234: */
235: CategoryNode createCategoryNode(
236: CategorizedPageRegistryReader reader, Object object) {
237: return new PropertyCategoryNode(reader,
238: (RegistryPageContributor) object);
239: }
240:
241: /*
242: * (non-Javadoc)
243: *
244: * @see org.eclipse.ui.internal.registry.CategorizedPageRegistryReader#findNode(java.lang.Object,
245: * java.lang.String)
246: */
247: Object findNode(Object parent, String currentToken) {
248: return ((RegistryPageContributor) parent)
249: .getChild(currentToken);
250: }
251:
252: /*
253: * (non-Javadoc)
254: *
255: * @see org.eclipse.ui.internal.registry.CategorizedPageRegistryReader#findNode(java.lang.String)
256: */
257: Object findNode(String id) {
258: Iterator iterator = pages.iterator();
259: while (iterator.hasNext()) {
260: RegistryPageContributor next = (RegistryPageContributor) iterator
261: .next();
262: if (next.getPageId().equals(id))
263: return next;
264: }
265: return null;
266: }
267:
268: /*
269: * (non-Javadoc)
270: *
271: * @see org.eclipse.ui.internal.registry.CategorizedPageRegistryReader#getCategory(java.lang.Object)
272: */
273: String getCategory(Object node) {
274: return ((RegistryPageContributor) node).getCategory();
275: }
276:
277: /*
278: * (non-Javadoc)
279: *
280: * @see org.eclipse.ui.internal.registry.CategorizedPageRegistryReader#getFavoriteNodeId()
281: */
282: String getFavoriteNodeId() {
283: return null;// properties do not support favorites
284: }
285:
286: /*
287: * (non-Javadoc)
288: *
289: * @see org.eclipse.ui.internal.registry.CategorizedPageRegistryReader#getNodes()
290: */
291: Collection getNodes() {
292: return pages;
293: }
294: }
|