01: /*******************************************************************************
02: * Copyright (c) 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.ui.editor.text;
11:
12: import org.eclipse.core.resources.IResource;
13: import org.eclipse.core.runtime.CoreException;
14: import org.eclipse.jdt.core.IJavaElement;
15: import org.eclipse.jdt.core.IJavaProject;
16: import org.eclipse.jdt.core.JavaCore;
17: import org.eclipse.jdt.core.JavaModelException;
18: import org.eclipse.jdt.ui.JavaUI;
19: import org.eclipse.jface.text.IRegion;
20: import org.eclipse.pde.internal.ui.PDEPlugin;
21: import org.eclipse.swt.widgets.Display;
22: import org.eclipse.ui.PartInitException;
23:
24: public class JavaHyperlink extends AbstractHyperlink {
25:
26: private IResource fResource;
27:
28: public JavaHyperlink(IRegion region, String clazz, IResource res) {
29: super (region, clazz);
30: fResource = res;
31: }
32:
33: public void open() {
34: try {
35: if (fResource == null)
36: return;
37: if (fResource.getProject().hasNature(JavaCore.NATURE_ID)) {
38: IJavaProject javaProject = JavaCore.create(fResource
39: .getProject());
40: IJavaElement result = javaProject.findType(fElement);
41: if (result != null)
42: JavaUI.openInEditor(result);
43: }
44: } catch (PartInitException e) {
45: PDEPlugin.logException(e);
46: } catch (JavaModelException e) {
47: Display.getCurrent().beep(); // just for Dejan
48: } catch (CoreException e) {
49: PDEPlugin.logException(e);
50: }
51: }
52:
53: }
|