Package de.innovationgate.eclipse.editors.tml

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

/*******************************************************************************
* 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.core.runtime.CoreException;
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 de.innovationgate.eclipse.editors.Plugin;
import de.innovationgate.eclipse.editors.helpers.LabelFileLookup;
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 TMLLabelHyperlink implements IHyperlink {

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

  public TMLLabelHyperlink(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) {
      String labelFilename = LabelFileLookup.determineLabelFileName(_tmlRegion);
      IFile referenceFile = null;
      try {
        if (labelFilename != null) {
          referenceFile = new WGADesignStructureHelper(file).getLabelFile(labelFilename);
        }
      } catch (CoreException e) {
        Plugin.getDefault().logError("Unable to lookup reference label file '" + labelFilename + "'.", e);
      }
      if (referenceFile != null) {
        if (Plugin.getDefault().isDebugging()) {
          System.out.println(referenceFile.getProjectRelativePath());
        }
        Plugin.getDefault().openLabelEditor(referenceFile, _reference);
      }
    }
  }



}
TOP

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

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.