KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > commands > OpenElementInEditorHandler


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  ******************************************************************************/

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 /**
26  * A command handler to open a java element in its editor.
27  *
28  * @since 3.2
29  */

30 public class OpenElementInEditorHandler extends AbstractHandler {
31
32     private static final String JavaDoc PARAM_ID_ELEMENT_REF= "elementRef"; //$NON-NLS-1$
33

34     public Object JavaDoc 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); //$NON-NLS-1$
43
} catch (PartInitException ex) {
44             throw new ExecutionException("Error opening java element in editor", ex); //$NON-NLS-1$
45
}
46
47         return null;
48     }
49
50 }
51
Popular Tags