mirror of
				https://github.com/Minres/RDL-Editor.git
				synced 2025-11-03 20:21:46 +00:00 
			
		
		
		
	Added hyperlinking and bumped version numbers
This commit is contained in:
		@@ -4,12 +4,20 @@
 | 
			
		||||
package com.minres.rdl.ui;
 | 
			
		||||
 | 
			
		||||
import com.minres.rdl.ui.AbstractRDLUiModule;
 | 
			
		||||
import com.minres.rdl.ui.JDTFreeStructuralProjectCreator;
 | 
			
		||||
import com.minres.rdl.ui.RDLEObjectDocumentationProvider;
 | 
			
		||||
import com.minres.rdl.ui.RDLEObjectHoverProvider;
 | 
			
		||||
import com.minres.structural.ui.hyperlink.MyHyperlinkHelper;
 | 
			
		||||
import com.minres.structural.ui.hyperlink.MyXtextHyperlink;
 | 
			
		||||
import org.eclipse.ui.plugin.AbstractUIPlugin;
 | 
			
		||||
import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor;
 | 
			
		||||
import org.eclipse.xtext.documentation.IEObjectDocumentationProvider;
 | 
			
		||||
import org.eclipse.xtext.ui.editor.hover.IEObjectHoverProvider;
 | 
			
		||||
import org.eclipse.xtext.ui.editor.hyperlinking.HyperlinkHelper;
 | 
			
		||||
import org.eclipse.xtext.ui.editor.hyperlinking.XtextHyperlink;
 | 
			
		||||
import org.eclipse.xtext.ui.resource.IResourceSetProvider;
 | 
			
		||||
import org.eclipse.xtext.ui.resource.SimpleResourceSetProvider;
 | 
			
		||||
import org.eclipse.xtext.ui.wizard.IProjectCreator;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Use this class to register components to be used within the Eclipse IDE.
 | 
			
		||||
@@ -25,6 +33,24 @@ public class RDLUiModule extends AbstractRDLUiModule {
 | 
			
		||||
    return RDLEObjectDocumentationProvider.class;
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  @Override
 | 
			
		||||
  public Class<? extends IProjectCreator> bindIProjectCreator() {
 | 
			
		||||
    return JDTFreeStructuralProjectCreator.class;
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  @Override
 | 
			
		||||
  public Class<? extends IResourceSetProvider> bindIResourceSetProvider() {
 | 
			
		||||
    return SimpleResourceSetProvider.class;
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  public Class<? extends HyperlinkHelper> bindHyperlinkHelper() {
 | 
			
		||||
    return MyHyperlinkHelper.class;
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  public Class<? extends XtextHyperlink> bindHyperlink() {
 | 
			
		||||
    return MyXtextHyperlink.class;
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  public RDLUiModule(final AbstractUIPlugin arg0) {
 | 
			
		||||
    super(arg0);
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,72 @@
 | 
			
		||||
package com.minres.structural.ui.hyperlink;
 | 
			
		||||
 | 
			
		||||
import com.google.inject.Inject;
 | 
			
		||||
import com.minres.structural.ui.hyperlink.MyXtextHyperlink;
 | 
			
		||||
import org.eclipse.emf.common.util.URI;
 | 
			
		||||
import org.eclipse.emf.ecore.EObject;
 | 
			
		||||
import org.eclipse.emf.ecore.resource.Resource;
 | 
			
		||||
import org.eclipse.emf.ecore.util.EcoreUtil;
 | 
			
		||||
import org.eclipse.jface.text.Region;
 | 
			
		||||
import org.eclipse.xtext.EcoreUtil2;
 | 
			
		||||
import org.eclipse.xtext.nodemodel.ILeafNode;
 | 
			
		||||
import org.eclipse.xtext.nodemodel.INode;
 | 
			
		||||
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
 | 
			
		||||
import org.eclipse.xtext.parser.IParseResult;
 | 
			
		||||
import org.eclipse.xtext.resource.XtextResource;
 | 
			
		||||
import org.eclipse.xtext.scoping.impl.ImportUriResolver;
 | 
			
		||||
import org.eclipse.xtext.ui.editor.hyperlinking.HyperlinkHelper;
 | 
			
		||||
import org.eclipse.xtext.ui.editor.hyperlinking.IHyperlinkAcceptor;
 | 
			
		||||
import org.eclipse.xtext.ui.editor.hyperlinking.XtextHyperlink;
 | 
			
		||||
import org.eclipse.xtext.util.ITextRegion;
 | 
			
		||||
import org.eclipse.xtext.util.TextRegion;
 | 
			
		||||
 | 
			
		||||
@SuppressWarnings("all")
 | 
			
		||||
public class MyHyperlinkHelper extends HyperlinkHelper {
 | 
			
		||||
  @Inject
 | 
			
		||||
  private ImportUriResolver resolver;
 | 
			
		||||
  
 | 
			
		||||
  @Override
 | 
			
		||||
  public void createHyperlinksByOffset(final XtextResource resource, final int offset, final IHyperlinkAcceptor acceptor) {
 | 
			
		||||
    final TextRegion region = new TextRegion(offset, 0);
 | 
			
		||||
    final INode crossRefNode = this.getEObjectAtOffsetHelper().getCrossReferenceNode(resource, region);
 | 
			
		||||
    if ((crossRefNode == null)) {
 | 
			
		||||
      final IParseResult parseResult = resource.getParseResult();
 | 
			
		||||
      if ((parseResult != null)) {
 | 
			
		||||
        final ILeafNode leaf = NodeModelUtils.findLeafNodeAtOffset(parseResult.getRootNode(), region.getOffset());
 | 
			
		||||
        final EObject semObj = NodeModelUtils.findActualSemanticObjectFor(leaf);
 | 
			
		||||
        final String importURI = this.resolver.resolve(semObj);
 | 
			
		||||
        if (((importURI != null) && EcoreUtil2.isValidUri(semObj, URI.createURI(importURI)))) {
 | 
			
		||||
          final Resource referencedResource = EcoreUtil2.getResource(resource, importURI);
 | 
			
		||||
          if (((referencedResource != null) && (referencedResource.getContents().size() > 0))) {
 | 
			
		||||
            final EObject top = referencedResource.getContents().get(0);
 | 
			
		||||
            final ITextRegion textRegion = leaf.getTextRegion();
 | 
			
		||||
            final URI uri = EcoreUtil.getURI(top);
 | 
			
		||||
            final XtextHyperlink result = this.getHyperlinkProvider().get();
 | 
			
		||||
            int _offset = textRegion.getOffset();
 | 
			
		||||
            int _length = textRegion.getLength();
 | 
			
		||||
            Region _region = new Region(_offset, _length);
 | 
			
		||||
            result.setHyperlinkRegion(_region);
 | 
			
		||||
            URI _xifexpression = null;
 | 
			
		||||
            boolean _isPlatformResource = uri.isPlatformResource();
 | 
			
		||||
            if (_isPlatformResource) {
 | 
			
		||||
              _xifexpression = uri;
 | 
			
		||||
            } else {
 | 
			
		||||
              _xifexpression = resource.getResourceSet().getURIConverter().normalize(uri);
 | 
			
		||||
            }
 | 
			
		||||
            result.setURI(_xifexpression);
 | 
			
		||||
            result.setHyperlinkText(this.getLabelProvider().getText(top));
 | 
			
		||||
            if ((result instanceof MyXtextHyperlink)) {
 | 
			
		||||
              ((MyXtextHyperlink)result).setSelectTarget(false);
 | 
			
		||||
            }
 | 
			
		||||
            acceptor.accept(result);
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    } else {
 | 
			
		||||
      final EObject crossLinkedEObject = this.getEObjectAtOffsetHelper().getCrossReferencedElement(crossRefNode);
 | 
			
		||||
      if (((crossLinkedEObject != null) && (!crossLinkedEObject.eIsProxy()))) {
 | 
			
		||||
        this.createHyperlinksTo(resource, crossRefNode, crossLinkedEObject, acceptor);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,26 @@
 | 
			
		||||
package com.minres.structural.ui.hyperlink;
 | 
			
		||||
 | 
			
		||||
import com.google.inject.Inject;
 | 
			
		||||
import org.eclipse.xtext.ui.editor.IURIEditorOpener;
 | 
			
		||||
import org.eclipse.xtext.ui.editor.hyperlinking.XtextHyperlink;
 | 
			
		||||
 | 
			
		||||
@SuppressWarnings("all")
 | 
			
		||||
public class MyXtextHyperlink extends XtextHyperlink {
 | 
			
		||||
  private boolean select = true;
 | 
			
		||||
  
 | 
			
		||||
  @Inject
 | 
			
		||||
  private IURIEditorOpener uriEditorOpener;
 | 
			
		||||
  
 | 
			
		||||
  @Override
 | 
			
		||||
  public void open() {
 | 
			
		||||
    this.uriEditorOpener.open(this.getURI(), this.select);
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  public boolean getSelectTarget() {
 | 
			
		||||
    return this.select;
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  public void setSelectTarget(final boolean select) {
 | 
			
		||||
    this.select = select;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user