1 11 package org.eclipse.jdt.internal.ui; 12 13 14 import java.io.IOException ; 15 import java.util.LinkedHashMap ; 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 111 public class JavaPlugin extends AbstractUIPlugin { 112 113 117 private static final String TEMPLATES_KEY= "org.eclipse.jdt.ui.text.custom_templates"; 122 private static final String CODE_TEMPLATES_KEY= "org.eclipse.jdt.ui.text.custom_code_templates"; 127 private static final String TEMPLATES_MIGRATION_KEY= "org.eclipse.jdt.ui.text.templates_migrated"; 132 private static final String CODE_TEMPLATES_MIGRATION_KEY= "org.eclipse.jdt.ui.text.code_templates_migrated"; 134 private static JavaPlugin fgJavaPlugin; 135 136 private static LinkedHashMap fgRepeatedMessages= new LinkedHashMap (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 147 private ContextTypeRegistry fContextTypeRegistry; 148 152 private ContextTypeRegistry fCodeTemplateContextTypeRegistry; 153 154 158 private TemplateStore fTemplateStore; 159 163 private TemplateStore fCodeTemplateStore; 164 165 169 private TypeFilter fTypeFilter; 170 171 172 private WorkingCopyManager fWorkingCopyManager; 173 174 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 192 private IPropertyChangeListener fPropertyChangeListener; 193 194 private JavaEditorTextHoverDescriptor[] fJavaEditorTextHoverDescriptors; 195 196 200 private ASTProvider fASTProvider; 201 202 206 private IPreferenceStore fCombinedPreferenceStore; 207 208 214 private JavaFoldingStructureProviderRegistry fFoldingStructureProviderRegistry; 215 216 220 private IDocumentProvider fPropertiesFileDocumentProvider; 221 222 227 private ContentAssistHistory fContentAssistHistory; 228 229 234 private SaveParticipantRegistry fSaveParticipantRegistry; 235 236 241 private ClasspathAttributeConfigurationDescriptors fClasspathAttributeConfigurationDescriptors; 242 243 private FormToolkit fDialogsFormToolkit; 244 245 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 278 public static IEditorPart[] getDirtyEditors() { 279 return EditorUtility.getDirtyEditors(); 280 } 281 282 public static String 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 message) { 291 log(new Status(IStatus.ERROR, getPluginId(), IJavaStatusConstants.INTERNAL_ERROR, message, null)); 292 } 293 294 public static void logErrorStatus(String 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 e) { 305 log(new Status(IStatus.ERROR, getPluginId(), IJavaStatusConstants.INTERNAL_ERROR, JavaUIMessages.JavaPlugin_internal_error, e)); 306 } 307 308 318 public static void logRepeatedMessage(String message, String detail) { 319 long now= System.currentTimeMillis(); 320 boolean writeToLog= true; 321 if (fgRepeatedMessages.containsKey(message)) { 322 long last= ((Long ) fgRepeatedMessages.get(message)).longValue(); 323 writeToLog= now - last > 5000; 324 } 325 fgRepeatedMessages.put(message, new Long (now)); 326 if (writeToLog) 327 log(new Exception (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 346 public void start(BundleContext context) throws Exception { 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 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 JavaManipulation.class.toString(); 378 } 379 380 static void initializeAfterLoad(IProgressMonitor monitor) { 381 OpenTypeHistory.getInstance().checkConsistency(monitor); 382 } 383 384 385 private static IPreferenceStore getDeprecatedWorkbenchPreferenceStore() { 386 return PlatformUI.getWorkbench().getPreferenceStore(); 387 } 388 389 390 private static final String DEPRECATED_EDITOR_TAB_WIDTH= PreferenceConstants.EDITOR_TAB_WIDTH; 391 392 393 private static final String DEPRECATED_REFACTOR_ERROR_PAGE_SEVERITY_THRESHOLD= PreferenceConstants.REFACTOR_ERROR_PAGE_SEVERITY_THRESHOLD; 394 395 396 private static final String DEPRECATED_CODEASSIST_ORDER_PROPOSALS= PreferenceConstants.CODEASSIST_ORDER_PROPOSALS; 397 398 401 private void ensurePreferenceStoreBackwardsCompatibility() { 402 403 IPreferenceStore store= getPreferenceStore(); 404 405 fMembersOrderPreferenceCache= new MembersOrderPreferenceCache(); 407 fMembersOrderPreferenceCache.install(store); 408 409 410 416 String fontPropagatedKey= "fontPropagated"; 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 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 443 final String oldTabWidthKey= DEPRECATED_EDITOR_TAB_WIDTH; 444 final String newTabWidthKey= AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH; 445 String tabWidthPropagatedKey= "tabWidthPropagated"; 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 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 473 477 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 492 String proposalOrderMigrated= "proposalOrderMigrated"; 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"); } 500 } 501 store.setValue(proposalOrderMigrated, true); 502 503 } 504 505 508 private void uninstallPreferenceStoreBackwardsCompatibility() { 509 JFaceResources.getFontRegistry().removeListener(fFontPropertyChangeListener); 510 getPreferenceStore().removePropertyChangeListener(fPropertyChangeListener); 511 } 512 513 516 protected ImageRegistry createImageRegistry() { 517 return JavaPluginImages.getImageRegistry(); 518 } 519 520 523 public void stop(BundleContext context) throws Exception { 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 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 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 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 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 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 704 public synchronized JavaEditorTextHoverDescriptor[] getJavaEditorTextHoverDescriptors() { 705 if (fJavaEditorTextHoverDescriptors == null) { 706 fJavaEditorTextHoverDescriptors= JavaEditorTextHoverDescriptor.getContributedHovers(); 707 ConfigurationElementSorter sorter= new ConfigurationElementSorter() { 708 711 public IConfigurationElement getConfigurationElement(Object object) { 712 return ((JavaEditorTextHoverDescriptor)object).getConfigurationElement(); 713 } 714 }; 715 sorter.sort(fJavaEditorTextHoverDescriptors); 716 717 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 742 public synchronized void resetJavaEditorTextHoverDescriptors() { 743 fJavaEditorTextHoverDescriptors= null; 744 } 745 746 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 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 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 e) { 807 log(e); 808 } 809 fTemplateStore.startListeningForPreferenceChanges(); 810 } 811 812 return fTemplateStore; 813 } 814 815 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 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 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 e) { 860 log(e); 861 } 862 863 fCodeTemplateStore.startListeningForPreferenceChanges(); 864 865 CompatibilityTemplateStore.pruneDuplicates(fCodeTemplateStore, true); 868 869 } 870 871 return fCodeTemplateStore; 872 } 873 874 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 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 909 public synchronized JavaFoldingStructureProviderRegistry getFoldingStructureProviderRegistry() { 910 if (fFoldingStructureProviderRegistry == null) 911 fFoldingStructureProviderRegistry= new JavaFoldingStructureProviderRegistry(); 912 return fFoldingStructureProviderRegistry; 913 } 914 915 921 public synchronized SaveParticipantRegistry getSaveParticipantRegistry() { 922 if (fSaveParticipantRegistry == null) 923 fSaveParticipantRegistry= new SaveParticipantRegistry(); 924 return fSaveParticipantRegistry; 925 } 926 927 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 954 public IDialogSettings getDialogSettingsSection(String 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 966 public ClasspathAttributeConfigurationDescriptors getClasspathAttributeConfigurationDescriptors() { 967 if (fClasspathAttributeConfigurationDescriptors == null) { 968 fClasspathAttributeConfigurationDescriptors= new ClasspathAttributeConfigurationDescriptors(); 969 } 970 return fClasspathAttributeConfigurationDescriptors; 971 } 972 973 } 974 | Popular Tags |