KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > text > JavaHyperlink


1 /*******************************************************************************
2  * Copyright (c) 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.pde.internal.ui.editor.text;
12
13 import org.eclipse.core.resources.IResource;
14 import org.eclipse.core.runtime.CoreException;
15 import org.eclipse.jdt.core.IJavaElement;
16 import org.eclipse.jdt.core.IJavaProject;
17 import org.eclipse.jdt.core.JavaCore;
18 import org.eclipse.jdt.core.JavaModelException;
19 import org.eclipse.jdt.ui.JavaUI;
20 import org.eclipse.jface.text.IRegion;
21 import org.eclipse.pde.internal.ui.PDEPlugin;
22 import org.eclipse.swt.widgets.Display;
23 import org.eclipse.ui.PartInitException;
24
25 public class JavaHyperlink extends AbstractHyperlink {
26
27     private IResource fResource;
28
29     public JavaHyperlink(IRegion region, String JavaDoc clazz, IResource res) {
30         super(region, clazz);
31         fResource = res;
32     }
33
34     public void open() {
35         try {
36             if (fResource == null)
37                 return;
38             if (fResource.getProject().hasNature(JavaCore.NATURE_ID)) {
39                 IJavaProject javaProject = JavaCore.create(fResource.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 }
54
Popular Tags