bchilds | 68f36fc | 2007-03-01 22:47:33 +0000 | [diff] [blame] | 1 | package org.eclipse.wst.jsdt.web.ui.internal.hyperlink; |
| 2 | |
| 3 | import java.io.File; |
| 4 | |
| 5 | import org.eclipse.jface.text.IRegion; |
| 6 | import org.eclipse.jface.text.hyperlink.IHyperlink; |
bchilds | 68f36fc | 2007-03-01 22:47:33 +0000 | [diff] [blame] | 7 | import org.eclipse.ui.IEditorDescriptor; |
| 8 | import org.eclipse.ui.IEditorInput; |
| 9 | import org.eclipse.ui.IWorkbenchPage; |
| 10 | import org.eclipse.ui.PartInitException; |
| 11 | import org.eclipse.ui.PlatformUI; |
| 12 | import org.eclipse.ui.ide.IDE; |
bchilds | 133806a | 2007-03-27 15:52:39 +0000 | [diff] [blame] | 13 | import org.eclipse.wst.jsdt.web.ui.internal.Logger; |
bchilds | 68f36fc | 2007-03-01 22:47:33 +0000 | [diff] [blame] | 14 | |
| 15 | /** |
| 16 | * Hyperlink for external files. |
| 17 | */ |
| 18 | class ExternalFileHyperlink implements IHyperlink { |
| 19 | // copies of this class exist in: |
| 20 | // org.eclipse.wst.xml.ui.internal.hyperlink |
| 21 | // org.eclipse.wst.html.ui.internal.hyperlink |
| 22 | // org.eclipse.wst.jsdt.web.ui.internal.hyperlink |
| 23 | |
| 24 | private IRegion fHyperlinkRegion; |
| 25 | private File fHyperlinkFile; |
| 26 | |
| 27 | public ExternalFileHyperlink(IRegion region, File file) { |
| 28 | fHyperlinkFile = file; |
| 29 | fHyperlinkRegion = region; |
| 30 | } |
| 31 | |
| 32 | public IRegion getHyperlinkRegion() { |
| 33 | return fHyperlinkRegion; |
| 34 | } |
| 35 | |
| 36 | public String getTypeLabel() { |
| 37 | return null; |
| 38 | } |
| 39 | |
| 40 | public String getHyperlinkText() { |
| 41 | return null; |
| 42 | } |
| 43 | |
| 44 | public void open() { |
| 45 | if (fHyperlinkFile != null) { |
| 46 | IEditorInput input = new ExternalFileEditorInput(fHyperlinkFile); |
| 47 | IEditorDescriptor descriptor; |
| 48 | try { |
| 49 | descriptor = IDE.getEditorDescriptor(input.getName(), true); |
| 50 | if (descriptor != null) { |
| 51 | IWorkbenchPage page = PlatformUI.getWorkbench() |
| 52 | .getActiveWorkbenchWindow().getActivePage(); |
| 53 | IDE.openEditor(page, input, descriptor.getId(), true); |
| 54 | } |
| 55 | } catch (PartInitException e) { |
| 56 | Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | } |