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.decorators;
011:
012: import java.util.ArrayList;
013: import java.util.Collection;
014: import java.util.HashSet;
015:
016: import org.eclipse.core.runtime.IConfigurationElement;
017: import org.eclipse.core.runtime.IExtensionRegistry;
018: import org.eclipse.ui.PlatformUI;
019: import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
020: import org.eclipse.ui.internal.registry.RegistryReader;
021:
022: /**
023: * The DecoratorRegistryReader is the class that reads the
024: * decorator descriptions from the registry
025: */
026: public class DecoratorRegistryReader extends RegistryReader {
027:
028: //The registry values are the ones read from the registry
029: private Collection values = new ArrayList();
030:
031: private Collection ids = new HashSet();
032:
033: /**
034: * Constructor for DecoratorRegistryReader.
035: */
036: public DecoratorRegistryReader() {
037: super ();
038: }
039:
040: /*
041: * @see RegistryReader#readElement(IConfigurationElement)
042: */
043: public boolean readElement(IConfigurationElement element) {
044:
045: DecoratorDefinition desc = getDecoratorDefinition(element);
046:
047: if (desc == null) {
048: return false;
049: }
050:
051: values.add(desc);
052:
053: return true;
054:
055: }
056:
057: /**
058: * Return the DecoratorDefinition defined by element or <code>null</code>
059: * if it cannot be determined.
060: * @param element
061: * @return DecoratorDefinition
062: */
063: DecoratorDefinition getDecoratorDefinition(
064: IConfigurationElement element) {
065:
066: String id = element
067: .getAttribute(IWorkbenchRegistryConstants.ATT_ID);
068: if (ids.contains(id)) {
069: logDuplicateId(element);
070: return null;
071: }
072: ids.add(id);
073:
074: boolean noClass = element
075: .getAttribute(DecoratorDefinition.ATT_CLASS) == null;
076:
077: //Lightweight or Full? It is lightweight if it is declared lightweight or if there is no class
078: if (Boolean
079: .valueOf(
080: element
081: .getAttribute(IWorkbenchRegistryConstants.ATT_LIGHTWEIGHT))
082: .booleanValue()
083: || noClass) {
084:
085: String iconPath = element
086: .getAttribute(LightweightDecoratorDefinition.ATT_ICON);
087:
088: if (noClass && iconPath == null) {
089: logMissingElement(element,
090: LightweightDecoratorDefinition.ATT_ICON);
091: return null;
092: }
093:
094: return new LightweightDecoratorDefinition(id, element);
095: }
096: return new FullDecoratorDefinition(id, element);
097:
098: }
099:
100: /**
101: * Read the decorator extensions within a registry and set
102: * up the registry values.
103: */
104: Collection readRegistry(IExtensionRegistry in) {
105: values.clear();
106: ids.clear();
107: readRegistry(in, PlatformUI.PLUGIN_ID,
108: IWorkbenchRegistryConstants.PL_DECORATORS);
109: return values;
110: }
111:
112: /**
113: * Return the values.
114: *
115: * @return the values
116: */
117: public Collection getValues() {
118: return values;
119: }
120:
121: /**
122: * Logs a registry error when the configuration element is unknown.
123: */
124: protected void logDuplicateId(IConfigurationElement element) {
125: logError(
126: element,
127: "Duplicate id found: " + element.getAttribute(IWorkbenchRegistryConstants.ATT_ID));//$NON-NLS-1$
128: }
129:
130: }
|