1 11 package org.eclipse.ui.internal.editors.text; 12 13 import org.osgi.framework.BundleContext; 14 15 import org.eclipse.core.runtime.Assert; 16 import org.eclipse.core.runtime.IStatus; 17 import org.eclipse.core.runtime.MultiStatus; 18 import org.eclipse.core.runtime.Status; 19 20 import org.eclipse.jface.util.IPropertyChangeListener; 21 import org.eclipse.jface.util.PropertyChangeEvent; 22 23 import org.eclipse.jface.text.source.ISharedTextColors; 24 25 import org.eclipse.ui.editors.text.EditorsUI; 26 27 import org.eclipse.ui.PlatformUI; 28 import org.eclipse.ui.internal.texteditor.AnnotationTypeHierarchy; 29 import org.eclipse.ui.plugin.AbstractUIPlugin; 30 import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants; 31 import org.eclipse.ui.texteditor.AnnotationPreferenceLookup; 32 import org.eclipse.ui.texteditor.AnnotationTypeLookup; 33 import org.eclipse.ui.texteditor.HyperlinkDetectorRegistry; 34 import org.eclipse.ui.texteditor.MarkerAnnotationPreferences; 35 import org.eclipse.ui.texteditor.spelling.SpellingService; 36 import org.eclipse.ui.themes.IThemeManager; 37 38 44 public class EditorsPlugin extends AbstractUIPlugin { 45 private static EditorsPlugin fgInstance; 46 47 public static EditorsPlugin getDefault() { 48 return fgInstance; 49 } 50 51 public static void log(IStatus status) { 52 getDefault().getLog().log(status); 53 } 54 55 public static void logErrorMessage(String message) { 56 if (message == null) 57 message= ""; log(new Status(IStatus.ERROR, EditorsUI.PLUGIN_ID, IEditorsStatusConstants.INTERNAL_ERROR, message, null)); 59 } 60 61 public static void logErrorStatus(String message, IStatus status) { 62 if (status == null) { 63 logErrorMessage(message); 64 return; 65 } 66 MultiStatus multi= new MultiStatus(EditorsUI.PLUGIN_ID, IEditorsStatusConstants.INTERNAL_ERROR, message, null); 67 multi.add(status); 68 log(multi); 69 } 70 71 public static void log(Throwable e) { 72 log(new Status(IStatus.ERROR, EditorsUI.PLUGIN_ID, IEditorsStatusConstants.INTERNAL_ERROR, TextEditorMessages.EditorsPlugin_internal_error, e)); 73 } 74 75 76 private ISharedTextColors fSharedTextColors; 77 private AnnotationTypeLookup fAnnotationTypeLookup; 78 private AnnotationPreferenceLookup fAnnotationPreferenceLookup; 79 private AnnotationTypeHierarchy fAnnotationTypeHierarchy; 80 private MarkerAnnotationPreferences fMarkerAnnotationPreferences; 81 85 private IPropertyChangeListener fThemeListener; 86 87 91 private SpellingService fSpellingService; 92 93 97 private HyperlinkDetectorRegistry fHyperlinkDetectorRegistry; 98 99 public EditorsPlugin() { 100 Assert.isTrue(fgInstance == null); 101 fgInstance= this; 102 } 103 104 110 public ISharedTextColors getSharedTextColors() { 111 if (fSharedTextColors == null) 112 fSharedTextColors= new SharedTextColors(); 113 return fSharedTextColors; 114 } 115 116 122 public AnnotationTypeLookup getAnnotationTypeLookup() { 123 if (fAnnotationTypeLookup == null) 124 fAnnotationTypeLookup= new AnnotationTypeLookup(); 125 return fAnnotationTypeLookup; 126 } 127 128 134 public AnnotationPreferenceLookup getAnnotationPreferenceLookup() { 135 if (fAnnotationPreferenceLookup == null) 136 fAnnotationPreferenceLookup= new AnnotationPreferenceLookup(); 137 return fAnnotationPreferenceLookup; 138 } 139 140 146 public AnnotationTypeHierarchy getAnnotationTypeHierarchy() { 147 if (fAnnotationTypeHierarchy == null) 148 fAnnotationTypeHierarchy= new AnnotationTypeHierarchy(); 149 return fAnnotationTypeHierarchy; 150 } 151 152 161 public synchronized void setMarkerAnnotationPreferences(MarkerAnnotationPreferences markerAnnotationPreferences) { 162 Assert.isTrue(fMarkerAnnotationPreferences == null); 163 fMarkerAnnotationPreferences= markerAnnotationPreferences; 164 } 165 166 172 public boolean isMarkerAnnotationPreferencesInitialized() { 173 return fMarkerAnnotationPreferences != null; 174 } 175 176 182 public synchronized MarkerAnnotationPreferences getMarkerAnnotationPreferences() { 183 if (!isMarkerAnnotationPreferencesInitialized()) 184 new MarkerAnnotationPreferences().getAnnotationPreferences(); return fMarkerAnnotationPreferences; 186 } 187 188 192 public void start(BundleContext context) throws Exception { 193 super.start(context); 194 195 if (PlatformUI.isWorkbenchRunning()) { 196 fThemeListener= new IPropertyChangeListener() { 197 public void propertyChange(PropertyChangeEvent event) { 198 if (IThemeManager.CHANGE_CURRENT_THEME.equals(event.getProperty())) 199 AbstractDecoratedTextEditorPreferenceConstants.initializeDefaultValues(getPreferenceStore()); 200 } 201 }; 202 PlatformUI.getWorkbench().getThemeManager().addPropertyChangeListener(fThemeListener); 203 } 204 } 205 206 210 public void stop(BundleContext context) throws Exception { 211 if (fSharedTextColors != null) { 212 fSharedTextColors.dispose(); 213 fSharedTextColors= null; 214 } 215 216 if (fThemeListener != null) { 217 if (PlatformUI.isWorkbenchRunning()) 218 PlatformUI.getWorkbench().getThemeManager().removePropertyChangeListener(fThemeListener); 219 fThemeListener= null; 220 } 221 222 fAnnotationTypeLookup= null; 223 fAnnotationPreferenceLookup= null; 224 fAnnotationTypeHierarchy= null; 225 fMarkerAnnotationPreferences= null; 226 fHyperlinkDetectorRegistry= null; 227 228 super.stop(context); 229 } 230 231 237 public SpellingService getSpellingService() { 238 if (fSpellingService == null) 239 fSpellingService= new SpellingService(getPreferenceStore()); 240 return fSpellingService; 241 } 242 243 251 public synchronized HyperlinkDetectorRegistry getHyperlinkDetectorRegistry() { 252 if (fHyperlinkDetectorRegistry == null) 253 fHyperlinkDetectorRegistry= new HyperlinkDetectorRegistry(getPreferenceStore()); 254 return fHyperlinkDetectorRegistry; 255 } 256 } 257 | Popular Tags |