KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > navigator > JavaFileLinkHelper


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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
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 JavaDoc 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