KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > texteditor > DelegatingAnnotationPreference


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.texteditor;
12
13 import java.util.HashSet JavaDoc;
14 import java.util.Set JavaDoc;
15
16 import org.eclipse.swt.graphics.RGB;
17
18 import org.eclipse.jface.resource.ImageDescriptor;
19
20 import org.eclipse.jface.text.source.IAnnotationAccessExtension;
21 import org.eclipse.ui.texteditor.AnnotationPreference;
22 import org.eclipse.ui.texteditor.AnnotationPreferenceLookup;
23 import org.eclipse.ui.texteditor.IAnnotationImageProvider;
24
25
26 public class DelegatingAnnotationPreference extends AnnotationPreference {
27
28     private AnnotationType fType;
29     private AnnotationPreferenceLookup fLookup;
30     private Set JavaDoc fCache= new HashSet JavaDoc();
31
32     public DelegatingAnnotationPreference(AnnotationType type, AnnotationPreferenceLookup lookup) {
33         fType= type;
34         fLookup= lookup;
35     }
36
37     private boolean isCached(Object JavaDoc attribute) {
38         return fCache.contains(attribute);
39     }
40
41     private void markCached(Object JavaDoc attribute) {
42         fCache.add(attribute);
43     }
44
45     private AnnotationPreference getDefiningPreference(Object JavaDoc attribute) {
46
47         AnnotationPreference p= fLookup.getAnnotationPreferenceFragment(fType.getType());
48         if (p != null && p.hasValue(attribute))
49             return p;
50
51         String JavaDoc[] superTypes= fType.getSuperTypes();
52         for (int i= 0; i < superTypes.length; i++) {
53             p= fLookup.getAnnotationPreferenceFragment(superTypes[i]);
54             if (p != null && p.hasValue(attribute))
55                 return p;
56         }
57
58         return null;
59     }
60
61     private Object JavaDoc getAttributeValue(Object JavaDoc attribute) {
62         if (!isCached(attribute)) {
63             AnnotationPreference preference= getDefiningPreference(attribute);
64             if (preference != null)
65                 setValue(attribute, preference.getValue(attribute));
66             markCached(attribute);
67         }
68         return getValue(attribute);
69     }
70
71     private boolean getBooleanAttributeValue(Object JavaDoc attribute) {
72         Object JavaDoc value= getAttributeValue(attribute);
73         if (value instanceof Boolean JavaDoc)
74             return ((Boolean JavaDoc) value).booleanValue();
75         return false;
76     }
77
78     /*
79      * @see org.eclipse.ui.texteditor.AnnotationPreference#getAnnotationType()
80      */

81     public Object JavaDoc getAnnotationType() {
82         return fType.getType();
83     }
84
85     /*
86      * @see org.eclipse.ui.texteditor.AnnotationPreference#contributesToHeader()
87      */

88     public boolean contributesToHeader() {
89         return getBooleanAttributeValue(HEADER_VALUE);
90     }
91
92     /*
93      * @see org.eclipse.ui.texteditor.AnnotationPreference#getAnnotationImageProvider()
94      */

95     public IAnnotationImageProvider getAnnotationImageProvider() {
96         if (!isCached(IMAGE_PROVIDER)) {
97             AnnotationPreference preference= getDefiningPreference(IMAGE_PROVIDER);
98             if (preference != null) {
99                 fAnnotationImageProvider= preference.fAnnotationImageProvider;
100                 fAnnotationImageProviderAttribute= preference.fAnnotationImageProviderAttribute;
101                 fConfigurationElement= preference.fConfigurationElement;
102             }
103             markCached(IMAGE_PROVIDER);
104         }
105         return super.getAnnotationImageProvider();
106     }
107
108     /*
109      * @see org.eclipse.ui.texteditor.AnnotationPreference#getColorPreferenceKey()
110      */

111     public String JavaDoc getColorPreferenceKey() {
112         return (String JavaDoc) getAttributeValue(COLOR_PREFERENCE_KEY);
113     }
114
115     /*
116      * @see org.eclipse.ui.texteditor.AnnotationPreference#getColorPreferenceValue()
117      */

118     public RGB getColorPreferenceValue() {
119         return (RGB) getAttributeValue(COLOR_PREFERENCE_VALUE);
120     }
121
122     /*
123      * @see org.eclipse.ui.texteditor.AnnotationPreference#getHighlightPreferenceKey()
124      */

125     public String JavaDoc getHighlightPreferenceKey() {
126         return (String JavaDoc) getAttributeValue(HIGHLIGHT_PREFERENCE_KEY);
127     }
128
129     /*
130      * @see org.eclipse.ui.texteditor.AnnotationPreference#getHighlightPreferenceValue()
131      */

132     public boolean getHighlightPreferenceValue() {
133         return getBooleanAttributeValue(HIGHLIGHT_PREFERENCE_VALUE);
134     }
135
136     /*
137      * @see org.eclipse.ui.texteditor.AnnotationPreference#getImageDescriptor()
138      */

139     public ImageDescriptor getImageDescriptor() {
140         return (ImageDescriptor) getAttributeValue(IMAGE_DESCRIPTOR);
141     }
142     
143     /*
144      * @see org.eclipse.ui.texteditor.AnnotationPreference#getQuickFixImageDescriptor()
145      */

146     public ImageDescriptor getQuickFixImageDescriptor() {
147         return (ImageDescriptor) getAttributeValue(QUICK_FIX_IMAGE_DESCRIPTOR);
148     }
149
150     /*
151      * @see org.eclipse.ui.texteditor.AnnotationPreference#getIsGoToNextNavigationTargetKey()
152      */

153     public String JavaDoc getIsGoToNextNavigationTargetKey() {
154         return (String JavaDoc) getAttributeValue(IS_GO_TO_NEXT_TARGET_KEY);
155     }
156
157     /*
158      * @see org.eclipse.ui.texteditor.AnnotationPreference#getIsGoToPreviousNavigationTargetKey()
159      */

160     public String JavaDoc getIsGoToPreviousNavigationTargetKey() {
161         return (String JavaDoc) getAttributeValue(IS_GO_TO_PREVIOUS_TARGET_KEY);
162     }
163
164     /*
165      * @see org.eclipse.ui.texteditor.AnnotationPreference#getOverviewRulerPreferenceKey()
166      */

167     public String JavaDoc getOverviewRulerPreferenceKey() {
168         return (String JavaDoc) getAttributeValue(OVERVIEW_RULER_PREFERENCE_KEY);
169     }
170
171     /*
172      * @see org.eclipse.ui.texteditor.AnnotationPreference#getOverviewRulerPreferenceValue()
173      */

174     public boolean getOverviewRulerPreferenceValue() {
175         return getBooleanAttributeValue(OVERVIEW_RULER_PREFERENCE_VALUE);
176     }
177
178     /*
179      * @see org.eclipse.ui.texteditor.AnnotationPreference#getPreferenceLabel()
180      */

181     public String JavaDoc getPreferenceLabel() {
182         return (String JavaDoc) getAttributeValue(PREFERENCE_LABEL);
183     }
184
185     /*
186      * @see org.eclipse.ui.texteditor.AnnotationPreference#getPresentationLayer()
187      */

188     public int getPresentationLayer() {
189         Object JavaDoc value= getAttributeValue(PRESENTATION_LAYER);
190         if (value instanceof Integer JavaDoc)
191             return ((Integer JavaDoc) value).intValue();
192         return IAnnotationAccessExtension.DEFAULT_LAYER;
193     }
194
195     /*
196      * @see org.eclipse.ui.texteditor.AnnotationPreference#getShowInNextPrevDropdownToolbarActionKey()
197      */

198     public String JavaDoc getShowInNextPrevDropdownToolbarActionKey() {
199         return (String JavaDoc) getAttributeValue(SHOW_IN_NAVIGATION_DROPDOWN_KEY);
200     }
201
202     /*
203      * @see org.eclipse.ui.texteditor.AnnotationPreference#getSymbolicImageName()
204      */

205     public String JavaDoc getSymbolicImageName() {
206         return (String JavaDoc) getAttributeValue(SYMBOLIC_IMAGE_NAME);
207     }
208
209     /*
210      * @see org.eclipse.ui.texteditor.AnnotationPreference#getTextPreferenceKey()
211      */

212     public String JavaDoc getTextPreferenceKey() {
213         return (String JavaDoc) getAttributeValue(TEXT_PREFERENCE_KEY);
214     }
215
216     /*
217      * @see org.eclipse.ui.texteditor.AnnotationPreference#getTextPreferenceValue()
218      */

219     public boolean getTextPreferenceValue() {
220         return getBooleanAttributeValue(TEXT_PREFERENCE_VALUE);
221     }
222
223     /*
224      * @see org.eclipse.ui.texteditor.AnnotationPreference#getVerticalRulerPreferenceKey()
225      */

226     public String JavaDoc getVerticalRulerPreferenceKey() {
227         return (String JavaDoc) getAttributeValue(VERTICAL_RULER_PREFERENCE_KEY);
228     }
229
230     /*
231      * @see org.eclipse.ui.texteditor.AnnotationPreference#getVerticalRulerPreferenceValue()
232      */

233     public boolean getVerticalRulerPreferenceValue() {
234         return getBooleanAttributeValue(VERTICAL_RULER_PREFERENCE_VALUE);
235     }
236
237     /*
238      * @see org.eclipse.ui.texteditor.AnnotationPreference#isGoToNextNavigationTarget()
239      */

240     public boolean isGoToNextNavigationTarget() {
241         return getBooleanAttributeValue(IS_GO_TO_NEXT_TARGET_VALUE);
242     }
243
244     /*
245      * @see org.eclipse.ui.texteditor.AnnotationPreference#isGoToPreviousNavigationTarget()
246      */

247     public boolean isGoToPreviousNavigationTarget() {
248         return getBooleanAttributeValue(IS_GO_TO_PREVIOUS_TARGET_VALUE);
249     }
250
251     /*
252      * @see org.eclipse.ui.texteditor.AnnotationPreference#isShowInNextPrevDropdownToolbarAction()
253      */

254     public boolean isShowInNextPrevDropdownToolbarAction() {
255         return getBooleanAttributeValue(SHOW_IN_NAVIGATION_DROPDOWN_VALUE);
256     }
257
258 }
259
Popular Tags