1 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 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(); } catch (CoreException e) { 49 PDEPlugin.logException(e); 50 } 51 } 52 53 } 54 | Popular Tags |