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.FindOccurrencesEngine; 35 import org.eclipse.jdt.internal.ui.search.ImplementOccurrencesFinder; 36 37 45 public class FindImplementOccurrencesAction extends SelectionDispatchAction { 46 47 private JavaEditor fEditor; 48 49 54 public FindImplementOccurrencesAction(JavaEditor editor) { 55 this(editor.getEditorSite()); 56 fEditor= editor; 57 setEnabled(getEditorInput(editor) != null); 58 } 59 60 67 public FindImplementOccurrencesAction(IWorkbenchSite site) { 68 super(site); 69 setText(ActionMessages.FindImplementOccurrencesAction_text); 70 setToolTipText(ActionMessages.FindImplementOccurrencesAction_toolTip); 71 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.FIND_IMPLEMENT_OCCURRENCES); 72 } 73 74 76 79 public void selectionChanged(ITextSelection selection) { 80 } 81 82 87 public void selectionChanged(IStructuredSelection selection) { 88 setEnabled(getMember(selection) != null); 89 } 90 91 94 public final void run(ITextSelection ts) { 95 IJavaElement input= getEditorInput(fEditor); 96 if (!ActionUtil.isProcessable(getShell(), input)) 97 return; 98 FindOccurrencesEngine engine= FindOccurrencesEngine.create(input, new ImplementOccurrencesFinder()); 99 try { 100 String result= engine.run(ts.getOffset(), ts.getLength()); 101 if (result != null) 102 showMessage(getShell(), fEditor, result); 103 } catch (JavaModelException e) { 104 JavaPlugin.log(e); 105 } 106 } 107 108 private static IJavaElement getEditorInput(JavaEditor editor) { 109 IEditorInput input= editor.getEditorInput(); 110 if (input instanceof IClassFileEditorInput) 111 return ((IClassFileEditorInput)input).getClassFile(); 112 return JavaPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(input); 113 } 114 115 private static void showMessage(Shell shell, JavaEditor editor, String msg) { 116 IEditorStatusLine statusLine= (IEditorStatusLine) editor.getAdapter(IEditorStatusLine.class); 117 if (statusLine != null) 118 statusLine.setMessage(true, msg, null); 119 shell.getDisplay().beep(); 120 } 121 122 private IMember getMember(IStructuredSelection selection) { 123 return null; 124 } 125 } 126 | Popular Tags |