KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > text > ResourceHyperlink


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 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 package org.eclipse.pde.internal.ui.editor.text;
12
13 import org.eclipse.core.resources.IFile;
14 import org.eclipse.core.resources.IResource;
15 import org.eclipse.jdt.ui.IPackagesViewPart;
16 import org.eclipse.jdt.ui.JavaUI;
17 import org.eclipse.jface.text.IRegion;
18 import org.eclipse.pde.internal.ui.PDEPlugin;
19 import org.eclipse.ui.PartInitException;
20 import org.eclipse.ui.ide.IDE;
21
22 public class ResourceHyperlink extends AbstractHyperlink {
23
24     private IResource fResource;
25     
26     public ResourceHyperlink(IRegion region, String JavaDoc element, IResource res) {
27         super(region, element);
28         fResource = res;
29     }
30
31     public void open() {
32         if (fResource == null)
33             return;
34         if (fElement.indexOf("$nl$/") == 0) //$NON-NLS-1$
35
fElement = fElement.substring(5);
36         fResource = fResource.getProject().findMember(fElement);
37         try {
38             if (fResource instanceof IFile)
39                 IDE.openEditor(PDEPlugin.getActivePage(), (IFile)fResource, true);
40             else if (fResource != null) {
41                 IPackagesViewPart part = (IPackagesViewPart)PDEPlugin.getActivePage().showView(JavaUI.ID_PACKAGES);
42                 part.selectAndReveal(fResource);
43             }
44         } catch (PartInitException e) {
45             PDEPlugin.logException(e);
46         }
47     }
48
49 }
50
Popular Tags