1 11 package org.eclipse.ui.internal.texteditor; 12 13 import java.util.HashSet ; 14 import java.util.Set ; 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 fCache= new HashSet (); 31 32 public DelegatingAnnotationPreference(AnnotationType type, AnnotationPreferenceLookup lookup) { 33 fType= type; 34 fLookup= lookup; 35 } 36 37 private boolean isCached(Object attribute) { 38 return fCache.contains(attribute); 39 } 40 41 private void markCached(Object attribute) { 42 fCache.add(attribute); 43 } 44 45 private AnnotationPreference getDefiningPreference(Object attribute) { 46 47 AnnotationPreference p= fLookup.getAnnotationPreferenceFragment(fType.getType()); 48 if (p != null && p.hasValue(attribute)) 49 return p; 50 51 String [] 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 getAttributeValue(Object 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 attribute) { 72 Object value= getAttributeValue(attribute); 73 if (value instanceof Boolean ) 74 return ((Boolean ) value).booleanValue(); 75 return false; 76 } 77 78 81 public Object getAnnotationType() { 82 return fType.getType(); 83 } 84 85 88 public boolean contributesToHeader() { 89 return getBooleanAttributeValue(HEADER_VALUE); 90 } 91 92 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 111 public String getColorPreferenceKey() { 112 return (String ) getAttributeValue(COLOR_PREFERENCE_KEY); 113 } 114 115 118 public RGB getColorPreferenceValue() { 119 return (RGB) getAttributeValue(COLOR_PREFERENCE_VALUE); 120 } 121 122 125 public String getHighlightPreferenceKey() { 126 return (String ) getAttributeValue(HIGHLIGHT_PREFERENCE_KEY); 127 } 128 129 132 public boolean getHighlightPreferenceValue() { 133 return getBooleanAttributeValue(HIGHLIGHT_PREFERENCE_VALUE); 134 } 135 136 139 public ImageDescriptor getImageDescriptor() { 140 return (ImageDescriptor) getAttributeValue(IMAGE_DESCRIPTOR); 141 } 142 143 146 public ImageDescriptor getQuickFixImageDescriptor() { 147 return (ImageDescriptor) getAttributeValue(QUICK_FIX_IMAGE_DESCRIPTOR); 148 } 149 150 153 public String getIsGoToNextNavigationTargetKey() { 154 return (String ) getAttributeValue(IS_GO_TO_NEXT_TARGET_KEY); 155 } 156 157 160 public String getIsGoToPreviousNavigationTargetKey() { 161 return (String ) getAttributeValue(IS_GO_TO_PREVIOUS_TARGET_KEY); 162 } 163 164 167 public String getOverviewRulerPreferenceKey() { 168 return (String ) getAttributeValue(OVERVIEW_RULER_PREFERENCE_KEY); 169 } 170 171 174 public boolean getOverviewRulerPreferenceValue() { 175 return getBooleanAttributeValue(OVERVIEW_RULER_PREFERENCE_VALUE); 176 } 177 178 181 public String getPreferenceLabel() { 182 return (String ) getAttributeValue(PREFERENCE_LABEL); 183 } 184 185 188 public int getPresentationLayer() { 189 Object value= getAttributeValue(PRESENTATION_LAYER); 190 if (value instanceof Integer ) 191 return ((Integer ) value).intValue(); 192 return IAnnotationAccessExtension.DEFAULT_LAYER; 193 } 194 195 198 public String getShowInNextPrevDropdownToolbarActionKey() { 199 return (String ) getAttributeValue(SHOW_IN_NAVIGATION_DROPDOWN_KEY); 200 } 201 202 205 public String getSymbolicImageName() { 206 return (String ) getAttributeValue(SYMBOLIC_IMAGE_NAME); 207 } 208 209 212 public String getTextPreferenceKey() { 213 return (String ) getAttributeValue(TEXT_PREFERENCE_KEY); 214 } 215 216 219 public boolean getTextPreferenceValue() { 220 return getBooleanAttributeValue(TEXT_PREFERENCE_VALUE); 221 } 222 223 226 public String getVerticalRulerPreferenceKey() { 227 return (String ) getAttributeValue(VERTICAL_RULER_PREFERENCE_KEY); 228 } 229 230 233 public boolean getVerticalRulerPreferenceValue() { 234 return getBooleanAttributeValue(VERTICAL_RULER_PREFERENCE_VALUE); 235 } 236 237 240 public boolean isGoToNextNavigationTarget() { 241 return getBooleanAttributeValue(IS_GO_TO_NEXT_TARGET_VALUE); 242 } 243 244 247 public boolean isGoToPreviousNavigationTarget() { 248 return getBooleanAttributeValue(IS_GO_TO_PREVIOUS_TARGET_VALUE); 249 } 250 251 254 public boolean isShowInNextPrevDropdownToolbarAction() { 255 return getBooleanAttributeValue(SHOW_IN_NAVIGATION_DROPDOWN_VALUE); 256 } 257 258 } 259 | Popular Tags |