KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > decorators > DecoratorRegistryReader


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.decorators;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.Collection JavaDoc;
15 import java.util.HashSet JavaDoc;
16
17 import org.eclipse.core.runtime.IConfigurationElement;
18 import org.eclipse.core.runtime.IExtensionRegistry;
19 import org.eclipse.ui.PlatformUI;
20 import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
21 import org.eclipse.ui.internal.registry.RegistryReader;
22
23 /**
24  * The DecoratorRegistryReader is the class that reads the
25  * decorator descriptions from the registry
26  */

27 public class DecoratorRegistryReader extends RegistryReader {
28
29     //The registry values are the ones read from the registry
30
private Collection JavaDoc values = new ArrayList JavaDoc();
31
32     private Collection JavaDoc ids = new HashSet JavaDoc();
33
34     /**
35      * Constructor for DecoratorRegistryReader.
36      */

37     public DecoratorRegistryReader() {
38         super();
39     }
40
41     /*
42      * @see RegistryReader#readElement(IConfigurationElement)
43      */

44     public boolean readElement(IConfigurationElement element) {
45
46         DecoratorDefinition desc = getDecoratorDefinition(element);
47         
48         if (desc == null) {
49             return false;
50         }
51         
52         values.add(desc);
53
54         return true;
55
56     }
57     
58     /**
59      * Return the DecoratorDefinition defined by element or <code>null</code>
60      * if it cannot be determined.
61      * @param element
62      * @return DecoratorDefinition
63      */

64     DecoratorDefinition getDecoratorDefinition(IConfigurationElement element){
65
66         String JavaDoc id = element.getAttribute(IWorkbenchRegistryConstants.ATT_ID);
67         if (ids.contains(id)) {
68             logDuplicateId(element);
69             return null;
70         }
71         ids.add(id);
72
73         boolean noClass = element.getAttribute(DecoratorDefinition.ATT_CLASS) == null;
74
75         //Lightweight or Full? It is lightweight if it is declared lightweight or if there is no class
76
if (Boolean.valueOf(element.getAttribute(IWorkbenchRegistryConstants.ATT_LIGHTWEIGHT)).booleanValue() || noClass) {
77
78             String JavaDoc iconPath = element.getAttribute(LightweightDecoratorDefinition.ATT_ICON);
79
80             if (noClass && iconPath == null) {
81                 logMissingElement(element, LightweightDecoratorDefinition.ATT_ICON);
82                 return null;
83             }
84
85             return new LightweightDecoratorDefinition(id, element);
86         }
87         return new FullDecoratorDefinition(id, element);
88         
89     }
90
91     /**
92      * Read the decorator extensions within a registry and set
93      * up the registry values.
94      */

95     Collection JavaDoc readRegistry(IExtensionRegistry in) {
96         values.clear();
97         ids.clear();
98         readRegistry(in, PlatformUI.PLUGIN_ID,
99                 IWorkbenchRegistryConstants.PL_DECORATORS);
100         return values;
101     }
102
103     /**
104      * Return the values.
105      *
106      * @return the values
107      */

108     public Collection JavaDoc getValues() {
109         return values;
110     }
111
112     /**
113      * Logs a registry error when the configuration element is unknown.
114      */

115     protected void logDuplicateId(IConfigurationElement element) {
116         logError(element, "Duplicate id found: " + element.getAttribute(IWorkbenchRegistryConstants.ATT_ID));//$NON-NLS-1$
117
}
118
119 }
120
Popular Tags