1 11 package org.eclipse.jdt.internal.ui.actions; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 15 16 import org.eclipse.swt.widgets.Shell; 17 18 import org.eclipse.jface.window.Window; 19 20 import org.eclipse.ui.IEditorPart; 21 import org.eclipse.ui.PartInitException; 22 import org.eclipse.ui.dialogs.ElementListSelectionDialog; 23 24 import org.eclipse.jdt.core.IJavaElement; 25 import org.eclipse.jdt.core.ISourceReference; 26 import org.eclipse.jdt.core.JavaModelException; 27 28 import org.eclipse.jdt.ui.JavaElementLabelProvider; 29 30 import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility; 31 32 public class OpenActionUtil { 33 34 private OpenActionUtil() { 35 } 37 38 41 public static void open(Object element) throws JavaModelException, PartInitException { 42 open(element, true); 43 } 44 45 48 public static void open(Object element, boolean activate) throws JavaModelException, PartInitException { 49 IEditorPart part= EditorUtility.openInEditor(element, activate); 50 if (element instanceof IJavaElement) 51 EditorUtility.revealInEditor(part, (IJavaElement)element); 52 } 53 54 58 public static List filterResolveResults(IJavaElement[] codeResolveResults) { 59 int nResults= codeResolveResults.length; 60 List refs= new ArrayList (nResults); 61 for (int i= 0; i < nResults; i++) { 62 if (codeResolveResults[i] instanceof ISourceReference) 63 refs.add(codeResolveResults[i]); 64 } 65 return refs; 66 } 67 68 72 public static IJavaElement selectJavaElement(IJavaElement[] elements, Shell shell, String title, String message) { 73 74 int nResults= elements.length; 75 76 if (nResults == 0) 77 return null; 78 79 if (nResults == 1) 80 return elements[0]; 81 82 int flags= JavaElementLabelProvider.SHOW_DEFAULT 83 | JavaElementLabelProvider.SHOW_QUALIFIED 84 | JavaElementLabelProvider.SHOW_ROOT; 85 86 ElementListSelectionDialog dialog= new ElementListSelectionDialog(shell, new JavaElementLabelProvider(flags)); 87 dialog.setTitle(title); 88 dialog.setMessage(message); 89 dialog.setElements(elements); 90 91 if (dialog.open() == Window.OK) { 92 Object [] selection= dialog.getResult(); 93 if (selection != null && selection.length > 0) { 94 nResults= selection.length; 95 for (int i= 0; i < nResults; i++) { 96 Object current= selection[i]; 97 if (current instanceof IJavaElement) 98 return (IJavaElement) current; 99 } 100 } 101 } 102 return null; 103 } 104 } 105 | Popular Tags |