Package de.innovationgate.eclipse.editors.tml

Source Code of de.innovationgate.eclipse.editors.tml.TMLModuleReferenceHyperlink

/*******************************************************************************
* 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.editors.ResourceIDs;
import de.innovationgate.eclipse.utils.WorkbenchUtils;
import de.innovationgate.eclipse.utils.wga.WGADesignStructureHelper;

/**
* represents an hyperlink to a referenced tml-module for e.g. in tml:include or
* tml:portlet
*
*
*
*/
public class TMLModuleReferenceHyperlink implements IHyperlink {

  private IRegion _region;
  private String _reference;
  private ITextViewer _viewer;
  private TMLRegion _tmlRegion;

  public TMLModuleReferenceHyperlink(ITextViewer viewer, IRegion region, TMLRegion tmlRegion) throws BadLocationException {
    _region = region;
    _viewer = viewer;
    _reference = _viewer.getDocument().get(_region.getOffset(), _region.getLength());
    _tmlRegion = tmlRegion;
  }

  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.findReferencedTMLModule(file, _reference, _tmlRegion.getAttributeValue("medium"));
      if (referenceFile != null) {
        if (Plugin.getDefault().isDebugging()) {
          System.out.println(referenceFile.getProjectRelativePath());
        }
        try {
          WorkbenchUtils.openEditor(Plugin.getDefault().getWorkbench(), referenceFile, ResourceIDs.EDITOR_TML);
        } catch (PartInitException e) {
          Plugin.getDefault().logError("Unable to open editor for reference '" + _reference + "'.", e);
        }
      }
    }
  }

}
TOP

Related Classes of de.innovationgate.eclipse.editors.tml.TMLModuleReferenceHyperlink

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.