1 11 12 package org.eclipse.jdt.internal.ui.navigator; 13 14 import org.eclipse.core.resources.IFile; 15 16 import org.eclipse.jface.viewers.IStructuredSelection; 17 import org.eclipse.jface.viewers.StructuredSelection; 18 19 import org.eclipse.ui.IEditorInput; 20 import org.eclipse.ui.IEditorPart; 21 import org.eclipse.ui.IWorkbenchPage; 22 import org.eclipse.ui.navigator.ILinkHelper; 23 24 import org.eclipse.ui.ide.ResourceUtil; 25 26 import org.eclipse.jdt.core.IJavaElement; 27 import org.eclipse.jdt.core.JavaCore; 28 29 import org.eclipse.jdt.ui.JavaUI; 30 31 import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility; 32 33 public class JavaFileLinkHelper implements ILinkHelper { 34 35 public void activateEditor(IWorkbenchPage page, IStructuredSelection selection) { 36 if (selection == null || selection.isEmpty()) 37 return; 38 Object element= selection.getFirstElement(); 39 IEditorPart part= EditorUtility.isOpenInEditor(element); 40 if (part != null) { 41 page.bringToTop(part); 42 if (element instanceof IJavaElement) 43 EditorUtility.revealInEditor(part, (IJavaElement) element); 44 } 45 46 } 47 48 public IStructuredSelection findSelection(IEditorInput input) { 49 IJavaElement element= JavaUI.getEditorInputJavaElement(input); 50 if (element == null) { 51 IFile file = ResourceUtil.getFile(input); 52 if (file != null) { 53 element= JavaCore.create(file); 54 } 55 } 56 return (element != null) ? new StructuredSelection(element) : StructuredSelection.EMPTY; 57 } 58 59 } 60 | Popular Tags |