/*******************************************************************************
* Copyright (c) 2009, 2010 Innovation Gate GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Innovation Gate GmbH - initial API and implementation
******************************************************************************/
package de.innovationgate.eclipse.editors.tml;
import org.eclipse.core.resources.IFile;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.hyperlink.IHyperlink;
import org.eclipse.ui.PartInitException;
import de.innovationgate.eclipse.editors.Plugin;
import de.innovationgate.eclipse.utils.WorkbenchUtils;
import de.innovationgate.eclipse.utils.wga.WGADesignStructureHelper;
/**
* represents an hyperlink to a referenced script for e.g. css or js
*
*
*
*/
public class ScriptReferenceHyperlink implements IHyperlink {
private IRegion _region;
private String _reference;
private ITextViewer _viewer;
private TMLRegion _tmlRegion;
private String _scriptType;
public ScriptReferenceHyperlink(ITextViewer viewer, IRegion region, TMLRegion tmlRegion, String scriptType) throws BadLocationException {
_region = region;
_viewer = viewer;
_reference = _viewer.getDocument().get(_region.getOffset(), _region.getLength());
_tmlRegion = tmlRegion;
_scriptType = scriptType;
}
public IRegion getHyperlinkRegion() {
return _region;
}
public String getHyperlinkText() {
return _reference;
}
public String getTypeLabel() {
return null;
}
public void open() {
IFile file = Plugin.getDefault().getActiveFile();
if (file != null) {
IFile referenceFile = WGADesignStructureHelper.findReferencedScript(file, _reference, _scriptType);
if (referenceFile != null) {
if (Plugin.getDefault().isDebugging()) {
System.out.println(referenceFile.getProjectRelativePath());
}
try {
WorkbenchUtils.openEditor(Plugin.getDefault().getWorkbench(), referenceFile);
} catch (PartInitException e) {
Plugin.getDefault().logError("Unable to open editor for reference '" + _reference + "'.", e);
}
}
}
}
}