1 11 package org.eclipse.jdt.internal.ui.commands; 12 13 import org.eclipse.core.commands.AbstractHandler; 14 import org.eclipse.core.commands.ExecutionEvent; 15 import org.eclipse.core.commands.ExecutionException; 16 17 import org.eclipse.ui.IEditorPart; 18 import org.eclipse.ui.PartInitException; 19 20 import org.eclipse.jdt.core.IJavaElement; 21 import org.eclipse.jdt.core.JavaModelException; 22 23 import org.eclipse.jdt.ui.JavaUI; 24 25 30 public class OpenElementInEditorHandler extends AbstractHandler { 31 32 private static final String PARAM_ID_ELEMENT_REF= "elementRef"; 34 public Object execute(ExecutionEvent event) throws ExecutionException { 35 36 IJavaElement javaElement= (IJavaElement) event.getObjectParameterForExecution(PARAM_ID_ELEMENT_REF); 37 38 try { 39 IEditorPart editorPart= JavaUI.openInEditor(javaElement); 40 JavaUI.revealInEditor(editorPart, javaElement); 41 } catch (JavaModelException ex) { 42 throw new ExecutionException("Error opening java element in editor", ex); } catch (PartInitException ex) { 44 throw new ExecutionException("Error opening java element in editor", ex); } 46 47 return null; 48 } 49 50 } 51 | Popular Tags |