1 11 package org.eclipse.jdt.ui; 12 13 import java.net.URL ; 14 import java.util.ArrayList ; 15 import java.util.Arrays ; 16 import java.util.List ; 17 18 import org.eclipse.core.runtime.Assert; 19 import org.eclipse.core.runtime.IPath; 20 21 import org.eclipse.core.resources.IProject; 22 23 import org.eclipse.swt.dnd.Transfer; 24 import org.eclipse.swt.widgets.Shell; 25 26 import org.eclipse.jface.operation.IRunnableContext; 27 28 import org.eclipse.ui.IEditorInput; 29 import org.eclipse.ui.IEditorPart; 30 import org.eclipse.ui.PartInitException; 31 import org.eclipse.ui.dialogs.SelectionDialog; 32 import org.eclipse.ui.texteditor.IDocumentProvider; 33 34 import org.eclipse.jdt.core.IClasspathEntry; 35 import org.eclipse.jdt.core.IJavaElement; 36 import org.eclipse.jdt.core.IJavaProject; 37 import org.eclipse.jdt.core.IPackageFragmentRoot; 38 import org.eclipse.jdt.core.ISourceReference; 39 import org.eclipse.jdt.core.JavaCore; 40 import org.eclipse.jdt.core.JavaModelException; 41 import org.eclipse.jdt.core.search.IJavaSearchConstants; 42 import org.eclipse.jdt.core.search.IJavaSearchScope; 43 import org.eclipse.jdt.core.search.SearchEngine; 44 45 import org.eclipse.jdt.internal.corext.javadoc.JavaDocLocations; 46 import org.eclipse.jdt.internal.corext.refactoring.reorg.JavaElementTransfer; 47 48 import org.eclipse.jdt.ui.dialogs.TypeSelectionExtension; 49 import org.eclipse.jdt.ui.text.IColorManager; 50 51 import org.eclipse.jdt.internal.ui.JavaPlugin; 52 import org.eclipse.jdt.internal.ui.JavaUIMessages; 53 import org.eclipse.jdt.internal.ui.SharedImages; 54 import org.eclipse.jdt.internal.ui.dialogs.FilteredTypesSelectionDialog; 55 import org.eclipse.jdt.internal.ui.dialogs.MainTypeSelectionDialog; 56 import org.eclipse.jdt.internal.ui.dialogs.MultiMainTypeSelectionDialog; 57 import org.eclipse.jdt.internal.ui.dialogs.PackageSelectionDialog; 58 import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility; 59 import org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext; 60 61 74 public final class JavaUI { 75 76 private static ISharedImages fgSharedImages= null; 77 78 private JavaUI() { 79 } 81 82 85 public static final String ID_PLUGIN= "org.eclipse.jdt.ui"; 87 91 public static final String ID_PERSPECTIVE= "org.eclipse.jdt.ui.JavaPerspective"; 93 97 public static final String ID_HIERARCHYPERSPECTIVE= "org.eclipse.jdt.ui.JavaHierarchyPerspective"; 99 103 public static final String ID_ACTION_SET= "org.eclipse.jdt.ui.JavaActionSet"; 105 111 public static final String ID_ELEMENT_CREATION_ACTION_SET= "org.eclipse.jdt.ui.JavaElementCreationActionSet"; 113 119 public static final String ID_CODING_ACTION_SET= "org.eclipse.jdt.ui.CodingActionSet"; 121 127 public static final String ID_OPEN_ACTION_SET= "org.eclipse.jdt.ui.A_OpenActionSet"; 129 135 public static final String ID_SEARCH_ACTION_SET= "org.eclipse.jdt.ui.SearchActionSet"; 137 141 public static final String ID_CU_EDITOR= "org.eclipse.jdt.ui.CompilationUnitEditor"; 143 147 public static final String ID_CF_EDITOR= "org.eclipse.jdt.ui.ClassFileEditor"; 149 153 public static final String ID_SNIPPET_EDITOR= "org.eclipse.jdt.ui.SnippetEditor"; 155 169 public static final String ID_PACKAGES= "org.eclipse.jdt.ui.PackageExplorer"; 171 185 public static final String ID_TYPE_HIERARCHY= "org.eclipse.jdt.ui.TypeHierarchy"; 187 195 public static final String ID_SOURCE_VIEW= "org.eclipse.jdt.ui.SourceView"; 197 205 public static final String ID_JAVADOC_VIEW= "org.eclipse.jdt.ui.JavadocView"; 207 213 public static String ID_BROWSING_PERSPECTIVE= "org.eclipse.jdt.ui.JavaBrowsingPerspective"; 215 221 public static String ID_PROJECTS_VIEW= "org.eclipse.jdt.ui.ProjectsView"; 223 229 public static String ID_PACKAGES_VIEW= "org.eclipse.jdt.ui.PackagesView"; 231 237 public static String ID_TYPES_VIEW= "org.eclipse.jdt.ui.TypesView"; 239 245 public static String ID_MEMBERS_VIEW= "org.eclipse.jdt.ui.MembersView"; 247 256 public final static String ATTR_CMDLINE= "org.eclipse.jdt.ui.launcher.cmdLine"; 258 259 262 private final static int DEPRECATED_CONSIDER_TYPES= IJavaElementSearchConstants.CONSIDER_TYPES; 263 264 269 public static ISharedImages getSharedImages() { 270 if (fgSharedImages == null) 271 fgSharedImages= new SharedImages(); 272 273 return fgSharedImages; 274 } 275 276 299 public static SelectionDialog createPackageDialog(Shell parent, IJavaProject project, int style, String filter) throws JavaModelException { 300 Assert.isTrue((style | IJavaElementSearchConstants.CONSIDER_BINARIES | IJavaElementSearchConstants.CONSIDER_REQUIRED_PROJECTS) == 301 (IJavaElementSearchConstants.CONSIDER_BINARIES | IJavaElementSearchConstants.CONSIDER_REQUIRED_PROJECTS)); 302 303 IPackageFragmentRoot[] roots= null; 304 if ((style & IJavaElementSearchConstants.CONSIDER_REQUIRED_PROJECTS) != 0) { 305 roots= project.getAllPackageFragmentRoots(); 306 } else { 307 roots= project.getPackageFragmentRoots(); 308 } 309 310 List consideredRoots= null; 311 if ((style & IJavaElementSearchConstants.CONSIDER_BINARIES) != 0) { 312 consideredRoots= Arrays.asList(roots); 313 } else { 314 consideredRoots= new ArrayList (roots.length); 315 for (int i= 0; i < roots.length; i++) { 316 IPackageFragmentRoot root= roots[i]; 317 if (root.getKind() != IPackageFragmentRoot.K_BINARY) 318 consideredRoots.add(root); 319 320 } 321 } 322 323 IJavaSearchScope searchScope= SearchEngine.createJavaSearchScope((IJavaElement[])consideredRoots.toArray(new IJavaElement[consideredRoots.size()])); 324 BusyIndicatorRunnableContext context= new BusyIndicatorRunnableContext(); 325 if (style == 0 || style == IJavaElementSearchConstants.CONSIDER_REQUIRED_PROJECTS) { 326 return createPackageDialog(parent, context, searchScope, false, true, filter); 327 } else { 328 return createPackageDialog(parent, context, searchScope, false, false, filter); 329 } 330 } 331 332 351 public static SelectionDialog createPackageDialog(Shell parent, IRunnableContext context, IJavaSearchScope scope, 352 boolean multipleSelection, boolean removeDuplicates, String filter) { 353 354 int flag= removeDuplicates ? PackageSelectionDialog.F_REMOVE_DUPLICATES : 0; 355 PackageSelectionDialog dialog= new PackageSelectionDialog(parent, context, flag, scope); 356 dialog.setFilter(filter); 357 dialog.setIgnoreCase(false); 358 dialog.setMultipleSelection(multipleSelection); 359 return dialog; 360 } 361 362 379 public static SelectionDialog createPackageDialog(Shell parent, IJavaProject project, int style) throws JavaModelException { 380 return createPackageDialog(parent, project, style, ""); } 382 383 401 public static SelectionDialog createPackageDialog(Shell parent, IPackageFragmentRoot root, String filter) throws JavaModelException { 402 IJavaSearchScope scope= SearchEngine.createJavaSearchScope(new IJavaElement[] {root}); 403 BusyIndicatorRunnableContext context= new BusyIndicatorRunnableContext(); 404 return createPackageDialog(parent, context, scope, false, true, filter); 405 } 406 407 419 public static SelectionDialog createPackageDialog(Shell parent, IPackageFragmentRoot root) throws JavaModelException { 420 return createPackageDialog(parent, root, ""); } 422 423 448 public static SelectionDialog createTypeDialog(Shell parent, IRunnableContext context, IProject project, int style, boolean multipleSelection) throws JavaModelException { 449 IJavaSearchScope scope= SearchEngine.createJavaSearchScope(new IJavaProject[] { JavaCore.create(project) }); 450 return createTypeDialog(parent, context, scope, style, multipleSelection); 451 } 452 453 478 public static SelectionDialog createTypeDialog(Shell parent, IRunnableContext context, IJavaSearchScope scope, int style, boolean multipleSelection) throws JavaModelException { 479 return createTypeDialog(parent, context, scope, style, multipleSelection, ""); } 481 482 513 public static SelectionDialog createTypeDialog(Shell parent, IRunnableContext context, IJavaSearchScope scope, int style, boolean multipleSelection, String filter) throws JavaModelException { 514 return createTypeDialog(parent, context, scope, style, multipleSelection, filter, null); 515 } 516 517 550 public static SelectionDialog createTypeDialog(Shell parent, IRunnableContext context, IJavaSearchScope scope, int style, 551 boolean multipleSelection, String filter, TypeSelectionExtension extension) throws JavaModelException { 552 int elementKinds= 0; 553 if (style == IJavaElementSearchConstants.CONSIDER_ALL_TYPES) { 554 elementKinds= IJavaSearchConstants.TYPE; 555 } else if (style == IJavaElementSearchConstants.CONSIDER_INTERFACES) { 556 elementKinds= IJavaSearchConstants.INTERFACE; 557 } else if (style == IJavaElementSearchConstants.CONSIDER_CLASSES) { 558 elementKinds= IJavaSearchConstants.CLASS; 559 } else if (style == IJavaElementSearchConstants.CONSIDER_ANNOTATION_TYPES) { 560 elementKinds= IJavaSearchConstants.ANNOTATION_TYPE; 561 } else if (style == IJavaElementSearchConstants.CONSIDER_ENUMS) { 562 elementKinds= IJavaSearchConstants.ENUM; 563 } else if (style == IJavaElementSearchConstants.CONSIDER_CLASSES_AND_INTERFACES) { 564 elementKinds= IJavaSearchConstants.CLASS_AND_INTERFACE; 565 } else if (style == IJavaElementSearchConstants.CONSIDER_CLASSES_AND_ENUMS) { 566 elementKinds= IJavaSearchConstants.CLASS_AND_ENUM; 567 } else if (style == DEPRECATED_CONSIDER_TYPES) { 568 elementKinds= IJavaSearchConstants.CLASS_AND_INTERFACE; 569 } else { 570 throw new IllegalArgumentException ("Invalid style constant."); } 572 FilteredTypesSelectionDialog dialog= new FilteredTypesSelectionDialog(parent, multipleSelection, 573 context, scope, elementKinds, extension); 574 dialog.setMessage(JavaUIMessages.JavaUI_defaultDialogMessage); 575 dialog.setInitialPattern(filter); 576 return dialog; 577 } 578 579 602 public static SelectionDialog createMainTypeDialog(Shell parent, IRunnableContext context, IJavaSearchScope scope, int style, boolean multipleSelection, String filter) { 603 if (multipleSelection) { 604 MultiMainTypeSelectionDialog dialog= new MultiMainTypeSelectionDialog(parent, context, scope, style); 605 dialog.setFilter(filter); 606 return dialog; 607 } else { 608 MainTypeSelectionDialog dialog= new MainTypeSelectionDialog(parent, context, scope, style); 609 dialog.setFilter(filter); 610 return dialog; 611 } 612 } 613 614 631 public static SelectionDialog createMainTypeDialog(Shell parent, IRunnableContext context, IJavaSearchScope scope, int style, boolean multipleSelection) { 632 return createMainTypeDialog(parent, context, scope, style, multipleSelection, ""); } 634 635 647 public static IEditorPart openInEditor(IJavaElement element) throws JavaModelException, PartInitException { 648 return openInEditor(element, true, true); 649 } 650 651 666 public static IEditorPart openInEditor(IJavaElement element, boolean activate, boolean reveal) throws JavaModelException, PartInitException { 667 if (!(element instanceof ISourceReference)) { 668 return null; 669 } 670 IEditorPart part= EditorUtility.openInEditor(element, activate); 671 if (reveal && part != null) { 672 EditorUtility.revealInEditor(part, element); 673 } 674 return part; 675 } 676 677 688 public static void revealInEditor(IEditorPart part, ISourceReference element) { 689 if (element instanceof IJavaElement) 690 revealInEditor(part, (IJavaElement) element); 691 } 692 693 705 public static void revealInEditor(IEditorPart part, IJavaElement element) { 706 EditorUtility.revealInEditor(part, element); 707 } 708 709 714 public static IWorkingCopyManager getWorkingCopyManager() { 715 return JavaPlugin.getDefault().getWorkingCopyManager(); 716 } 717 718 725 public static IJavaElement getEditorInputJavaElement(IEditorInput editorInput) { 726 IJavaElement je= JavaPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(editorInput); 728 if (je != null) 729 return je; 730 731 return (IJavaElement)editorInput.getAdapter(IJavaElement.class); 732 } 733 734 746 public static org.eclipse.jdt.core.IWorkingCopy[] getSharedWorkingCopies() { 747 return JavaCore.getSharedWorkingCopies(getBufferFactory()); 748 } 749 750 762 public static org.eclipse.jdt.core.IWorkingCopy[] getSharedWorkingCopiesOnClasspath() { 763 org.eclipse.jdt.core.IWorkingCopy[] wcs= getSharedWorkingCopies(); 764 List result= new ArrayList (wcs.length); 765 for (int i = 0; i < wcs.length; i++) { 766 org.eclipse.jdt.core.IWorkingCopy wc= wcs[i]; 767 if (wc instanceof IJavaElement) { 768 IJavaElement je= (IJavaElement)wc; 769 if (je.getJavaProject().isOnClasspath(je)) { 770 result.add(wc); 771 } 772 } 773 } 774 return (org.eclipse.jdt.core.IWorkingCopy[])result.toArray(new org.eclipse.jdt.core.IWorkingCopy[result.size()]); 775 } 776 777 788 public static org.eclipse.jdt.core.IBufferFactory getBufferFactory() { 789 return JavaPlugin.getDefault().getBufferFactory(); 790 } 791 792 800 public static IDocumentProvider getDocumentProvider() { 801 return JavaPlugin.getDefault().getCompilationUnitDocumentProvider(); 802 } 803 804 817 public static void setLibraryJavadocLocation(IPath archivePath, URL url) { 818 } 820 821 835 public static void setLibraryJavadocLocations(IPath[] archivePaths, URL [] urls) { 836 } 838 839 853 public static URL getLibraryJavadocLocation(IPath archivePath) { 854 return null; 855 } 856 857 869 public static URL getLibraryJavadocLocation(IClasspathEntry entry) { 870 return JavaDocLocations.getLibraryJavadocLocation(entry); 871 } 872 873 884 public static void setProjectJavadocLocation(IJavaProject project, URL url) { 885 JavaDocLocations.setProjectJavadocLocation(project, url); 886 } 887 888 898 public static URL getProjectJavadocLocation(IJavaProject project) { 899 return JavaDocLocations.getProjectJavadocLocation(project); 900 } 901 902 914 public static URL getJavadocBaseLocation(IJavaElement element) throws JavaModelException { 915 return JavaDocLocations.getJavadocBaseLocation(element); 916 } 917 918 934 public static URL getJavadocLocation(IJavaElement element, boolean includeAnchor) throws JavaModelException { 935 return JavaDocLocations.getJavadocLocation(element, includeAnchor); 936 } 937 938 962 public static Transfer getJavaElementClipboardTransfer() { 963 return JavaElementTransfer.getInstance(); 964 } 965 966 973 public static IColorManager getColorManager() { 974 return JavaPlugin.getDefault().getJavaTextTools().getColorManager(); 975 } 976 } 977 | Popular Tags |