0001: /*******************************************************************************
0002: * Copyright (c) 2000, 2007 IBM Corporation and others.
0003: * All rights reserved. This program and the accompanying materials
0004: * are made available under the terms of the Eclipse Public License v1.0
0005: * which accompanies this distribution, and is available at
0006: * http://www.eclipse.org/legal/epl-v10.html
0007: *
0008: * Contributors:
0009: * IBM Corporation - initial API and implementation
0010: *******************************************************************************/package org.eclipse.jdt.internal.ui;
0011:
0012: import java.io.IOException;
0013: import java.util.LinkedHashMap;
0014:
0015: import org.eclipse.core.runtime.CoreException;
0016: import org.eclipse.core.runtime.IConfigurationElement;
0017: import org.eclipse.core.runtime.IProgressMonitor;
0018: import org.eclipse.core.runtime.IStatus;
0019: import org.eclipse.core.runtime.MultiStatus;
0020: import org.eclipse.core.runtime.Status;
0021:
0022: import org.eclipse.core.resources.IFile;
0023: import org.eclipse.core.resources.IResource;
0024: import org.eclipse.core.resources.IWorkspace;
0025: import org.eclipse.core.resources.ResourcesPlugin;
0026:
0027: import org.eclipse.swt.widgets.Display;
0028: import org.eclipse.swt.widgets.Shell;
0029:
0030: import org.eclipse.jface.action.GroupMarker;
0031: import org.eclipse.jface.action.IMenuManager;
0032: import org.eclipse.jface.action.Separator;
0033: import org.eclipse.jface.dialogs.IDialogSettings;
0034: import org.eclipse.jface.preference.IPreferenceStore;
0035: import org.eclipse.jface.preference.PreferenceConverter;
0036: import org.eclipse.jface.resource.ImageRegistry;
0037: import org.eclipse.jface.resource.JFaceResources;
0038: import org.eclipse.jface.util.IPropertyChangeListener;
0039: import org.eclipse.jface.util.PropertyChangeEvent;
0040:
0041: import org.eclipse.jface.text.templates.ContextTypeRegistry;
0042: import org.eclipse.jface.text.templates.persistence.TemplateStore;
0043:
0044: import org.eclipse.ui.IWorkbenchPage;
0045: import org.eclipse.ui.IWorkbenchWindow;
0046: import org.eclipse.ui.PlatformUI;
0047: import org.eclipse.ui.navigator.ICommonMenuConstants;
0048: import org.eclipse.ui.plugin.AbstractUIPlugin;
0049: import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
0050: import org.eclipse.ui.texteditor.ChainedPreferenceStore;
0051: import org.eclipse.ui.texteditor.ConfigurationElementSorter;
0052: import org.eclipse.ui.texteditor.IDocumentProvider;
0053: import org.eclipse.ui.themes.IThemeManager;
0054:
0055: import org.eclipse.ui.editors.text.EditorsUI;
0056: import org.eclipse.ui.editors.text.templates.ContributionContextTypeRegistry;
0057: import org.eclipse.ui.editors.text.templates.ContributionTemplateStore;
0058:
0059: import org.eclipse.ui.forms.FormColors;
0060: import org.eclipse.ui.forms.widgets.FormToolkit;
0061:
0062: import org.eclipse.jdt.core.IBuffer;
0063: import org.eclipse.jdt.core.ICompilationUnit;
0064: import org.eclipse.jdt.core.JavaCore;
0065: import org.eclipse.jdt.core.WorkingCopyOwner;
0066: import org.eclipse.jdt.core.manipulation.JavaManipulation;
0067:
0068: import org.eclipse.jdt.internal.corext.javadoc.JavaDocLocations;
0069: import org.eclipse.jdt.internal.corext.template.java.CodeTemplateContextType;
0070: import org.eclipse.jdt.internal.corext.template.java.JavaContextType;
0071: import org.eclipse.jdt.internal.corext.template.java.JavaDocContextType;
0072: import org.eclipse.jdt.internal.corext.template.java.SWTContextType;
0073: import org.eclipse.jdt.internal.corext.util.OpenTypeHistory;
0074: import org.eclipse.jdt.internal.corext.util.QualifiedTypeNameHistory;
0075: import org.eclipse.jdt.internal.corext.util.TypeFilter;
0076:
0077: import org.eclipse.jdt.ui.IContextMenuConstants;
0078: import org.eclipse.jdt.ui.JavaUI;
0079: import org.eclipse.jdt.ui.PreferenceConstants;
0080: import org.eclipse.jdt.ui.text.JavaTextTools;
0081:
0082: import org.eclipse.jdt.internal.ui.javaeditor.ASTProvider;
0083: import org.eclipse.jdt.internal.ui.javaeditor.ClassFileDocumentProvider;
0084: import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitDocumentProvider;
0085: import org.eclipse.jdt.internal.ui.javaeditor.DocumentAdapter;
0086: import org.eclipse.jdt.internal.ui.javaeditor.ICompilationUnitDocumentProvider;
0087: import org.eclipse.jdt.internal.ui.javaeditor.WorkingCopyManager;
0088: import org.eclipse.jdt.internal.ui.javaeditor.saveparticipant.SaveParticipantRegistry;
0089: import org.eclipse.jdt.internal.ui.preferences.MembersOrderPreferenceCache;
0090: import org.eclipse.jdt.internal.ui.preferences.formatter.FormatterProfileStore;
0091: import org.eclipse.jdt.internal.ui.propertiesfileeditor.PropertiesFileDocumentProvider;
0092: import org.eclipse.jdt.internal.ui.text.PreferencesAdapter;
0093: import org.eclipse.jdt.internal.ui.text.folding.JavaFoldingStructureProviderRegistry;
0094: import org.eclipse.jdt.internal.ui.text.java.ContentAssistHistory;
0095: import org.eclipse.jdt.internal.ui.text.java.hover.JavaEditorTextHoverDescriptor;
0096: import org.eclipse.jdt.internal.ui.text.spelling.SpellCheckEngine;
0097: import org.eclipse.jdt.internal.ui.viewsupport.ImageDescriptorRegistry;
0098: import org.eclipse.jdt.internal.ui.viewsupport.ProblemMarkerManager;
0099: import org.eclipse.jdt.internal.ui.wizards.buildpaths.ClasspathAttributeConfigurationDescriptors;
0100:
0101: import org.osgi.framework.BundleContext;
0102:
0103: /**
0104: * Represents the java plug-in. It provides a series of convenience methods such as
0105: * access to the workbench, keeps track of elements shared by all editors and viewers
0106: * of the plug-in such as document providers and find-replace-dialogs.
0107: */
0108: public class JavaPlugin extends AbstractUIPlugin {
0109:
0110: /**
0111: * The key to store customized templates.
0112: * @since 3.0
0113: */
0114: private static final String TEMPLATES_KEY = "org.eclipse.jdt.ui.text.custom_templates"; //$NON-NLS-1$
0115: /**
0116: * The key to store customized code templates.
0117: * @since 3.0
0118: */
0119: private static final String CODE_TEMPLATES_KEY = "org.eclipse.jdt.ui.text.custom_code_templates"; //$NON-NLS-1$
0120: /**
0121: * The key to store whether the legacy templates have been migrated
0122: * @since 3.0
0123: */
0124: private static final String TEMPLATES_MIGRATION_KEY = "org.eclipse.jdt.ui.text.templates_migrated"; //$NON-NLS-1$
0125: /**
0126: * The key to store whether the legacy code templates have been migrated
0127: * @since 3.0
0128: */
0129: private static final String CODE_TEMPLATES_MIGRATION_KEY = "org.eclipse.jdt.ui.text.code_templates_migrated"; //$NON-NLS-1$
0130:
0131: private static JavaPlugin fgJavaPlugin;
0132:
0133: private static LinkedHashMap fgRepeatedMessages = new LinkedHashMap(
0134: 20, 0.75f, true) {
0135: private static final long serialVersionUID = 1L;
0136:
0137: protected boolean removeEldestEntry(java.util.Map.Entry eldest) {
0138: return size() >= 20;
0139: }
0140: };
0141:
0142: /**
0143: * The template context type registry for the java editor.
0144: * @since 3.0
0145: */
0146: private ContextTypeRegistry fContextTypeRegistry;
0147: /**
0148: * The code template context type registry for the java editor.
0149: * @since 3.0
0150: */
0151: private ContextTypeRegistry fCodeTemplateContextTypeRegistry;
0152:
0153: /**
0154: * The template store for the java editor.
0155: * @since 3.0
0156: */
0157: private TemplateStore fTemplateStore;
0158: /**
0159: * The coded template store for the java editor.
0160: * @since 3.0
0161: */
0162: private TemplateStore fCodeTemplateStore;
0163:
0164: /**
0165: * Default instance of the appearance type filters.
0166: * @since 3.0
0167: */
0168: private TypeFilter fTypeFilter;
0169:
0170: private WorkingCopyManager fWorkingCopyManager;
0171:
0172: /**
0173: * @deprecated
0174: */
0175: private org.eclipse.jdt.core.IBufferFactory fBufferFactory;
0176: private ICompilationUnitDocumentProvider fCompilationUnitDocumentProvider;
0177: private ClassFileDocumentProvider fClassFileDocumentProvider;
0178: private JavaTextTools fJavaTextTools;
0179: private ProblemMarkerManager fProblemMarkerManager;
0180: private ImageDescriptorRegistry fImageDescriptorRegistry;
0181:
0182: private MembersOrderPreferenceCache fMembersOrderPreferenceCache;
0183: private IPropertyChangeListener fFontPropertyChangeListener;
0184:
0185: /**
0186: * Property change listener on this plugin's preference store.
0187: * @since 3.0
0188: */
0189: private IPropertyChangeListener fPropertyChangeListener;
0190:
0191: private JavaEditorTextHoverDescriptor[] fJavaEditorTextHoverDescriptors;
0192:
0193: /**
0194: * The AST provider.
0195: * @since 3.0
0196: */
0197: private ASTProvider fASTProvider;
0198:
0199: /**
0200: * The combined preference store.
0201: * @since 3.0
0202: */
0203: private IPreferenceStore fCombinedPreferenceStore;
0204:
0205: /**
0206: * The extension point registry for the <code>org.eclipse.jdt.ui.javaFoldingStructureProvider</code>
0207: * extension point.
0208: *
0209: * @since 3.0
0210: */
0211: private JavaFoldingStructureProviderRegistry fFoldingStructureProviderRegistry;
0212:
0213: /**
0214: * The shared Java properties file document provider.
0215: * @since 3.1
0216: */
0217: private IDocumentProvider fPropertiesFileDocumentProvider;
0218:
0219: /**
0220: * Content assist history.
0221: * @since 3.2
0222: */
0223: private ContentAssistHistory fContentAssistHistory;
0224:
0225: /**
0226: * The save participant registry.
0227: * @since 3.3
0228: */
0229: private SaveParticipantRegistry fSaveParticipantRegistry;
0230:
0231: /**
0232: * The descriptors from the 'classpathAttributeConfiguration' extension point.
0233: * @since 3.3
0234: */
0235: private ClasspathAttributeConfigurationDescriptors fClasspathAttributeConfigurationDescriptors;
0236:
0237: private FormToolkit fDialogsFormToolkit;
0238:
0239: /**
0240: * Theme listener.
0241: * @since 3.3
0242: */
0243: private IPropertyChangeListener fThemeListener;
0244:
0245: public static JavaPlugin getDefault() {
0246: return fgJavaPlugin;
0247: }
0248:
0249: public static IWorkspace getWorkspace() {
0250: return ResourcesPlugin.getWorkspace();
0251: }
0252:
0253: public static IWorkbenchPage getActivePage() {
0254: return getDefault().internalGetActivePage();
0255: }
0256:
0257: public static IWorkbenchWindow getActiveWorkbenchWindow() {
0258: return getDefault().getWorkbench().getActiveWorkbenchWindow();
0259: }
0260:
0261: public static Shell getActiveWorkbenchShell() {
0262: IWorkbenchWindow window = getActiveWorkbenchWindow();
0263: if (window != null) {
0264: return window.getShell();
0265: }
0266: return null;
0267: }
0268:
0269: public static String getPluginId() {
0270: return JavaUI.ID_PLUGIN;
0271: }
0272:
0273: public static void log(IStatus status) {
0274: getDefault().getLog().log(status);
0275: }
0276:
0277: public static void logErrorMessage(String message) {
0278: log(new Status(IStatus.ERROR, getPluginId(),
0279: IJavaStatusConstants.INTERNAL_ERROR, message, null));
0280: }
0281:
0282: public static void logErrorStatus(String message, IStatus status) {
0283: if (status == null) {
0284: logErrorMessage(message);
0285: return;
0286: }
0287: MultiStatus multi = new MultiStatus(getPluginId(),
0288: IJavaStatusConstants.INTERNAL_ERROR, message, null);
0289: multi.add(status);
0290: log(multi);
0291: }
0292:
0293: public static void log(Throwable e) {
0294: log(new Status(IStatus.ERROR, getPluginId(),
0295: IJavaStatusConstants.INTERNAL_ERROR,
0296: JavaUIMessages.JavaPlugin_internal_error, e));
0297: }
0298:
0299: /**
0300: * Log a message that is potentially repeated after a very short time.
0301: * The first time this method is called with a given message, the
0302: * message is written to the log along with the detail message and a stack trace.
0303: * <p>
0304: * Only intended for use in debug statements.
0305: *
0306: * @param message the (generic) message
0307: * @param detail the detail message
0308: */
0309: public static void logRepeatedMessage(String message, String detail) {
0310: long now = System.currentTimeMillis();
0311: boolean writeToLog = true;
0312: if (fgRepeatedMessages.containsKey(message)) {
0313: long last = ((Long) fgRepeatedMessages.get(message))
0314: .longValue();
0315: writeToLog = now - last > 5000;
0316: }
0317: fgRepeatedMessages.put(message, new Long(now));
0318: if (writeToLog)
0319: log(new Exception(message + detail).fillInStackTrace());
0320: }
0321:
0322: public static boolean isDebug() {
0323: return getDefault().isDebugging();
0324: }
0325:
0326: public static ImageDescriptorRegistry getImageDescriptorRegistry() {
0327: return getDefault().internalGetImageDescriptorRegistry();
0328: }
0329:
0330: public JavaPlugin() {
0331: super ();
0332: fgJavaPlugin = this ;
0333: }
0334:
0335: /* (non - Javadoc)
0336: * Method declared in plug-in
0337: */
0338: public void start(BundleContext context) throws Exception {
0339: super .start(context);
0340:
0341: WorkingCopyOwner
0342: .setPrimaryBufferProvider(new WorkingCopyOwner() {
0343: public IBuffer createBuffer(
0344: ICompilationUnit workingCopy) {
0345: ICompilationUnit original = workingCopy
0346: .getPrimary();
0347: IResource resource = original.getResource();
0348: if (resource instanceof IFile)
0349: return new DocumentAdapter(workingCopy,
0350: (IFile) resource);
0351: return DocumentAdapter.NULL;
0352: }
0353: });
0354:
0355: ensurePreferenceStoreBackwardsCompatibility();
0356:
0357: // make sure org.eclipse.jdt.core.manipulation is loaded too
0358: // can be removed if JavaElementPropertyTester is moved down to jdt.core (bug 127085)
0359: JavaManipulation.class.toString();
0360:
0361: if (PlatformUI.isWorkbenchRunning()) {
0362: // Initialize AST provider
0363: getASTProvider();
0364:
0365: fThemeListener = new IPropertyChangeListener() {
0366: public void propertyChange(PropertyChangeEvent event) {
0367: if (IThemeManager.CHANGE_CURRENT_THEME.equals(event
0368: .getProperty()))
0369: new JavaUIPreferenceInitializer()
0370: .initializeDefaultPreferences();
0371: }
0372: };
0373: PlatformUI.getWorkbench().getThemeManager()
0374: .addPropertyChangeListener(fThemeListener);
0375: new InitializeAfterLoadJob().schedule(); // last call in start, see bug 191193
0376: }
0377: }
0378:
0379: /* package */static void initializeAfterLoad(
0380: IProgressMonitor monitor) {
0381: OpenTypeHistory.getInstance().checkConsistency(monitor);
0382: }
0383:
0384: /**
0385: * Private deprecated method to avoid deprecation warnings
0386: *
0387: * @return the deprecated preference store
0388: * @deprecated
0389: */
0390: private static IPreferenceStore getDeprecatedWorkbenchPreferenceStore() {
0391: return PlatformUI.getWorkbench().getPreferenceStore();
0392: }
0393:
0394: /** @deprecated */
0395: private static final String DEPRECATED_EDITOR_TAB_WIDTH = PreferenceConstants.EDITOR_TAB_WIDTH;
0396:
0397: /** @deprecated */
0398: private static final String DEPRECATED_REFACTOR_ERROR_PAGE_SEVERITY_THRESHOLD = PreferenceConstants.REFACTOR_ERROR_PAGE_SEVERITY_THRESHOLD;
0399:
0400: /** @deprecated */
0401: private static final String DEPRECATED_CODEASSIST_ORDER_PROPOSALS = PreferenceConstants.CODEASSIST_ORDER_PROPOSALS;
0402:
0403: /**
0404: * Installs backwards compatibility for the preference store.
0405: */
0406: private void ensurePreferenceStoreBackwardsCompatibility() {
0407:
0408: IPreferenceStore store = getPreferenceStore();
0409:
0410: // must add here to guarantee that it is the first in the listener list
0411: fMembersOrderPreferenceCache = new MembersOrderPreferenceCache();
0412: fMembersOrderPreferenceCache.install(store);
0413:
0414: /*
0415: * Installs backwards compatibility: propagate the Java editor font from a
0416: * pre-2.1 plug-in to the Platform UI's preference store to preserve
0417: * the Java editor font from a pre-2.1 workspace. This is done only
0418: * once.
0419: */
0420: String fontPropagatedKey = "fontPropagated"; //$NON-NLS-1$
0421: if (store.contains(JFaceResources.TEXT_FONT)
0422: && !store.isDefault(JFaceResources.TEXT_FONT)) {
0423: if (!store.getBoolean(fontPropagatedKey))
0424: PreferenceConverter.setValue(
0425: getDeprecatedWorkbenchPreferenceStore(),
0426: PreferenceConstants.EDITOR_TEXT_FONT,
0427: PreferenceConverter.getFontDataArray(store,
0428: JFaceResources.TEXT_FONT));
0429: }
0430: store.setValue(fontPropagatedKey, true);
0431:
0432: /*
0433: * Backwards compatibility: set the Java editor font in this plug-in's
0434: * preference store to let older versions access it. Since 2.1 the
0435: * Java editor font is managed by the workbench font preference page.
0436: */
0437: PreferenceConverter.putValue(store, JFaceResources.TEXT_FONT,
0438: JFaceResources.getFontRegistry().getFontData(
0439: PreferenceConstants.EDITOR_TEXT_FONT));
0440:
0441: fFontPropertyChangeListener = new IPropertyChangeListener() {
0442: public void propertyChange(PropertyChangeEvent event) {
0443: if (PreferenceConstants.EDITOR_TEXT_FONT.equals(event
0444: .getProperty()))
0445: PreferenceConverter
0446: .putValue(
0447: getPreferenceStore(),
0448: JFaceResources.TEXT_FONT,
0449: JFaceResources
0450: .getFontRegistry()
0451: .getFontData(
0452: PreferenceConstants.EDITOR_TEXT_FONT));
0453: }
0454: };
0455: JFaceResources.getFontRegistry().addListener(
0456: fFontPropertyChangeListener);
0457:
0458: /*
0459: * Backwards compatibility: propagate the Java editor tab width from a
0460: * pre-3.0 plug-in to the new preference key. This is done only once.
0461: */
0462: final String oldTabWidthKey = DEPRECATED_EDITOR_TAB_WIDTH;
0463: final String newTabWidthKey = AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH;
0464: String tabWidthPropagatedKey = "tabWidthPropagated"; //$NON-NLS-1$
0465: if (store.contains(oldTabWidthKey)
0466: && !store.isDefault(oldTabWidthKey)) {
0467: if (!store.getBoolean(tabWidthPropagatedKey))
0468: store.setValue(newTabWidthKey, store
0469: .getInt(oldTabWidthKey));
0470: }
0471: store.setValue(tabWidthPropagatedKey, true);
0472:
0473: /*
0474: * Backwards compatibility: set the Java editor tab width in this plug-in's
0475: * preference store with the old key to let older versions access it.
0476: * Since 3.0 the tab width is managed by the extended text editor and
0477: * uses a new key.
0478: */
0479: store.putValue(oldTabWidthKey, store.getString(newTabWidthKey));
0480:
0481: fPropertyChangeListener = new IPropertyChangeListener() {
0482: public void propertyChange(PropertyChangeEvent event) {
0483: if (newTabWidthKey.equals(event.getProperty())) {
0484: IPreferenceStore prefStore = getPreferenceStore();
0485: prefStore.putValue(oldTabWidthKey, prefStore
0486: .getString(newTabWidthKey));
0487: }
0488: }
0489: };
0490: store.addPropertyChangeListener(fPropertyChangeListener);
0491:
0492: /*
0493: * Backward compatibility for the refactoring preference key.
0494: */
0495: // store.setValue(
0496: // PreferenceConstants.REFACTOR_ERROR_PAGE_SEVERITY_THRESHOLD,
0497: // RefactoringCore.getConditionCheckingFailedSeverity());
0498: // The commented call above triggers the eager loading of the LTK core plug-in
0499: // Since the condition checking failed severity is guaranteed to be of RefactoringStatus.SEVERITY_WARNING,
0500: // we directly insert the inlined value of this constant
0501: store
0502: .setToDefault(DEPRECATED_REFACTOR_ERROR_PAGE_SEVERITY_THRESHOLD);
0503:
0504: if (!store
0505: .getBoolean(JavaDocLocations.PREF_JAVADOCLOCATIONS_MIGRATED)) {
0506: JavaDocLocations.migrateToClasspathAttributes();
0507: }
0508:
0509: FormatterProfileStore.checkCurrentOptionsVersion();
0510:
0511: /*
0512: * Backward compatibility: migrate "alphabetic ordering" preference to point the sorter
0513: * preference to the alphabetic sorter.
0514: */
0515: String proposalOrderMigrated = "proposalOrderMigrated"; //$NON-NLS-1$
0516:
0517: if (store.contains(DEPRECATED_CODEASSIST_ORDER_PROPOSALS)) {
0518: if (!store.getBoolean(proposalOrderMigrated)) {
0519: boolean alphabetic = store
0520: .getBoolean(DEPRECATED_CODEASSIST_ORDER_PROPOSALS);
0521: if (alphabetic)
0522: store.setValue(
0523: PreferenceConstants.CODEASSIST_SORTER,
0524: "org.eclipse.jdt.ui.AlphabeticSorter"); //$NON-NLS-1$
0525: }
0526: }
0527: store.setValue(proposalOrderMigrated, true);
0528:
0529: }
0530:
0531: /**
0532: * Uninstalls backwards compatibility for the preference store.
0533: */
0534: private void uninstallPreferenceStoreBackwardsCompatibility() {
0535: JFaceResources.getFontRegistry().removeListener(
0536: fFontPropertyChangeListener);
0537: getPreferenceStore().removePropertyChangeListener(
0538: fPropertyChangeListener);
0539: }
0540:
0541: /*
0542: * @see org.eclipse.ui.plugin.AbstractUIPlugin#createImageRegistry()
0543: */
0544: protected ImageRegistry createImageRegistry() {
0545: return JavaPluginImages.getImageRegistry();
0546: }
0547:
0548: /*
0549: * @see org.eclipse.core.runtime.Plugin#stop
0550: */
0551: public void stop(BundleContext context) throws Exception {
0552: try {
0553: if (fImageDescriptorRegistry != null)
0554: fImageDescriptorRegistry.dispose();
0555:
0556: if (fASTProvider != null) {
0557: fASTProvider.dispose();
0558: fASTProvider = null;
0559: }
0560:
0561: if (fWorkingCopyManager != null) {
0562: fWorkingCopyManager.shutdown();
0563: fWorkingCopyManager = null;
0564: }
0565:
0566: if (fCompilationUnitDocumentProvider != null) {
0567: fCompilationUnitDocumentProvider.shutdown();
0568: fCompilationUnitDocumentProvider = null;
0569: }
0570:
0571: if (fJavaTextTools != null) {
0572: fJavaTextTools.dispose();
0573: fJavaTextTools = null;
0574: }
0575:
0576: if (fTypeFilter != null) {
0577: fTypeFilter.dispose();
0578: fTypeFilter = null;
0579: }
0580:
0581: if (fContentAssistHistory != null) {
0582: ContentAssistHistory.store(fContentAssistHistory,
0583: getPluginPreferences(),
0584: PreferenceConstants.CODEASSIST_LRU_HISTORY);
0585: fContentAssistHistory = null;
0586: }
0587:
0588: uninstallPreferenceStoreBackwardsCompatibility();
0589:
0590: if (fTemplateStore != null) {
0591: fTemplateStore.stopListeningForPreferenceChanges();
0592: fTemplateStore = null;
0593: }
0594:
0595: if (fCodeTemplateStore != null) {
0596: fCodeTemplateStore.stopListeningForPreferenceChanges();
0597: fCodeTemplateStore = null;
0598: }
0599:
0600: if (fMembersOrderPreferenceCache != null) {
0601: fMembersOrderPreferenceCache.dispose();
0602: fMembersOrderPreferenceCache = null;
0603: }
0604:
0605: if (fSaveParticipantRegistry != null) {
0606: fSaveParticipantRegistry.dispose();
0607: fSaveParticipantRegistry = null;
0608: }
0609:
0610: if (fDialogsFormToolkit != null) {
0611: fDialogsFormToolkit.dispose();
0612: fDialogsFormToolkit = null;
0613: }
0614:
0615: if (fThemeListener != null) {
0616: PlatformUI.getWorkbench().getThemeManager()
0617: .removePropertyChangeListener(fThemeListener);
0618: fThemeListener = null;
0619: }
0620:
0621: SpellCheckEngine.shutdownInstance();
0622:
0623: QualifiedTypeNameHistory.getDefault().save();
0624:
0625: // must add here to guarantee that it is the first in the listener list
0626:
0627: OpenTypeHistory.shutdown();
0628: } finally {
0629: super .stop(context);
0630: }
0631: }
0632:
0633: private IWorkbenchPage internalGetActivePage() {
0634: IWorkbenchWindow window = getWorkbench()
0635: .getActiveWorkbenchWindow();
0636: if (window == null)
0637: return null;
0638: return window.getActivePage();
0639: }
0640:
0641: /**
0642: * Private deprecated method to avoid deprecation warnings
0643: *
0644: * @return the deprecated buffer factory
0645: * @deprecated
0646: */
0647: public synchronized org.eclipse.jdt.core.IBufferFactory getBufferFactory() {
0648: if (fBufferFactory == null)
0649: fBufferFactory = new org.eclipse.jdt.internal.ui.javaeditor.CustomBufferFactory();
0650: return fBufferFactory;
0651: }
0652:
0653: public synchronized ICompilationUnitDocumentProvider getCompilationUnitDocumentProvider() {
0654: if (fCompilationUnitDocumentProvider == null)
0655: fCompilationUnitDocumentProvider = new CompilationUnitDocumentProvider();
0656: return fCompilationUnitDocumentProvider;
0657: }
0658:
0659: /**
0660: * Returns the shared document provider for Java properties files
0661: * used by this plug-in instance.
0662: *
0663: * @return the shared document provider for Java properties files
0664: * @since 3.1
0665: */
0666: public synchronized IDocumentProvider getPropertiesFileDocumentProvider() {
0667: if (fPropertiesFileDocumentProvider == null)
0668: fPropertiesFileDocumentProvider = new PropertiesFileDocumentProvider();
0669: return fPropertiesFileDocumentProvider;
0670: }
0671:
0672: public synchronized ClassFileDocumentProvider getClassFileDocumentProvider() {
0673: if (fClassFileDocumentProvider == null)
0674: fClassFileDocumentProvider = new ClassFileDocumentProvider();
0675: return fClassFileDocumentProvider;
0676: }
0677:
0678: public synchronized WorkingCopyManager getWorkingCopyManager() {
0679: if (fWorkingCopyManager == null) {
0680: ICompilationUnitDocumentProvider provider = getCompilationUnitDocumentProvider();
0681: fWorkingCopyManager = new WorkingCopyManager(provider);
0682: }
0683: return fWorkingCopyManager;
0684: }
0685:
0686: public synchronized ProblemMarkerManager getProblemMarkerManager() {
0687: if (fProblemMarkerManager == null)
0688: fProblemMarkerManager = new ProblemMarkerManager();
0689: return fProblemMarkerManager;
0690: }
0691:
0692: public synchronized JavaTextTools getJavaTextTools() {
0693: if (fJavaTextTools == null)
0694: fJavaTextTools = new JavaTextTools(getPreferenceStore(),
0695: JavaCore.getPlugin().getPluginPreferences());
0696: return fJavaTextTools;
0697: }
0698:
0699: /**
0700: * Returns the AST provider.
0701: *
0702: * @return the AST provider
0703: * @since 3.0
0704: */
0705: public synchronized ASTProvider getASTProvider() {
0706: if (fASTProvider == null)
0707: fASTProvider = new ASTProvider();
0708:
0709: return fASTProvider;
0710: }
0711:
0712: public synchronized MembersOrderPreferenceCache getMemberOrderPreferenceCache() {
0713: // initialized on startup
0714: return fMembersOrderPreferenceCache;
0715: }
0716:
0717: public synchronized TypeFilter getTypeFilter() {
0718: if (fTypeFilter == null)
0719: fTypeFilter = new TypeFilter();
0720: return fTypeFilter;
0721: }
0722:
0723: public FormToolkit getDialogsFormToolkit() {
0724: if (fDialogsFormToolkit == null) {
0725: FormColors colors = new FormColors(Display.getCurrent());
0726: colors.setBackground(null);
0727: colors.setForeground(null);
0728: fDialogsFormToolkit = new FormToolkit(colors);
0729: }
0730: return fDialogsFormToolkit;
0731: }
0732:
0733: /**
0734: * Returns all Java editor text hovers contributed to the workbench.
0735: *
0736: * @return an array of JavaEditorTextHoverDescriptor
0737: * @since 2.1
0738: */
0739: public synchronized JavaEditorTextHoverDescriptor[] getJavaEditorTextHoverDescriptors() {
0740: if (fJavaEditorTextHoverDescriptors == null) {
0741: fJavaEditorTextHoverDescriptors = JavaEditorTextHoverDescriptor
0742: .getContributedHovers();
0743: ConfigurationElementSorter sorter = new ConfigurationElementSorter() {
0744: /*
0745: * @see org.eclipse.ui.texteditor.ConfigurationElementSorter#getConfigurationElement(java.lang.Object)
0746: */
0747: public IConfigurationElement getConfigurationElement(
0748: Object object) {
0749: return ((JavaEditorTextHoverDescriptor) object)
0750: .getConfigurationElement();
0751: }
0752: };
0753: sorter.sort(fJavaEditorTextHoverDescriptors);
0754:
0755: // Move Best Match hover to front
0756: for (int i = 0; i < fJavaEditorTextHoverDescriptors.length - 1; i++) {
0757: if (PreferenceConstants.ID_BESTMATCH_HOVER
0758: .equals(fJavaEditorTextHoverDescriptors[i]
0759: .getId())) {
0760: JavaEditorTextHoverDescriptor hoverDescriptor = fJavaEditorTextHoverDescriptors[i];
0761: for (int j = i; j > 0; j--)
0762: fJavaEditorTextHoverDescriptors[j] = fJavaEditorTextHoverDescriptors[j - 1];
0763: fJavaEditorTextHoverDescriptors[0] = hoverDescriptor;
0764: break;
0765: }
0766:
0767: }
0768: }
0769:
0770: return fJavaEditorTextHoverDescriptors;
0771: }
0772:
0773: /**
0774: * Resets the Java editor text hovers contributed to the workbench.
0775: * <p>
0776: * This will force a rebuild of the descriptors the next time
0777: * a client asks for them.
0778: * </p>
0779: *
0780: * @since 2.1
0781: */
0782: public synchronized void resetJavaEditorTextHoverDescriptors() {
0783: fJavaEditorTextHoverDescriptors = null;
0784: }
0785:
0786: /**
0787: * Creates the Java plug-in's standard groups for view context menus.
0788: *
0789: * @param menu the menu manager to be populated
0790: */
0791: public static void createStandardGroups(IMenuManager menu) {
0792: if (!menu.isEmpty())
0793: return;
0794:
0795: menu.add(new Separator(IContextMenuConstants.GROUP_NEW));
0796: menu.add(new GroupMarker(IContextMenuConstants.GROUP_GOTO));
0797: menu.add(new Separator(IContextMenuConstants.GROUP_OPEN));
0798: menu.add(new GroupMarker(IContextMenuConstants.GROUP_SHOW));
0799: menu.add(new Separator(ICommonMenuConstants.GROUP_EDIT));
0800: menu.add(new Separator(IContextMenuConstants.GROUP_REORGANIZE));
0801: menu.add(new Separator(IContextMenuConstants.GROUP_GENERATE));
0802: menu.add(new Separator(IContextMenuConstants.GROUP_SEARCH));
0803: menu.add(new Separator(IContextMenuConstants.GROUP_BUILD));
0804: menu.add(new Separator(IContextMenuConstants.GROUP_ADDITIONS));
0805: menu
0806: .add(new Separator(
0807: IContextMenuConstants.GROUP_VIEWER_SETUP));
0808: menu.add(new Separator(IContextMenuConstants.GROUP_PROPERTIES));
0809: }
0810:
0811: /**
0812: * Returns the template context type registry for the java plug-in.
0813: *
0814: * @return the template context type registry for the java plug-in
0815: * @since 3.0
0816: */
0817: public synchronized ContextTypeRegistry getTemplateContextRegistry() {
0818: if (fContextTypeRegistry == null) {
0819: ContributionContextTypeRegistry registry = new ContributionContextTypeRegistry();
0820: registry.addContextType(JavaContextType.ID);
0821: registry.addContextType(JavaDocContextType.ID);
0822: registry.addContextType(SWTContextType.ID);
0823:
0824: SWTContextType swtContext = (SWTContextType) registry
0825: .getContextType(SWTContextType.ID);
0826: swtContext.inheritResolvers(registry
0827: .getContextType(JavaContextType.ID));
0828:
0829: fContextTypeRegistry = registry;
0830: }
0831:
0832: return fContextTypeRegistry;
0833: }
0834:
0835: /**
0836: * Returns the template store for the java editor templates.
0837: *
0838: * @return the template store for the java editor templates
0839: * @since 3.0
0840: */
0841: public TemplateStore getTemplateStore() {
0842: if (fTemplateStore == null) {
0843: final IPreferenceStore store = getPreferenceStore();
0844: boolean alreadyMigrated = store
0845: .getBoolean(TEMPLATES_MIGRATION_KEY);
0846: if (alreadyMigrated)
0847: fTemplateStore = new ContributionTemplateStore(
0848: getTemplateContextRegistry(), store,
0849: TEMPLATES_KEY);
0850: else {
0851: fTemplateStore = new CompatibilityTemplateStore(
0852: getTemplateContextRegistry(), store,
0853: TEMPLATES_KEY, getOldTemplateStoreInstance());
0854: store.setValue(TEMPLATES_MIGRATION_KEY, true);
0855: }
0856:
0857: try {
0858: fTemplateStore.load();
0859: } catch (IOException e) {
0860: log(e);
0861: }
0862: fTemplateStore.startListeningForPreferenceChanges();
0863: }
0864:
0865: return fTemplateStore;
0866: }
0867:
0868: /**
0869: * Private deprecated method to avoid deprecation warnings
0870: *
0871: * @return the deprecated template store
0872: * @deprecated
0873: */
0874: private org.eclipse.jdt.internal.corext.template.java.Templates getOldTemplateStoreInstance() {
0875: return org.eclipse.jdt.internal.corext.template.java.Templates
0876: .getInstance();
0877: }
0878:
0879: /**
0880: * Returns the template context type registry for the code generation
0881: * templates.
0882: *
0883: * @return the template context type registry for the code generation
0884: * templates
0885: * @since 3.0
0886: */
0887: public ContextTypeRegistry getCodeTemplateContextRegistry() {
0888: if (fCodeTemplateContextTypeRegistry == null) {
0889: fCodeTemplateContextTypeRegistry = new ContributionContextTypeRegistry();
0890:
0891: CodeTemplateContextType
0892: .registerContextTypes(fCodeTemplateContextTypeRegistry);
0893: }
0894:
0895: return fCodeTemplateContextTypeRegistry;
0896: }
0897:
0898: /**
0899: * Returns the template store for the code generation templates.
0900: *
0901: * @return the template store for the code generation templates
0902: * @since 3.0
0903: */
0904: public TemplateStore getCodeTemplateStore() {
0905: if (fCodeTemplateStore == null) {
0906: IPreferenceStore store = getPreferenceStore();
0907: boolean alreadyMigrated = store
0908: .getBoolean(CODE_TEMPLATES_MIGRATION_KEY);
0909: if (alreadyMigrated)
0910: fCodeTemplateStore = new ContributionTemplateStore(
0911: getCodeTemplateContextRegistry(), store,
0912: CODE_TEMPLATES_KEY);
0913: else {
0914: fCodeTemplateStore = new CompatibilityTemplateStore(
0915: getCodeTemplateContextRegistry(), store,
0916: CODE_TEMPLATES_KEY,
0917: getOldCodeTemplateStoreInstance());
0918: store.setValue(CODE_TEMPLATES_MIGRATION_KEY, true);
0919: }
0920:
0921: try {
0922: fCodeTemplateStore.load();
0923: } catch (IOException e) {
0924: log(e);
0925: }
0926:
0927: fCodeTemplateStore.startListeningForPreferenceChanges();
0928:
0929: // compatibility / bug fixing code for duplicated templates
0930: // TODO remove for 3.0
0931: CompatibilityTemplateStore.pruneDuplicates(
0932: fCodeTemplateStore, true);
0933:
0934: }
0935:
0936: return fCodeTemplateStore;
0937: }
0938:
0939: /**
0940: * Private deprecated method to avoid deprecation warnings
0941: *
0942: * @return the deprecated code template store
0943: * @deprecated
0944: */
0945: private org.eclipse.jdt.internal.corext.template.java.CodeTemplates getOldCodeTemplateStoreInstance() {
0946: return org.eclipse.jdt.internal.corext.template.java.CodeTemplates
0947: .getInstance();
0948: }
0949:
0950: private synchronized ImageDescriptorRegistry internalGetImageDescriptorRegistry() {
0951: if (fImageDescriptorRegistry == null)
0952: fImageDescriptorRegistry = new ImageDescriptorRegistry();
0953: return fImageDescriptorRegistry;
0954: }
0955:
0956: /**
0957: * Returns a combined preference store, this store is read-only.
0958: *
0959: * @return the combined preference store
0960: *
0961: * @since 3.0
0962: */
0963: public IPreferenceStore getCombinedPreferenceStore() {
0964: if (fCombinedPreferenceStore == null) {
0965: IPreferenceStore generalTextStore = EditorsUI
0966: .getPreferenceStore();
0967: fCombinedPreferenceStore = new ChainedPreferenceStore(
0968: new IPreferenceStore[] {
0969: getPreferenceStore(),
0970: new PreferencesAdapter(JavaCore.getPlugin()
0971: .getPluginPreferences()),
0972: generalTextStore });
0973: }
0974: return fCombinedPreferenceStore;
0975: }
0976:
0977: /**
0978: * Returns the registry of the extensions to the <code>org.eclipse.jdt.ui.javaFoldingStructureProvider</code>
0979: * extension point.
0980: *
0981: * @return the registry of contributed <code>IJavaFoldingStructureProvider</code>
0982: * @since 3.0
0983: */
0984: public synchronized JavaFoldingStructureProviderRegistry getFoldingStructureProviderRegistry() {
0985: if (fFoldingStructureProviderRegistry == null)
0986: fFoldingStructureProviderRegistry = new JavaFoldingStructureProviderRegistry();
0987: return fFoldingStructureProviderRegistry;
0988: }
0989:
0990: /**
0991: * Returns the save participant registry.
0992: *
0993: * @return the save participant registry, not null
0994: * @since 3.3
0995: */
0996: public synchronized SaveParticipantRegistry getSaveParticipantRegistry() {
0997: if (fSaveParticipantRegistry == null)
0998: fSaveParticipantRegistry = new SaveParticipantRegistry();
0999: return fSaveParticipantRegistry;
1000: }
1001:
1002: /**
1003: * Returns the Java content assist history.
1004: *
1005: * @return the Java content assist history
1006: * @since 3.2
1007: */
1008: public ContentAssistHistory getContentAssistHistory() {
1009: if (fContentAssistHistory == null) {
1010: try {
1011: fContentAssistHistory = ContentAssistHistory.load(
1012: getPluginPreferences(),
1013: PreferenceConstants.CODEASSIST_LRU_HISTORY);
1014: } catch (CoreException x) {
1015: log(x);
1016: }
1017: if (fContentAssistHistory == null)
1018: fContentAssistHistory = new ContentAssistHistory();
1019: }
1020:
1021: return fContentAssistHistory;
1022: }
1023:
1024: /**
1025: * Returns a section in the Java plugin's dialog settings. If the section doesn't exist yet, it is created.
1026: *
1027: * @param name the name of the section
1028: * @return the section of the given name
1029: * @since 3.2
1030: */
1031: public IDialogSettings getDialogSettingsSection(String name) {
1032: IDialogSettings dialogSettings = getDialogSettings();
1033: IDialogSettings section = dialogSettings.getSection(name);
1034: if (section == null) {
1035: section = dialogSettings.addNewSection(name);
1036: }
1037: return section;
1038: }
1039:
1040: /**
1041: * Returns the descriptors for the class path attribute configuration extension point
1042: *
1043: * @return access to the descriptors for the class path attribute configuration extension point
1044: * @since 3.3
1045: */
1046: public ClasspathAttributeConfigurationDescriptors getClasspathAttributeConfigurationDescriptors() {
1047: if (fClasspathAttributeConfigurationDescriptors == null) {
1048: fClasspathAttributeConfigurationDescriptors = new ClasspathAttributeConfigurationDescriptors();
1049: }
1050: return fClasspathAttributeConfigurationDescriptors;
1051: }
1052:
1053: }
|