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.texteditor;
011:
012: import java.util.HashSet;
013: import java.util.Set;
014:
015: import org.eclipse.swt.graphics.RGB;
016:
017: import org.eclipse.jface.resource.ImageDescriptor;
018:
019: import org.eclipse.jface.text.source.IAnnotationAccessExtension;
020: import org.eclipse.ui.texteditor.AnnotationPreference;
021: import org.eclipse.ui.texteditor.AnnotationPreferenceLookup;
022: import org.eclipse.ui.texteditor.IAnnotationImageProvider;
023:
024: public class DelegatingAnnotationPreference extends
025: AnnotationPreference {
026:
027: private AnnotationType fType;
028: private AnnotationPreferenceLookup fLookup;
029: private Set fCache = new HashSet();
030:
031: public DelegatingAnnotationPreference(AnnotationType type,
032: AnnotationPreferenceLookup lookup) {
033: fType = type;
034: fLookup = lookup;
035: }
036:
037: private boolean isCached(Object attribute) {
038: return fCache.contains(attribute);
039: }
040:
041: private void markCached(Object attribute) {
042: fCache.add(attribute);
043: }
044:
045: private AnnotationPreference getDefiningPreference(Object attribute) {
046:
047: AnnotationPreference p = fLookup
048: .getAnnotationPreferenceFragment(fType.getType());
049: if (p != null && p.hasValue(attribute))
050: return p;
051:
052: String[] super Types = fType.getSuperTypes();
053: for (int i = 0; i < super Types.length; i++) {
054: p = fLookup.getAnnotationPreferenceFragment(super Types[i]);
055: if (p != null && p.hasValue(attribute))
056: return p;
057: }
058:
059: return null;
060: }
061:
062: private Object getAttributeValue(Object attribute) {
063: if (!isCached(attribute)) {
064: AnnotationPreference preference = getDefiningPreference(attribute);
065: if (preference != null)
066: setValue(attribute, preference.getValue(attribute));
067: markCached(attribute);
068: }
069: return getValue(attribute);
070: }
071:
072: private boolean getBooleanAttributeValue(Object attribute) {
073: Object value = getAttributeValue(attribute);
074: if (value instanceof Boolean)
075: return ((Boolean) value).booleanValue();
076: return false;
077: }
078:
079: /*
080: * @see org.eclipse.ui.texteditor.AnnotationPreference#getAnnotationType()
081: */
082: public Object getAnnotationType() {
083: return fType.getType();
084: }
085:
086: /*
087: * @see org.eclipse.ui.texteditor.AnnotationPreference#contributesToHeader()
088: */
089: public boolean contributesToHeader() {
090: return getBooleanAttributeValue(HEADER_VALUE);
091: }
092:
093: /*
094: * @see org.eclipse.ui.texteditor.AnnotationPreference#getAnnotationImageProvider()
095: */
096: public IAnnotationImageProvider getAnnotationImageProvider() {
097: if (!isCached(IMAGE_PROVIDER)) {
098: AnnotationPreference preference = getDefiningPreference(IMAGE_PROVIDER);
099: if (preference != null) {
100: fAnnotationImageProvider = preference.fAnnotationImageProvider;
101: fAnnotationImageProviderAttribute = preference.fAnnotationImageProviderAttribute;
102: fConfigurationElement = preference.fConfigurationElement;
103: }
104: markCached(IMAGE_PROVIDER);
105: }
106: return super .getAnnotationImageProvider();
107: }
108:
109: /*
110: * @see org.eclipse.ui.texteditor.AnnotationPreference#getColorPreferenceKey()
111: */
112: public String getColorPreferenceKey() {
113: return (String) getAttributeValue(COLOR_PREFERENCE_KEY);
114: }
115:
116: /*
117: * @see org.eclipse.ui.texteditor.AnnotationPreference#getColorPreferenceValue()
118: */
119: public RGB getColorPreferenceValue() {
120: return (RGB) getAttributeValue(COLOR_PREFERENCE_VALUE);
121: }
122:
123: /*
124: * @see org.eclipse.ui.texteditor.AnnotationPreference#getHighlightPreferenceKey()
125: */
126: public String getHighlightPreferenceKey() {
127: return (String) getAttributeValue(HIGHLIGHT_PREFERENCE_KEY);
128: }
129:
130: /*
131: * @see org.eclipse.ui.texteditor.AnnotationPreference#getHighlightPreferenceValue()
132: */
133: public boolean getHighlightPreferenceValue() {
134: return getBooleanAttributeValue(HIGHLIGHT_PREFERENCE_VALUE);
135: }
136:
137: /*
138: * @see org.eclipse.ui.texteditor.AnnotationPreference#getImageDescriptor()
139: */
140: public ImageDescriptor getImageDescriptor() {
141: return (ImageDescriptor) getAttributeValue(IMAGE_DESCRIPTOR);
142: }
143:
144: /*
145: * @see org.eclipse.ui.texteditor.AnnotationPreference#getQuickFixImageDescriptor()
146: */
147: public ImageDescriptor getQuickFixImageDescriptor() {
148: return (ImageDescriptor) getAttributeValue(QUICK_FIX_IMAGE_DESCRIPTOR);
149: }
150:
151: /*
152: * @see org.eclipse.ui.texteditor.AnnotationPreference#getIsGoToNextNavigationTargetKey()
153: */
154: public String getIsGoToNextNavigationTargetKey() {
155: return (String) getAttributeValue(IS_GO_TO_NEXT_TARGET_KEY);
156: }
157:
158: /*
159: * @see org.eclipse.ui.texteditor.AnnotationPreference#getIsGoToPreviousNavigationTargetKey()
160: */
161: public String getIsGoToPreviousNavigationTargetKey() {
162: return (String) getAttributeValue(IS_GO_TO_PREVIOUS_TARGET_KEY);
163: }
164:
165: /*
166: * @see org.eclipse.ui.texteditor.AnnotationPreference#getOverviewRulerPreferenceKey()
167: */
168: public String getOverviewRulerPreferenceKey() {
169: return (String) getAttributeValue(OVERVIEW_RULER_PREFERENCE_KEY);
170: }
171:
172: /*
173: * @see org.eclipse.ui.texteditor.AnnotationPreference#getOverviewRulerPreferenceValue()
174: */
175: public boolean getOverviewRulerPreferenceValue() {
176: return getBooleanAttributeValue(OVERVIEW_RULER_PREFERENCE_VALUE);
177: }
178:
179: /*
180: * @see org.eclipse.ui.texteditor.AnnotationPreference#getPreferenceLabel()
181: */
182: public String getPreferenceLabel() {
183: return (String) getAttributeValue(PREFERENCE_LABEL);
184: }
185:
186: /*
187: * @see org.eclipse.ui.texteditor.AnnotationPreference#getPresentationLayer()
188: */
189: public int getPresentationLayer() {
190: Object value = getAttributeValue(PRESENTATION_LAYER);
191: if (value instanceof Integer)
192: return ((Integer) value).intValue();
193: return IAnnotationAccessExtension.DEFAULT_LAYER;
194: }
195:
196: /*
197: * @see org.eclipse.ui.texteditor.AnnotationPreference#getShowInNextPrevDropdownToolbarActionKey()
198: */
199: public String getShowInNextPrevDropdownToolbarActionKey() {
200: return (String) getAttributeValue(SHOW_IN_NAVIGATION_DROPDOWN_KEY);
201: }
202:
203: /*
204: * @see org.eclipse.ui.texteditor.AnnotationPreference#getSymbolicImageName()
205: */
206: public String getSymbolicImageName() {
207: return (String) getAttributeValue(SYMBOLIC_IMAGE_NAME);
208: }
209:
210: /*
211: * @see org.eclipse.ui.texteditor.AnnotationPreference#getTextPreferenceKey()
212: */
213: public String getTextPreferenceKey() {
214: return (String) getAttributeValue(TEXT_PREFERENCE_KEY);
215: }
216:
217: /*
218: * @see org.eclipse.ui.texteditor.AnnotationPreference#getTextPreferenceValue()
219: */
220: public boolean getTextPreferenceValue() {
221: return getBooleanAttributeValue(TEXT_PREFERENCE_VALUE);
222: }
223:
224: /*
225: * @see org.eclipse.ui.texteditor.AnnotationPreference#getVerticalRulerPreferenceKey()
226: */
227: public String getVerticalRulerPreferenceKey() {
228: return (String) getAttributeValue(VERTICAL_RULER_PREFERENCE_KEY);
229: }
230:
231: /*
232: * @see org.eclipse.ui.texteditor.AnnotationPreference#getVerticalRulerPreferenceValue()
233: */
234: public boolean getVerticalRulerPreferenceValue() {
235: return getBooleanAttributeValue(VERTICAL_RULER_PREFERENCE_VALUE);
236: }
237:
238: /*
239: * @see org.eclipse.ui.texteditor.AnnotationPreference#isGoToNextNavigationTarget()
240: */
241: public boolean isGoToNextNavigationTarget() {
242: return getBooleanAttributeValue(IS_GO_TO_NEXT_TARGET_VALUE);
243: }
244:
245: /*
246: * @see org.eclipse.ui.texteditor.AnnotationPreference#isGoToPreviousNavigationTarget()
247: */
248: public boolean isGoToPreviousNavigationTarget() {
249: return getBooleanAttributeValue(IS_GO_TO_PREVIOUS_TARGET_VALUE);
250: }
251:
252: /*
253: * @see org.eclipse.ui.texteditor.AnnotationPreference#isShowInNextPrevDropdownToolbarAction()
254: */
255: public boolean isShowInNextPrevDropdownToolbarAction() {
256: return getBooleanAttributeValue(SHOW_IN_NAVIGATION_DROPDOWN_VALUE);
257: }
258:
259: }
|