KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > JavaPlugin


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.jdt.internal.ui;
12
13
14 import java.io.IOException JavaDoc;
15 import java.util.LinkedHashMap JavaDoc;
16
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.core.runtime.IConfigurationElement;
19 import org.eclipse.core.runtime.IProgressMonitor;
20 import org.eclipse.core.runtime.IStatus;
21 import org.eclipse.core.runtime.MultiStatus;
22 import org.eclipse.core.runtime.Status;
23
24 import org.eclipse.core.resources.IFile;
25 import org.eclipse.core.resources.IResource;
26 import org.eclipse.core.resources.IWorkspace;
27 import org.eclipse.core.resources.ResourcesPlugin;
28
29 import org.eclipse.swt.widgets.Display;
30 import org.eclipse.swt.widgets.Shell;
31
32 import org.eclipse.jface.action.GroupMarker;
33 import org.eclipse.jface.action.IMenuManager;
34 import org.eclipse.jface.action.Separator;
35 import org.eclipse.jface.dialogs.IDialogSettings;
36 import org.eclipse.jface.preference.IPreferenceStore;
37 import org.eclipse.jface.preference.PreferenceConverter;
38 import org.eclipse.jface.resource.ImageRegistry;
39 import org.eclipse.jface.resource.JFaceResources;
40 import org.eclipse.jface.util.IPropertyChangeListener;
41 import org.eclipse.jface.util.PropertyChangeEvent;
42
43 import org.eclipse.jface.text.templates.ContextTypeRegistry;
44 import org.eclipse.jface.text.templates.persistence.TemplateStore;
45
46 import org.eclipse.ui.IEditorPart;
47 import org.eclipse.ui.IWorkbenchPage;
48 import org.eclipse.ui.IWorkbenchWindow;
49 import org.eclipse.ui.PlatformUI;
50 import org.eclipse.ui.navigator.ICommonMenuConstants;
51 import org.eclipse.ui.plugin.AbstractUIPlugin;
52 import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
53 import org.eclipse.ui.texteditor.ChainedPreferenceStore;
54 import org.eclipse.ui.texteditor.ConfigurationElementSorter;
55 import org.eclipse.ui.texteditor.IDocumentProvider;
56 import org.eclipse.ui.themes.IThemeManager;
57
58 import org.eclipse.ui.editors.text.EditorsUI;
59 import org.eclipse.ui.editors.text.templates.ContributionContextTypeRegistry;
60 import org.eclipse.ui.editors.text.templates.ContributionTemplateStore;
61
62 import org.eclipse.ui.forms.FormColors;
63 import org.eclipse.ui.forms.widgets.FormToolkit;
64
65 import org.eclipse.jdt.core.IBuffer;
66 import org.eclipse.jdt.core.ICompilationUnit;
67 import org.eclipse.jdt.core.JavaCore;
68 import org.eclipse.jdt.core.WorkingCopyOwner;
69 import org.eclipse.jdt.core.manipulation.JavaManipulation;
70
71 import org.eclipse.jdt.internal.corext.javadoc.JavaDocLocations;
72 import org.eclipse.jdt.internal.corext.template.java.CodeTemplateContextType;
73 import org.eclipse.jdt.internal.corext.template.java.JavaContextType;
74 import org.eclipse.jdt.internal.corext.template.java.JavaDocContextType;
75 import org.eclipse.jdt.internal.corext.util.OpenTypeHistory;
76 import org.eclipse.jdt.internal.corext.util.QualifiedTypeNameHistory;
77 import org.eclipse.jdt.internal.corext.util.TypeFilter;
78
79 import org.eclipse.jdt.ui.IContextMenuConstants;
80 import org.eclipse.jdt.ui.JavaUI;
81 import org.eclipse.jdt.ui.PreferenceConstants;
82 import org.eclipse.jdt.ui.text.JavaTextTools;
83
84 import org.eclipse.jdt.internal.ui.javaeditor.ASTProvider;
85 import org.eclipse.jdt.internal.ui.javaeditor.ClassFileDocumentProvider;
86 import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitDocumentProvider;
87 import org.eclipse.jdt.internal.ui.javaeditor.DocumentAdapter;
88 import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
89 import org.eclipse.jdt.internal.ui.javaeditor.ICompilationUnitDocumentProvider;
90 import org.eclipse.jdt.internal.ui.javaeditor.WorkingCopyManager;
91 import org.eclipse.jdt.internal.ui.javaeditor.saveparticipant.SaveParticipantRegistry;
92 import org.eclipse.jdt.internal.ui.preferences.MembersOrderPreferenceCache;
93 import org.eclipse.jdt.internal.ui.preferences.formatter.FormatterProfileStore;
94 import org.eclipse.jdt.internal.ui.propertiesfileeditor.PropertiesFileDocumentProvider;
95 import org.eclipse.jdt.internal.ui.text.PreferencesAdapter;
96 import org.eclipse.jdt.internal.ui.text.folding.JavaFoldingStructureProviderRegistry;
97 import org.eclipse.jdt.internal.ui.text.java.ContentAssistHistory;
98 import org.eclipse.jdt.internal.ui.text.java.hover.JavaEditorTextHoverDescriptor;
99 import org.eclipse.jdt.internal.ui.text.spelling.SpellCheckEngine;
100 import org.eclipse.jdt.internal.ui.viewsupport.ImageDescriptorRegistry;
101 import org.eclipse.jdt.internal.ui.viewsupport.ProblemMarkerManager;
102 import org.eclipse.jdt.internal.ui.wizards.buildpaths.ClasspathAttributeConfigurationDescriptors;
103
104 import org.osgi.framework.BundleContext;
105
106 /**
107  * Represents the java plug-in. It provides a series of convenience methods such as
108  * access to the workbench, keeps track of elements shared by all editors and viewers
109  * of the plug-in such as document providers and find-replace-dialogs.
110  */

111 public class JavaPlugin extends AbstractUIPlugin {
112     
113     /**
114      * The key to store customized templates.
115      * @since 3.0
116      */

117     private static final String JavaDoc TEMPLATES_KEY= "org.eclipse.jdt.ui.text.custom_templates"; //$NON-NLS-1$
118
/**
119      * The key to store customized code templates.
120      * @since 3.0
121      */

122     private static final String JavaDoc CODE_TEMPLATES_KEY= "org.eclipse.jdt.ui.text.custom_code_templates"; //$NON-NLS-1$
123
/**
124      * The key to store whether the legacy templates have been migrated
125      * @since 3.0
126      */

127     private static final String JavaDoc TEMPLATES_MIGRATION_KEY= "org.eclipse.jdt.ui.text.templates_migrated"; //$NON-NLS-1$
128
/**
129      * The key to store whether the legacy code templates have been migrated
130      * @since 3.0
131      */

132     private static final String JavaDoc CODE_TEMPLATES_MIGRATION_KEY= "org.eclipse.jdt.ui.text.code_templates_migrated"; //$NON-NLS-1$
133

134     private static JavaPlugin fgJavaPlugin;
135     
136     private static LinkedHashMap JavaDoc fgRepeatedMessages= new LinkedHashMap JavaDoc(20, 0.75f, true) {
137         private static final long serialVersionUID= 1L;
138         protected boolean removeEldestEntry(java.util.Map.Entry eldest) {
139             return size() >= 20;
140         }
141     };
142     
143     /**
144      * The template context type registry for the java editor.
145      * @since 3.0
146      */

147     private ContextTypeRegistry fContextTypeRegistry;
148     /**
149      * The code template context type registry for the java editor.
150      * @since 3.0
151      */

152     private ContextTypeRegistry fCodeTemplateContextTypeRegistry;
153     
154     /**
155      * The template store for the java editor.
156      * @since 3.0
157      */

158     private TemplateStore fTemplateStore;
159     /**
160      * The coded template store for the java editor.
161      * @since 3.0
162      */

163     private TemplateStore fCodeTemplateStore;
164     
165     /**
166      * Default instance of the appearance type filters.
167      * @since 3.0
168      */

169     private TypeFilter fTypeFilter;
170
171
172     private WorkingCopyManager fWorkingCopyManager;
173     
174     /**
175      * @deprecated
176      */

177     private org.eclipse.jdt.core.IBufferFactory fBufferFactory;
178     private ICompilationUnitDocumentProvider fCompilationUnitDocumentProvider;
179     private ClassFileDocumentProvider fClassFileDocumentProvider;
180     private JavaTextTools fJavaTextTools;
181     private ProblemMarkerManager fProblemMarkerManager;
182     private ImageDescriptorRegistry fImageDescriptorRegistry;
183     
184     private MembersOrderPreferenceCache fMembersOrderPreferenceCache;
185     private IPropertyChangeListener fFontPropertyChangeListener;
186     
187     /**
188      * Property change listener on this plugin's preference store.
189      *
190      * @since 3.0
191      */

192     private IPropertyChangeListener fPropertyChangeListener;
193     
194     private JavaEditorTextHoverDescriptor[] fJavaEditorTextHoverDescriptors;
195         
196     /**
197      * The AST provider.
198      * @since 3.0
199      */

200     private ASTProvider fASTProvider;
201     
202     /**
203      * The combined preference store.
204      * @since 3.0
205      */

206     private IPreferenceStore fCombinedPreferenceStore;
207     
208     /**
209      * The extension point registry for the <code>org.eclipse.jdt.ui.javaFoldingStructureProvider</code>
210      * extension point.
211      *
212      * @since 3.0
213      */

214     private JavaFoldingStructureProviderRegistry fFoldingStructureProviderRegistry;
215
216     /**
217      * The shared Java properties file document provider.
218      * @since 3.1
219      */

220     private IDocumentProvider fPropertiesFileDocumentProvider;
221
222     /**
223      * Content assist history.
224      *
225      * @since 3.2
226      */

227     private ContentAssistHistory fContentAssistHistory;
228     
229     /**
230      * The save participant registry.
231      *
232      * @since 3.3
233      */

234     private SaveParticipantRegistry fSaveParticipantRegistry;
235     
236     /**
237      * The descriptors from the 'classpathAttributeConfiguration' extension point.
238      *
239      * @since 3.3
240      */

241     private ClasspathAttributeConfigurationDescriptors fClasspathAttributeConfigurationDescriptors;
242     
243     private FormToolkit fDialogsFormToolkit;
244     
245     /**
246      * Theme listener.
247      * @since 3.3
248      */

249     private IPropertyChangeListener fThemeListener;
250
251     public static JavaPlugin getDefault() {
252         return fgJavaPlugin;
253     }
254     
255     public static IWorkspace getWorkspace() {
256         return ResourcesPlugin.getWorkspace();
257     }
258     
259     public static IWorkbenchPage getActivePage() {
260         return getDefault().internalGetActivePage();
261     }
262     
263     public static IWorkbenchWindow getActiveWorkbenchWindow() {
264         return getDefault().getWorkbench().getActiveWorkbenchWindow();
265     }
266     
267     public static Shell getActiveWorkbenchShell() {
268          IWorkbenchWindow window= getActiveWorkbenchWindow();
269          if (window != null) {
270             return window.getShell();
271          }
272          return null;
273     }
274     
275     /**
276      * @deprecated Use EditorUtility.getDirtyEditors() instead.
277      */

278     public static IEditorPart[] getDirtyEditors() {
279         return EditorUtility.getDirtyEditors();
280     }
281         
282     public static String JavaDoc getPluginId() {
283         return JavaUI.ID_PLUGIN;
284     }
285
286     public static void log(IStatus status) {
287         getDefault().getLog().log(status);
288     }
289     
290     public static void logErrorMessage(String JavaDoc message) {
291         log(new Status(IStatus.ERROR, getPluginId(), IJavaStatusConstants.INTERNAL_ERROR, message, null));
292     }
293
294     public static void logErrorStatus(String JavaDoc message, IStatus status) {
295         if (status == null) {
296             logErrorMessage(message);
297             return;
298         }
299         MultiStatus multi= new MultiStatus(getPluginId(), IJavaStatusConstants.INTERNAL_ERROR, message, null);
300         multi.add(status);
301         log(multi);
302     }
303     
304     public static void log(Throwable JavaDoc e) {
305         log(new Status(IStatus.ERROR, getPluginId(), IJavaStatusConstants.INTERNAL_ERROR, JavaUIMessages.JavaPlugin_internal_error, e));
306     }
307     
308     /**
309      * Log a message that is potentially repeated after a very short time.
310      * The first time this method is called with a given message, the
311      * message is written to the log along with the detail message and a stack trace.
312      * <p>
313      * Only intended for use in debug statements.
314      *
315      * @param message the (generic) message
316      * @param detail the detail message
317      */

318     public static void logRepeatedMessage(String JavaDoc message, String JavaDoc detail) {
319         long now= System.currentTimeMillis();
320         boolean writeToLog= true;
321         if (fgRepeatedMessages.containsKey(message)) {
322             long last= ((Long JavaDoc) fgRepeatedMessages.get(message)).longValue();
323             writeToLog= now - last > 5000;
324         }
325         fgRepeatedMessages.put(message, new Long JavaDoc(now));
326         if (writeToLog)
327             log(new Exception JavaDoc(message + detail).fillInStackTrace());
328     }
329     
330     public static boolean isDebug() {
331         return getDefault().isDebugging();
332     }
333             
334     public static ImageDescriptorRegistry getImageDescriptorRegistry() {
335         return getDefault().internalGetImageDescriptorRegistry();
336     }
337         
338     public JavaPlugin() {
339         super();
340         fgJavaPlugin = this;
341     }
342
343     /* (non - Javadoc)
344      * Method declared in plug-in
345      */

346     public void start(BundleContext context) throws Exception JavaDoc {
347         super.start(context);
348         
349         WorkingCopyOwner.setPrimaryBufferProvider(new WorkingCopyOwner() {
350             public IBuffer createBuffer(ICompilationUnit workingCopy) {
351                 ICompilationUnit original= workingCopy.getPrimary();
352                 IResource resource= original.getResource();
353                 if (resource instanceof IFile)
354                     return new DocumentAdapter(workingCopy, (IFile) resource);
355                 return DocumentAdapter.NULL;
356             }
357         });
358
359         ensurePreferenceStoreBackwardsCompatibility();
360
361         if (PlatformUI.isWorkbenchRunning()) {
362             // Initialize AST provider
363
getASTProvider();
364             new InitializeAfterLoadJob().schedule();
365             
366             fThemeListener= new IPropertyChangeListener() {
367                 public void propertyChange(PropertyChangeEvent event) {
368                     if (IThemeManager.CHANGE_CURRENT_THEME.equals(event.getProperty()))
369                         new JavaUIPreferenceInitializer().initializeDefaultPreferences();
370                 }
371             };
372             PlatformUI.getWorkbench().getThemeManager().addPropertyChangeListener(fThemeListener);
373         }
374         
375         // make sure is loaded too for org.eclipse.jdt.core.manipulation
376
// can be removed if JavaElementPropertyTester is moved down to jdt.core (bug 127085)
377
JavaManipulation.class.toString();
378     }
379
380     /* package */ static void initializeAfterLoad(IProgressMonitor monitor) {
381         OpenTypeHistory.getInstance().checkConsistency(monitor);
382     }
383     
384     /** @deprecated */
385     private static IPreferenceStore getDeprecatedWorkbenchPreferenceStore() {
386         return PlatformUI.getWorkbench().getPreferenceStore();
387     }
388     
389     /** @deprecated */
390     private static final String JavaDoc DEPRECATED_EDITOR_TAB_WIDTH= PreferenceConstants.EDITOR_TAB_WIDTH;
391     
392     /** @deprecated */
393     private static final String JavaDoc DEPRECATED_REFACTOR_ERROR_PAGE_SEVERITY_THRESHOLD= PreferenceConstants.REFACTOR_ERROR_PAGE_SEVERITY_THRESHOLD;
394     
395     /** @deprecated */
396     private static final String JavaDoc DEPRECATED_CODEASSIST_ORDER_PROPOSALS= PreferenceConstants.CODEASSIST_ORDER_PROPOSALS;
397     
398     /**
399      * Installs backwards compatibility for the preference store.
400      */

401     private void ensurePreferenceStoreBackwardsCompatibility() {
402
403         IPreferenceStore store= getPreferenceStore();
404         
405         // must add here to guarantee that it is the first in the listener list
406
fMembersOrderPreferenceCache= new MembersOrderPreferenceCache();
407         fMembersOrderPreferenceCache.install(store);
408         
409         
410         /*
411          * Installs backwards compatibility: propagate the Java editor font from a
412          * pre-2.1 plug-in to the Platform UI's preference store to preserve
413          * the Java editor font from a pre-2.1 workspace. This is done only
414          * once.
415          */

416         String JavaDoc fontPropagatedKey= "fontPropagated"; //$NON-NLS-1$
417
if (store.contains(JFaceResources.TEXT_FONT) && !store.isDefault(JFaceResources.TEXT_FONT)) {
418             if (!store.getBoolean(fontPropagatedKey))
419                 PreferenceConverter.setValue(
420                         getDeprecatedWorkbenchPreferenceStore(), PreferenceConstants.EDITOR_TEXT_FONT, PreferenceConverter.getFontDataArray(store, JFaceResources.TEXT_FONT));
421         }
422         store.setValue(fontPropagatedKey, true);
423
424         /*
425          * Backwards compatibility: set the Java editor font in this plug-in's
426          * preference store to let older versions access it. Since 2.1 the
427          * Java editor font is managed by the workbench font preference page.
428          */

429         PreferenceConverter.putValue(store, JFaceResources.TEXT_FONT, JFaceResources.getFontRegistry().getFontData(PreferenceConstants.EDITOR_TEXT_FONT));
430
431         fFontPropertyChangeListener= new IPropertyChangeListener() {
432             public void propertyChange(PropertyChangeEvent event) {
433                 if (PreferenceConstants.EDITOR_TEXT_FONT.equals(event.getProperty()))
434                     PreferenceConverter.putValue(getPreferenceStore(), JFaceResources.TEXT_FONT, JFaceResources.getFontRegistry().getFontData(PreferenceConstants.EDITOR_TEXT_FONT));
435             }
436         };
437         JFaceResources.getFontRegistry().addListener(fFontPropertyChangeListener);
438         
439         /*
440          * Backwards compatibility: propagate the Java editor tab width from a
441          * pre-3.0 plug-in to the new preference key. This is done only once.
442          */

443         final String JavaDoc oldTabWidthKey= DEPRECATED_EDITOR_TAB_WIDTH;
444         final String JavaDoc newTabWidthKey= AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH;
445         String JavaDoc tabWidthPropagatedKey= "tabWidthPropagated"; //$NON-NLS-1$
446
if (store.contains(oldTabWidthKey) && !store.isDefault(oldTabWidthKey)) {
447             if (!store.getBoolean(tabWidthPropagatedKey))
448                 store.setValue(newTabWidthKey, store.getInt(oldTabWidthKey));
449         }
450         store.setValue(tabWidthPropagatedKey, true);
451
452         /*
453          * Backwards compatibility: set the Java editor tab width in this plug-in's
454          * preference store with the old key to let older versions access it.
455          * Since 3.0 the tab width is managed by the extended text editor and
456          * uses a new key.
457          */

458         store.putValue(oldTabWidthKey, store.getString(newTabWidthKey));
459
460         fPropertyChangeListener= new IPropertyChangeListener() {
461             public void propertyChange(PropertyChangeEvent event) {
462                 if (newTabWidthKey.equals(event.getProperty())) {
463                     IPreferenceStore prefStore= getPreferenceStore();
464                     prefStore.putValue(oldTabWidthKey, prefStore.getString(newTabWidthKey));
465                 }
466             }
467         };
468         store.addPropertyChangeListener(fPropertyChangeListener);
469         
470         /*
471          * Backward compatibility for the refactoring preference key.
472          */

473 // store.setValue(
474
// PreferenceConstants.REFACTOR_ERROR_PAGE_SEVERITY_THRESHOLD,
475
// RefactoringCore.getConditionCheckingFailedSeverity());
476

477         // The commented call above triggers the eager loading of the LTK core plug-in
478
// Since the condition checking failed severity is guaranteed to be of RefactoringStatus.SEVERITY_WARNING,
479
// we directly insert the inlined value of this constant
480
store.setToDefault(DEPRECATED_REFACTOR_ERROR_PAGE_SEVERITY_THRESHOLD);
481         
482         if (!store.getBoolean(JavaDocLocations.PREF_JAVADOCLOCATIONS_MIGRATED)) {
483             JavaDocLocations.migrateToClasspathAttributes();
484         }
485         
486         FormatterProfileStore.checkCurrentOptionsVersion();
487         
488         /*
489          * Backward compatibility: migrate "alphabetic ordering" preference to point the sorter
490          * preference to the alphabetic sorter.
491          */

492         String JavaDoc proposalOrderMigrated= "proposalOrderMigrated"; //$NON-NLS-1$
493

494         if (store.contains(DEPRECATED_CODEASSIST_ORDER_PROPOSALS)) {
495             if (!store.getBoolean(proposalOrderMigrated)) {
496                 boolean alphabetic= store.getBoolean(DEPRECATED_CODEASSIST_ORDER_PROPOSALS);
497                 if (alphabetic)
498                     store.setValue(PreferenceConstants.CODEASSIST_SORTER, "org.eclipse.jdt.ui.AlphabeticSorter"); //$NON-NLS-1$
499
}
500         }
501         store.setValue(proposalOrderMigrated, true);
502
503     }
504     
505     /**
506      * Uninstalls backwards compatibility for the preference store.
507      */

508     private void uninstallPreferenceStoreBackwardsCompatibility() {
509         JFaceResources.getFontRegistry().removeListener(fFontPropertyChangeListener);
510         getPreferenceStore().removePropertyChangeListener(fPropertyChangeListener);
511     }
512     
513     /*
514      * @see org.eclipse.ui.plugin.AbstractUIPlugin#createImageRegistry()
515      */

516     protected ImageRegistry createImageRegistry() {
517         return JavaPluginImages.getImageRegistry();
518     }
519
520     /*
521      * @see org.eclipse.core.runtime.Plugin#stop
522      */

523     public void stop(BundleContext context) throws Exception JavaDoc {
524         try {
525             if (fImageDescriptorRegistry != null)
526                 fImageDescriptorRegistry.dispose();
527             
528             if (fASTProvider != null) {
529                 fASTProvider.dispose();
530                 fASTProvider= null;
531             }
532             
533             if (fWorkingCopyManager != null) {
534                 fWorkingCopyManager.shutdown();
535                 fWorkingCopyManager= null;
536             }
537             
538             if (fCompilationUnitDocumentProvider != null) {
539                 fCompilationUnitDocumentProvider.shutdown();
540                 fCompilationUnitDocumentProvider= null;
541             }
542                     
543             if (fJavaTextTools != null) {
544                 fJavaTextTools.dispose();
545                 fJavaTextTools= null;
546             }
547             
548             if (fTypeFilter != null) {
549                 fTypeFilter.dispose();
550                 fTypeFilter= null;
551             }
552             
553             if (fContentAssistHistory != null) {
554                 ContentAssistHistory.store(fContentAssistHistory, getPluginPreferences(), PreferenceConstants.CODEASSIST_LRU_HISTORY);
555                 fContentAssistHistory= null;
556             }
557             
558             uninstallPreferenceStoreBackwardsCompatibility();
559             
560             if (fTemplateStore != null) {
561                 fTemplateStore.stopListeningForPreferenceChanges();
562                 fTemplateStore= null;
563             }
564             
565             if (fCodeTemplateStore != null) {
566                 fCodeTemplateStore.stopListeningForPreferenceChanges();
567                 fCodeTemplateStore= null;
568             }
569             
570             if (fMembersOrderPreferenceCache != null) {
571                 fMembersOrderPreferenceCache.dispose();
572                 fMembersOrderPreferenceCache= null;
573             }
574             
575             if (fSaveParticipantRegistry != null) {
576                 fSaveParticipantRegistry.dispose();
577                 fSaveParticipantRegistry= null;
578             }
579             
580             if (fDialogsFormToolkit != null) {
581                 fDialogsFormToolkit.dispose();
582                 fDialogsFormToolkit= null;
583             }
584             
585             if (fThemeListener != null) {
586                 PlatformUI.getWorkbench().getThemeManager().removePropertyChangeListener(fThemeListener);
587                 fThemeListener= null;
588             }
589             
590             SpellCheckEngine.shutdownInstance();
591             
592             QualifiedTypeNameHistory.getDefault().save();
593             
594             // must add here to guarantee that it is the first in the listener list
595

596             OpenTypeHistory.shutdown();
597         } finally {
598             super.stop(context);
599         }
600     }
601         
602     private IWorkbenchPage internalGetActivePage() {
603         IWorkbenchWindow window= getWorkbench().getActiveWorkbenchWindow();
604         if (window == null)
605             return null;
606         return window.getActivePage();
607     }
608     
609     /**
610      * @deprecated
611      */

612     public synchronized org.eclipse.jdt.core.IBufferFactory getBufferFactory() {
613         if (fBufferFactory == null)
614             fBufferFactory= new org.eclipse.jdt.internal.ui.javaeditor.CustomBufferFactory();
615         return fBufferFactory;
616     }
617     
618     public synchronized ICompilationUnitDocumentProvider getCompilationUnitDocumentProvider() {
619         if (fCompilationUnitDocumentProvider == null)
620             fCompilationUnitDocumentProvider= new CompilationUnitDocumentProvider();
621         return fCompilationUnitDocumentProvider;
622     }
623     
624     /**
625      * Returns the shared document provider for Java properties files
626      * used by this plug-in instance.
627      *
628      * @return the shared document provider for Java properties files
629      * @since 3.1
630      */

631     public synchronized IDocumentProvider getPropertiesFileDocumentProvider() {
632         if (fPropertiesFileDocumentProvider == null)
633             fPropertiesFileDocumentProvider= new PropertiesFileDocumentProvider();
634         return fPropertiesFileDocumentProvider;
635     }
636     
637     public synchronized ClassFileDocumentProvider getClassFileDocumentProvider() {
638         if (fClassFileDocumentProvider == null)
639             fClassFileDocumentProvider= new ClassFileDocumentProvider();
640         return fClassFileDocumentProvider;
641     }
642
643     public synchronized WorkingCopyManager getWorkingCopyManager() {
644         if (fWorkingCopyManager == null) {
645             ICompilationUnitDocumentProvider provider= getCompilationUnitDocumentProvider();
646             fWorkingCopyManager= new WorkingCopyManager(provider);
647         }
648         return fWorkingCopyManager;
649     }
650         
651     public synchronized ProblemMarkerManager getProblemMarkerManager() {
652         if (fProblemMarkerManager == null)
653             fProblemMarkerManager= new ProblemMarkerManager();
654         return fProblemMarkerManager;
655     }
656     
657     public synchronized JavaTextTools getJavaTextTools() {
658         if (fJavaTextTools == null)
659             fJavaTextTools= new JavaTextTools(getPreferenceStore(), JavaCore.getPlugin().getPluginPreferences());
660         return fJavaTextTools;
661     }
662     
663     /**
664      * Returns the AST provider.
665      *
666      * @return the AST provider
667      * @since 3.0
668      */

669     public synchronized ASTProvider getASTProvider() {
670         if (fASTProvider == null)
671             fASTProvider= new ASTProvider();
672         
673         return fASTProvider;
674     }
675         
676     public synchronized MembersOrderPreferenceCache getMemberOrderPreferenceCache() {
677         // initialized on startup
678
return fMembersOrderPreferenceCache;
679     }
680     
681     
682     public synchronized TypeFilter getTypeFilter() {
683         if (fTypeFilter == null)
684             fTypeFilter= new TypeFilter();
685         return fTypeFilter;
686     }
687     
688     public FormToolkit getDialogsFormToolkit() {
689         if (fDialogsFormToolkit == null) {
690             FormColors colors= new FormColors(Display.getCurrent());
691             colors.setBackground(null);
692             colors.setForeground(null);
693             fDialogsFormToolkit= new FormToolkit(colors);
694         }
695         return fDialogsFormToolkit;
696     }
697
698     /**
699      * Returns all Java editor text hovers contributed to the workbench.
700      *
701      * @return an array of JavaEditorTextHoverDescriptor
702      * @since 2.1
703      */

704     public synchronized JavaEditorTextHoverDescriptor[] getJavaEditorTextHoverDescriptors() {
705         if (fJavaEditorTextHoverDescriptors == null) {
706             fJavaEditorTextHoverDescriptors= JavaEditorTextHoverDescriptor.getContributedHovers();
707             ConfigurationElementSorter sorter= new ConfigurationElementSorter() {
708                 /*
709                  * @see org.eclipse.ui.texteditor.ConfigurationElementSorter#getConfigurationElement(java.lang.Object)
710                  */

711                 public IConfigurationElement getConfigurationElement(Object JavaDoc object) {
712                     return ((JavaEditorTextHoverDescriptor)object).getConfigurationElement();
713                 }
714             };
715             sorter.sort(fJavaEditorTextHoverDescriptors);
716         
717             // Move Best Match hover to front
718
for (int i= 0; i < fJavaEditorTextHoverDescriptors.length - 1; i++) {
719                 if (PreferenceConstants.ID_BESTMATCH_HOVER.equals(fJavaEditorTextHoverDescriptors[i].getId())) {
720                     JavaEditorTextHoverDescriptor hoverDescriptor= fJavaEditorTextHoverDescriptors[i];
721                     for (int j= i; j > 0; j--)
722                         fJavaEditorTextHoverDescriptors[j]= fJavaEditorTextHoverDescriptors[j-1];
723                     fJavaEditorTextHoverDescriptors[0]= hoverDescriptor;
724                     break;
725                 }
726                 
727             }
728         }
729         
730         return fJavaEditorTextHoverDescriptors;
731     }
732
733     /**
734      * Resets the Java editor text hovers contributed to the workbench.
735      * <p>
736      * This will force a rebuild of the descriptors the next time
737      * a client asks for them.
738      * </p>
739      *
740      * @since 2.1
741      */

742     public synchronized void resetJavaEditorTextHoverDescriptors() {
743         fJavaEditorTextHoverDescriptors= null;
744     }
745
746     /**
747      * Creates the Java plug-in's standard groups for view context menus.
748      *
749      * @param menu the menu manager to be populated
750      */

751     public static void createStandardGroups(IMenuManager menu) {
752         if (!menu.isEmpty())
753             return;
754             
755         menu.add(new Separator(IContextMenuConstants.GROUP_NEW));
756         menu.add(new GroupMarker(IContextMenuConstants.GROUP_GOTO));
757         menu.add(new Separator(IContextMenuConstants.GROUP_OPEN));
758         menu.add(new GroupMarker(IContextMenuConstants.GROUP_SHOW));
759         menu.add(new Separator(ICommonMenuConstants.GROUP_EDIT));
760         menu.add(new Separator(IContextMenuConstants.GROUP_REORGANIZE));
761         menu.add(new Separator(IContextMenuConstants.GROUP_GENERATE));
762         menu.add(new Separator(IContextMenuConstants.GROUP_SEARCH));
763         menu.add(new Separator(IContextMenuConstants.GROUP_BUILD));
764         menu.add(new Separator(IContextMenuConstants.GROUP_ADDITIONS));
765         menu.add(new Separator(IContextMenuConstants.GROUP_VIEWER_SETUP));
766         menu.add(new Separator(IContextMenuConstants.GROUP_PROPERTIES));
767     }
768
769     /**
770      * Returns the template context type registry for the java plug-in.
771      *
772      * @return the template context type registry for the java plug-in
773      * @since 3.0
774      */

775     public ContextTypeRegistry getTemplateContextRegistry() {
776         if (fContextTypeRegistry == null) {
777             ContributionContextTypeRegistry registry= new ContributionContextTypeRegistry();
778             registry.addContextType(JavaContextType.NAME);
779             registry.addContextType(JavaDocContextType.NAME);
780
781             fContextTypeRegistry= registry;
782         }
783
784         return fContextTypeRegistry;
785     }
786     
787     /**
788      * Returns the template store for the java editor templates.
789      *
790      * @return the template store for the java editor templates
791      * @since 3.0
792      */

793     public TemplateStore getTemplateStore() {
794         if (fTemplateStore == null) {
795             final IPreferenceStore store= getPreferenceStore();
796             boolean alreadyMigrated= store.getBoolean(TEMPLATES_MIGRATION_KEY);
797             if (alreadyMigrated)
798                 fTemplateStore= new ContributionTemplateStore(getTemplateContextRegistry(), store, TEMPLATES_KEY);
799             else {
800                 fTemplateStore= new CompatibilityTemplateStore(getTemplateContextRegistry(), store, TEMPLATES_KEY, getOldTemplateStoreInstance());
801                 store.setValue(TEMPLATES_MIGRATION_KEY, true);
802             }
803
804             try {
805                 fTemplateStore.load();
806             } catch (IOException JavaDoc e) {
807                 log(e);
808             }
809             fTemplateStore.startListeningForPreferenceChanges();
810         }
811         
812         return fTemplateStore;
813     }
814     
815     /**
816      * @deprecated Indirection added to avoid deprecated warning on file
817      */

818     private org.eclipse.jdt.internal.corext.template.java.Templates getOldTemplateStoreInstance() {
819         return org.eclipse.jdt.internal.corext.template.java.Templates.getInstance();
820     }
821
822     /**
823      * Returns the template context type registry for the code generation
824      * templates.
825      *
826      * @return the template context type registry for the code generation
827      * templates
828      * @since 3.0
829      */

830     public ContextTypeRegistry getCodeTemplateContextRegistry() {
831         if (fCodeTemplateContextTypeRegistry == null) {
832             fCodeTemplateContextTypeRegistry= new ContributionContextTypeRegistry();
833             
834             CodeTemplateContextType.registerContextTypes(fCodeTemplateContextTypeRegistry);
835         }
836
837         return fCodeTemplateContextTypeRegistry;
838     }
839     
840     /**
841      * Returns the template store for the code generation templates.
842      *
843      * @return the template store for the code generation templates
844      * @since 3.0
845      */

846     public TemplateStore getCodeTemplateStore() {
847         if (fCodeTemplateStore == null) {
848             IPreferenceStore store= getPreferenceStore();
849             boolean alreadyMigrated= store.getBoolean(CODE_TEMPLATES_MIGRATION_KEY);
850             if (alreadyMigrated)
851                 fCodeTemplateStore= new ContributionTemplateStore(getCodeTemplateContextRegistry(), store, CODE_TEMPLATES_KEY);
852             else {
853                 fCodeTemplateStore= new CompatibilityTemplateStore(getCodeTemplateContextRegistry(), store, CODE_TEMPLATES_KEY, getOldCodeTemplateStoreInstance());
854                 store.setValue(CODE_TEMPLATES_MIGRATION_KEY, true);
855             }
856
857             try {
858                 fCodeTemplateStore.load();
859             } catch (IOException JavaDoc e) {
860                 log(e);
861             }
862             
863             fCodeTemplateStore.startListeningForPreferenceChanges();
864             
865             // compatibility / bug fixing code for duplicated templates
866
// TODO remove for 3.0
867
CompatibilityTemplateStore.pruneDuplicates(fCodeTemplateStore, true);
868             
869         }
870         
871         return fCodeTemplateStore;
872     }
873     
874     /**
875      * @deprecated Indirection added to avoid deprecated warning on file
876      */

877     private org.eclipse.jdt.internal.corext.template.java.CodeTemplates getOldCodeTemplateStoreInstance() {
878         return org.eclipse.jdt.internal.corext.template.java.CodeTemplates.getInstance();
879     }
880     
881     private synchronized ImageDescriptorRegistry internalGetImageDescriptorRegistry() {
882         if (fImageDescriptorRegistry == null)
883             fImageDescriptorRegistry= new ImageDescriptorRegistry();
884         return fImageDescriptorRegistry;
885     }
886
887     /**
888      * Returns a combined preference store, this store is read-only.
889      *
890      * @return the combined preference store
891      *
892      * @since 3.0
893      */

894     public IPreferenceStore getCombinedPreferenceStore() {
895         if (fCombinedPreferenceStore == null) {
896             IPreferenceStore generalTextStore= EditorsUI.getPreferenceStore();
897             fCombinedPreferenceStore= new ChainedPreferenceStore(new IPreferenceStore[] { getPreferenceStore(), new PreferencesAdapter(JavaCore.getPlugin().getPluginPreferences()), generalTextStore });
898         }
899         return fCombinedPreferenceStore;
900     }
901     
902     /**
903      * Returns the registry of the extensions to the <code>org.eclipse.jdt.ui.javaFoldingStructureProvider</code>
904      * extension point.
905      *
906      * @return the registry of contributed <code>IJavaFoldingStructureProvider</code>
907      * @since 3.0
908      */

909     public synchronized JavaFoldingStructureProviderRegistry getFoldingStructureProviderRegistry() {
910         if (fFoldingStructureProviderRegistry == null)
911             fFoldingStructureProviderRegistry= new JavaFoldingStructureProviderRegistry();
912         return fFoldingStructureProviderRegistry;
913     }
914     
915     /**
916      * Returns the save participant registry.
917      *
918      * @return the save participant registry, not null
919      * @since 3.3
920      */

921     public synchronized SaveParticipantRegistry getSaveParticipantRegistry() {
922         if (fSaveParticipantRegistry == null)
923             fSaveParticipantRegistry= new SaveParticipantRegistry();
924         return fSaveParticipantRegistry;
925     }
926
927     /**
928      * Returns the Java content assist history.
929      *
930      * @return the Java content assist history
931      * @since 3.2
932      */

933     public ContentAssistHistory getContentAssistHistory() {
934         if (fContentAssistHistory == null) {
935             try {
936                 fContentAssistHistory= ContentAssistHistory.load(getPluginPreferences(), PreferenceConstants.CODEASSIST_LRU_HISTORY);
937             } catch (CoreException x) {
938                 log(x);
939             }
940             if (fContentAssistHistory == null)
941                 fContentAssistHistory= new ContentAssistHistory();
942         }
943
944         return fContentAssistHistory;
945     }
946     
947     /**
948      * Returns a section in the Java plugin's dialog settings. If the section doesn't exist yet, it is created.
949      *
950      * @param name the name of the section
951      * @return the section of the given name
952      * @since 3.2
953      */

954     public IDialogSettings getDialogSettingsSection(String JavaDoc name) {
955         IDialogSettings dialogSettings= getDialogSettings();
956         IDialogSettings section= dialogSettings.getSection(name);
957         if (section == null) {
958             section= dialogSettings.addNewSection(name);
959         }
960         return section;
961     }
962     
963     /**
964      * @since 3.3
965      */

966     public ClasspathAttributeConfigurationDescriptors getClasspathAttributeConfigurationDescriptors() {
967         if (fClasspathAttributeConfigurationDescriptors == null) {
968             fClasspathAttributeConfigurationDescriptors= new ClasspathAttributeConfigurationDescriptors();
969         }
970         return fClasspathAttributeConfigurationDescriptors;
971     }
972     
973 }
974
Popular Tags