]> git.uio.no Git - ifi-stolz-refaktor.git/blob - case-study/jdt-after/ui/org/eclipse/jdt/internal/ui/navigator/JavaFileLinkHelper.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-after / ui / org / eclipse / jdt / internal / ui / navigator / JavaFileLinkHelper.java
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
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.ide.ResourceUtil;
23 import org.eclipse.ui.navigator.ILinkHelper;
24
25 import org.eclipse.jdt.core.IJavaElement;
26 import org.eclipse.jdt.core.JavaCore;
27
28 import org.eclipse.jdt.ui.JavaUI;
29
30 import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
31
32 public class JavaFileLinkHelper implements ILinkHelper {
33
34         public void activateEditor(IWorkbenchPage page, IStructuredSelection selection) {
35                 if (selection == null || selection.isEmpty())
36                         return;
37                 Object element= selection.getFirstElement();
38                 IEditorPart part= EditorUtility.isOpenInEditor(element);
39                 if (part != null) {
40                         page.bringToTop(part);
41                         if (element instanceof IJavaElement)
42                                 EditorUtility.revealInEditor(part, (IJavaElement) element);
43                 }
44
45         }
46
47         public IStructuredSelection findSelection(IEditorInput input) {
48                 IJavaElement element= JavaUI.getEditorInputJavaElement(input);
49                 if (element == null) {
50                         IFile file = ResourceUtil.getFile(input);
51                         if (file != null) {
52                                 element= JavaCore.create(file);
53                         }
54                 }
55                 return (element != null) ? new StructuredSelection(element) : StructuredSelection.EMPTY;
56         }
57
58 }