| /******************************************************************************* |
| * Copyright (c) 2014 Christian Pontesegger and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v2.0 |
| * which accompanies this distribution, and is available at |
| * https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * Contributors: |
| * Christian Pontesegger - initial API and implementation |
| *******************************************************************************/ |
| package org.eclipse.ease.lang.javascript.ui; |
| |
| import org.eclipse.core.resources.IFile; |
| import org.eclipse.jface.text.IRegion; |
| import org.eclipse.jface.text.hyperlink.IHyperlink; |
| import org.eclipse.ui.IEditorDescriptor; |
| import org.eclipse.ui.PartInitException; |
| import org.eclipse.ui.PlatformUI; |
| import org.eclipse.ui.editors.text.EditorsUI; |
| import org.eclipse.ui.part.FileEditorInput; |
| |
| public class ResourceHyperlink implements IHyperlink { |
| |
| private final IRegion fRegion; |
| private final IFile fFile; |
| |
| public ResourceHyperlink(final IFile file, final IRegion region) { |
| fFile = file; |
| fRegion = region; |
| } |
| |
| @Override |
| public IRegion getHyperlinkRegion() { |
| return fRegion; |
| } |
| |
| @Override |
| public String getTypeLabel() { |
| return null; |
| } |
| |
| @Override |
| public String getHyperlinkText() { |
| return "Open in editor"; |
| } |
| |
| @Override |
| public void open() { |
| IEditorDescriptor descriptor = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(fFile.getName()); |
| if (descriptor == null) |
| descriptor = PlatformUI.getWorkbench().getEditorRegistry().findEditor(EditorsUI.DEFAULT_TEXT_EDITOR_ID); |
| |
| if (descriptor != null) { |
| final IEditorDescriptor editorDescriptor = descriptor; |
| try { |
| PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(new FileEditorInput(fFile), editorDescriptor.getId()); |
| } catch (PartInitException e) { |
| // cannot open editor, ignore |
| e.printStackTrace(); |
| } |
| } |
| } |
| } |