/******************************************************************************* * Copyright (c) 2007, 2011 IBM Corporation and others. * 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: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.wst.jsdt.web.ui.internal.hyperlink; import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.hyperlink.IHyperlink; import org.eclipse.osgi.util.NLS; import org.eclipse.ui.IEditorPart; import org.eclipse.wst.html.ui.internal.HTMLUIMessages; import org.eclipse.wst.jsdt.core.IJavaScriptElement; import org.eclipse.wst.jsdt.internal.ui.actions.ActionMessages; import org.eclipse.wst.jsdt.ui.JavaScriptUI; import org.eclipse.wst.jsdt.web.ui.internal.Logger; /** * * Provisional API: This class/interface is part of an interim API that is still under development and expected to * change significantly before reaching stability. It is being made available at this early stage to solicit feedback * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken * (repeatedly) as the API evolves. */ class JSDTHyperlink implements IHyperlink { private IJavaScriptElement fElement; private IRegion fRegion; public JSDTHyperlink(IRegion region, IJavaScriptElement element) { fRegion = region; fElement = element; } /* * (non-Javadoc) * * @see org.eclipse.jface.text.hyperlink.IHyperlink#getHyperlinkRegion() */ public IRegion getHyperlinkRegion() { return fRegion; } /* * (non-Javadoc) * * @see org.eclipse.jface.text.hyperlink.IHyperlink#getHyperlinkText() */ public String getHyperlinkText() { return fElement != null ? NLS.bind(HTMLUIMessages.Open, fElement.getDisplayName()) : ActionMessages.OpenAction_declaration_label; } /* * (non-Javadoc) * * @see org.eclipse.jface.text.hyperlink.IHyperlink#getTypeLabel() */ public String getTypeLabel() { return null; } /* * (non-Javadoc) * * @see org.eclipse.jface.text.hyperlink.IHyperlink#open() */ public void open() { try { IEditorPart editor = JavaScriptUI.openInEditor(fElement); if (editor != null) { JavaScriptUI.revealInEditor(editor, fElement); } } catch (Exception e) { Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); } } }