KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > navigator > resources > workbench > ResourceLinkHelper


1 /*******************************************************************************
2  * Copyright (c) 2006, 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.ui.internal.navigator.resources.workbench;
13
14 import org.eclipse.core.resources.IFile;
15 import org.eclipse.jface.viewers.IStructuredSelection;
16 import org.eclipse.jface.viewers.StructuredSelection;
17 import org.eclipse.ui.IEditorInput;
18 import org.eclipse.ui.IEditorPart;
19 import org.eclipse.ui.IWorkbenchPage;
20 import org.eclipse.ui.ide.ResourceUtil;
21 import org.eclipse.ui.navigator.ILinkHelper;
22 import org.eclipse.ui.part.FileEditorInput;
23
24 /**
25  *
26  * Links IFileEditorInput to IFiles, and vice versa.
27  *
28  * @since 3.2
29  *
30  */

31 public class ResourceLinkHelper implements ILinkHelper {
32
33     /* (non-Javadoc)
34      * @see org.eclipse.ui.navigator.ILinkHelper#findSelection(org.eclipse.ui.IEditorInput)
35      */

36     public IStructuredSelection findSelection(IEditorInput anInput) {
37         IFile file = ResourceUtil.getFile(anInput);
38         if (file != null) {
39             return new StructuredSelection(file);
40         }
41         return StructuredSelection.EMPTY;
42     }
43
44     /* (non-Javadoc)
45      * @see org.eclipse.ui.navigator.ILinkHelper#activateEditor(org.eclipse.ui.IWorkbenchPage, org.eclipse.jface.viewers.IStructuredSelection)
46      */

47     public void activateEditor(IWorkbenchPage aPage,
48             IStructuredSelection aSelection) {
49         if (aSelection == null || aSelection.isEmpty())
50             return;
51         if (aSelection.getFirstElement() instanceof IFile) {
52             IEditorInput fileInput = new FileEditorInput((IFile) aSelection.getFirstElement());
53             IEditorPart editor = null;
54             if ((editor = aPage.findEditor(fileInput)) != null)
55                 aPage.bringToTop(editor);
56         }
57
58     }
59
60 }
61
Popular Tags