1 11 package org.eclipse.jdt.internal.ui.actions; 12 13 import org.eclipse.jdt.core.IJavaElement; 14 import org.eclipse.jdt.core.JavaModelException; 15 16 import org.eclipse.swt.widgets.Shell; 17 18 import org.eclipse.jface.text.ITextSelection; 19 20 import org.eclipse.ui.IEditorInput; 21 import org.eclipse.ui.IWorkbenchSite; 22 import org.eclipse.ui.help.WorkbenchHelp; 23 import org.eclipse.ui.texteditor.IEditorStatusLine; 24 25 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; 26 import org.eclipse.jdt.internal.ui.JavaPlugin; 27 import org.eclipse.jdt.internal.ui.javaeditor.IClassFileEditorInput; 28 import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor; 29 import org.eclipse.jdt.internal.ui.search.FindOccurrencesEngine; 30 import org.eclipse.jdt.internal.ui.search.ExceptionOccurrencesFinder; 31 32 import org.eclipse.jdt.ui.actions.SelectionDispatchAction; 33 34 35 44 public class FindExceptionOccurrences extends SelectionDispatchAction { 45 46 private JavaEditor fEditor; 47 48 51 public FindExceptionOccurrences(JavaEditor editor) { 52 this(editor.getEditorSite()); 53 fEditor= editor; 54 setEnabled(getEditorInput(editor) != null); 55 } 56 57 private FindExceptionOccurrences(IWorkbenchSite site) { 58 super(site); 59 setText(ActionMessages.getString("FindExceptionOccurrences.text")); setToolTipText(ActionMessages.getString("FindExceptionOccurrences.toolTip")); WorkbenchHelp.setHelp(this, IJavaHelpContextIds.FIND_EXCEPTION_OCCURRENCES); 62 } 63 64 66 69 public void selectionChanged(ITextSelection selection) { 70 } 71 72 75 public final void run(ITextSelection ts) { 76 IJavaElement input= getEditorInput(fEditor); 77 if (!ActionUtil.isProcessable(getShell(), input)) 78 return; 79 FindOccurrencesEngine engine= FindOccurrencesEngine.create(input, new ExceptionOccurrencesFinder()); 80 try { 81 String result= engine.run(ts.getOffset(), ts.getLength()); 82 if (result != null) 83 showMessage(getShell(), fEditor, result); 84 } catch (JavaModelException e) { 85 JavaPlugin.log(e); 86 } 87 } 88 89 private static IJavaElement getEditorInput(JavaEditor editor) { 90 IEditorInput input= editor.getEditorInput(); 91 if (input instanceof IClassFileEditorInput) 92 return ((IClassFileEditorInput)input).getClassFile(); 93 return JavaPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(input); 94 } 95 96 private static void showMessage(Shell shell, JavaEditor editor, String msg) { 97 IEditorStatusLine statusLine= (IEditorStatusLine) editor.getAdapter(IEditorStatusLine.class); 98 if (statusLine != null) 99 statusLine.setMessage(true, msg, null); 100 shell.getDisplay().beep(); 101 } 102 } 103 | Popular Tags |