1 /*******************************************************************************
2 * Copyright (c) 2000, 2008 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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
12 package org.eclipse.jdt.internal.ui.navigator;
14 import org.eclipse.core.resources.IFile;
16 import org.eclipse.jface.viewers.IStructuredSelection;
17 import org.eclipse.jface.viewers.StructuredSelection;
19 import org.eclipse.ui.IEditorInput;
20 import org.eclipse.ui.IEditorPart;
21 import org.eclipse.ui.IWorkbenchPage;
22 import org.eclipse.ui.ide.ResourceUtil;
23 import org.eclipse.ui.navigator.ILinkHelper;
25 import org.eclipse.jdt.core.IJavaElement;
26 import org.eclipse.jdt.core.JavaCore;
28 import org.eclipse.jdt.ui.JavaUI;
30 import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
32 public class JavaFileLinkHelper implements ILinkHelper {
34 public void activateEditor(IWorkbenchPage page, IStructuredSelection selection) {
35 if (selection == null || selection.isEmpty())
37 Object element= selection.getFirstElement();
38 IEditorPart part= EditorUtility.isOpenInEditor(element);
40 page.bringToTop(part);
41 if (element instanceof IJavaElement)
42 EditorUtility.revealInEditor(part, (IJavaElement) element);
47 public IStructuredSelection findSelection(IEditorInput input) {
48 IJavaElement element= JavaUI.getEditorInputJavaElement(input);
49 if (element == null) {
50 IFile file = ResourceUtil.getFile(input);
52 element= JavaCore.create(file);
55 return (element != null) ? new StructuredSelection(element) : StructuredSelection.EMPTY;