1 11 package org.eclipse.jdt.ui.actions; 12 13 import org.eclipse.swt.widgets.Shell; 14 15 import org.eclipse.jface.viewers.IStructuredSelection; 16 17 import org.eclipse.jface.text.ITextSelection; 18 19 import org.eclipse.ui.IEditorInput; 20 import org.eclipse.ui.IWorkbenchSite; 21 import org.eclipse.ui.PlatformUI; 22 import org.eclipse.ui.texteditor.IEditorStatusLine; 23 24 import org.eclipse.jdt.core.IJavaElement; 25 import org.eclipse.jdt.core.IMember; 26 import org.eclipse.jdt.core.JavaModelException; 27 28 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; 29 import org.eclipse.jdt.internal.ui.JavaPlugin; 30 import org.eclipse.jdt.internal.ui.actions.ActionMessages; 31 import org.eclipse.jdt.internal.ui.actions.ActionUtil; 32 import org.eclipse.jdt.internal.ui.javaeditor.IClassFileEditorInput; 33 import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor; 34 import org.eclipse.jdt.internal.ui.search.ExceptionOccurrencesFinder; 35 import org.eclipse.jdt.internal.ui.search.FindOccurrencesEngine; 36 37 46 public class FindExceptionOccurrencesAction extends SelectionDispatchAction { 47 48 private JavaEditor fEditor; 49 50 55 public FindExceptionOccurrencesAction(JavaEditor editor) { 56 this(editor.getEditorSite()); 57 fEditor= editor; 58 setEnabled(getEditorInput(editor) != null); 59 } 60 61 68 public FindExceptionOccurrencesAction(IWorkbenchSite site) { 69 super(site); 70 setText(ActionMessages.FindExceptionOccurrences_text); 71 setToolTipText(ActionMessages.FindExceptionOccurrences_toolTip); 72 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.FIND_EXCEPTION_OCCURRENCES); 73 } 74 75 77 80 public void selectionChanged(ITextSelection selection) { 81 } 82 83 88 public void selectionChanged(IStructuredSelection selection) { 89 setEnabled(getMember(selection) != null); 90 } 91 92 95 public final void run(ITextSelection ts) { 96 IJavaElement input= getEditorInput(fEditor); 97 if (!ActionUtil.isProcessable(getShell(), input)) 98 return; 99 FindOccurrencesEngine engine= FindOccurrencesEngine.create(input, new ExceptionOccurrencesFinder()); 100 try { 101 String result= engine.run(ts.getOffset(), ts.getLength()); 102 if (result != null) 103 showMessage(getShell(), fEditor, result); 104 } catch (JavaModelException e) { 105 JavaPlugin.log(e); 106 } 107 } 108 109 private static IJavaElement getEditorInput(JavaEditor editor) { 110 IEditorInput input= editor.getEditorInput(); 111 if (input instanceof IClassFileEditorInput) 112 return ((IClassFileEditorInput)input).getClassFile(); 113 return JavaPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(input); 114 } 115 116 private static void showMessage(Shell shell, JavaEditor editor, String msg) { 117 IEditorStatusLine statusLine= (IEditorStatusLine) editor.getAdapter(IEditorStatusLine.class); 118 if (statusLine != null) 119 statusLine.setMessage(true, msg, null); 120 shell.getDisplay().beep(); 121 } 122 123 private IMember getMember(IStructuredSelection selection) { 124 return null; 125 } 126 } 127 | Popular Tags |