From 1eea28e55c2207aa1f41c50b24cb3d167f734a83 Mon Sep 17 00:00:00 2001 From: Eyck Jentzsch Date: Sun, 3 Jun 2018 10:45:09 +0200 Subject: [PATCH] Added hyperlinking and bumped version numbers --- .../com.minres.rdl.feature/feature.xml | 48 +++++++------ .../feature.xml | 2 +- .../feature.xml | 3 +- .../com.minres.rdl.product.product | 2 +- .../META-INF/MANIFEST.MF | 3 +- .../com.minres.rdl.product/build.properties | 1 - .../com.minres.rdl.ui/META-INF/MANIFEST.MF | 4 +- .../com.minres.rdl.ui/pom.xml | 2 +- .../ui/JDTFreeStructuralProjectCreator.java | 17 +++++ .../src/com/minres/rdl/ui/RDLUiModule.xtend | 23 ++++++ .../ui/hyperlink/MyHyperlinkHelper.xtend | 52 ++++++++++++++ .../ui/hyperlink/MyXtextHyperlink.xtend | 24 +++++++ .../com/minres/rdl/ui/RDLUiModule.java | 26 +++++++ .../ui/hyperlink/MyHyperlinkHelper.java | 72 +++++++++++++++++++ .../ui/hyperlink/MyXtextHyperlink.java | 26 +++++++ .../com.minres.rdl/META-INF/MANIFEST.MF | 2 +- .../src/com/minres/rdl/generator/Main.xtend | 2 +- 17 files changed, 278 insertions(+), 31 deletions(-) create mode 100644 com.minres.rdl.parent/com.minres.rdl.ui/src/com/minres/rdl/ui/JDTFreeStructuralProjectCreator.java create mode 100644 com.minres.rdl.parent/com.minres.rdl.ui/src/com/minres/structural/ui/hyperlink/MyHyperlinkHelper.xtend create mode 100644 com.minres.rdl.parent/com.minres.rdl.ui/src/com/minres/structural/ui/hyperlink/MyXtextHyperlink.xtend create mode 100644 com.minres.rdl.parent/com.minres.rdl.ui/xtend-gen/com/minres/structural/ui/hyperlink/MyHyperlinkHelper.java create mode 100644 com.minres.rdl.parent/com.minres.rdl.ui/xtend-gen/com/minres/structural/ui/hyperlink/MyXtextHyperlink.java diff --git a/com.minres.rdl.parent/com.minres.rdl.feature/feature.xml b/com.minres.rdl.parent/com.minres.rdl.feature/feature.xml index cb5ccc5..ca5056f 100644 --- a/com.minres.rdl.parent/com.minres.rdl.feature/feature.xml +++ b/com.minres.rdl.parent/com.minres.rdl.feature/feature.xml @@ -1,23 +1,29 @@ - - - - + + + + + + + + diff --git a/com.minres.rdl.parent/com.minres.rdl.platform.feature/feature.xml b/com.minres.rdl.parent/com.minres.rdl.platform.feature/feature.xml index 7bd0cbf..f93d24a 100644 --- a/com.minres.rdl.parent/com.minres.rdl.platform.feature/feature.xml +++ b/com.minres.rdl.parent/com.minres.rdl.platform.feature/feature.xml @@ -3,7 +3,7 @@ id="com.minres.rdl.platform.feature" label="Xtext Platform Feature" version="1.0.0.qualifier" - provider-name="MINRES"> + provider-name="MINRES Technologies GmbH"> [Enter Feature Description here.] diff --git a/com.minres.rdl.parent/com.minres.rdl.product.feature/feature.xml b/com.minres.rdl.parent/com.minres.rdl.product.feature/feature.xml index 92aa4cd..ff890d4 100644 --- a/com.minres.rdl.parent/com.minres.rdl.product.feature/feature.xml +++ b/com.minres.rdl.parent/com.minres.rdl.product.feature/feature.xml @@ -2,7 +2,8 @@ + version="1.0.0.qualifier" + provider-name="MINRES Technologies GmbH"> diff --git a/com.minres.rdl.parent/com.minres.rdl.product.releng/com.minres.rdl.product.product b/com.minres.rdl.parent/com.minres.rdl.product.releng/com.minres.rdl.product.product index 251f2d7..89e242e 100644 --- a/com.minres.rdl.parent/com.minres.rdl.product.releng/com.minres.rdl.product.product +++ b/com.minres.rdl.parent/com.minres.rdl.product.releng/com.minres.rdl.product.product @@ -1,7 +1,7 @@ - + diff --git a/com.minres.rdl.parent/com.minres.rdl.product/META-INF/MANIFEST.MF b/com.minres.rdl.parent/com.minres.rdl.product/META-INF/MANIFEST.MF index 1d1c713..a717280 100644 --- a/com.minres.rdl.parent/com.minres.rdl.product/META-INF/MANIFEST.MF +++ b/com.minres.rdl.parent/com.minres.rdl.product/META-INF/MANIFEST.MF @@ -3,6 +3,7 @@ Bundle-ManifestVersion: 2 Bundle-Name: RDL Editor Bundle-SymbolicName: com.minres.rdl.product;singleton:=true Bundle-Version: 1.1.1.qualifier -Bundle-Vendor: MINRES +Bundle-Vendor: MINRES Technologies GmbH Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Require-Bundle: org.eclipse.core.runtime;bundle-version="3.12.0" +Automatic-Module-Name: com.minres.rdl.product diff --git a/com.minres.rdl.parent/com.minres.rdl.product/build.properties b/com.minres.rdl.parent/com.minres.rdl.product/build.properties index e9863e2..cc91072 100644 --- a/com.minres.rdl.parent/com.minres.rdl.product/build.properties +++ b/com.minres.rdl.parent/com.minres.rdl.product/build.properties @@ -1,5 +1,4 @@ source.. = src/ -output.. = bin/ bin.includes = META-INF/,\ .,\ plugin.xml diff --git a/com.minres.rdl.parent/com.minres.rdl.ui/META-INF/MANIFEST.MF b/com.minres.rdl.parent/com.minres.rdl.ui/META-INF/MANIFEST.MF index 79a275c..5ffeb3d 100644 --- a/com.minres.rdl.parent/com.minres.rdl.ui/META-INF/MANIFEST.MF +++ b/com.minres.rdl.parent/com.minres.rdl.ui/META-INF/MANIFEST.MF @@ -2,8 +2,8 @@ Manifest-Version: 1.0 Automatic-Module-Name: com.minres.rdl.ui Bundle-ManifestVersion: 2 Bundle-Name: com.minres.rdl.ui -Bundle-Vendor: My Company -Bundle-Version: 1.1.1.qualifier +Bundle-Vendor: MINRES Technologies GmbH +Bundle-Version: 1.2.0.qualifier Bundle-SymbolicName: com.minres.rdl.ui; singleton:=true Bundle-ActivationPolicy: lazy Require-Bundle: com.minres.rdl, diff --git a/com.minres.rdl.parent/com.minres.rdl.ui/pom.xml b/com.minres.rdl.parent/com.minres.rdl.ui/pom.xml index ee61d4b..68c4985 100644 --- a/com.minres.rdl.parent/com.minres.rdl.ui/pom.xml +++ b/com.minres.rdl.parent/com.minres.rdl.ui/pom.xml @@ -18,5 +18,5 @@ - 1.1.1-SNAPSHOT + 1.2.0-SNAPSHOT diff --git a/com.minres.rdl.parent/com.minres.rdl.ui/src/com/minres/rdl/ui/JDTFreeStructuralProjectCreator.java b/com.minres.rdl.parent/com.minres.rdl.ui/src/com/minres/rdl/ui/JDTFreeStructuralProjectCreator.java new file mode 100644 index 0000000..b5985d5 --- /dev/null +++ b/com.minres.rdl.parent/com.minres.rdl.ui/src/com/minres/rdl/ui/JDTFreeStructuralProjectCreator.java @@ -0,0 +1,17 @@ +package com.minres.rdl.ui; + +import org.eclipse.xtext.ui.XtextProjectHelper; + +import com.minres.rdl.ui.wizard.RDLProjectCreator; + + +public class JDTFreeStructuralProjectCreator extends RDLProjectCreator { + @Override + protected String[] getProjectNatures() { + return new String[] {XtextProjectHelper.NATURE_ID}; + } + @Override + protected String[] getBuilders() { + return new String[] {XtextProjectHelper.BUILDER_ID}; + } +} diff --git a/com.minres.rdl.parent/com.minres.rdl.ui/src/com/minres/rdl/ui/RDLUiModule.xtend b/com.minres.rdl.parent/com.minres.rdl.ui/src/com/minres/rdl/ui/RDLUiModule.xtend index 967e9ac..7f93637 100644 --- a/com.minres.rdl.parent/com.minres.rdl.ui/src/com/minres/rdl/ui/RDLUiModule.xtend +++ b/com.minres.rdl.parent/com.minres.rdl.ui/src/com/minres/rdl/ui/RDLUiModule.xtend @@ -6,6 +6,13 @@ package com.minres.rdl.ui import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor import org.eclipse.xtext.ui.editor.hover.IEObjectHoverProvider import org.eclipse.xtext.documentation.IEObjectDocumentationProvider +import org.eclipse.xtext.ui.wizard.IProjectCreator +import org.eclipse.xtext.ui.resource.IResourceSetProvider +import org.eclipse.xtext.ui.resource.SimpleResourceSetProvider +import org.eclipse.xtext.ui.editor.hyperlinking.HyperlinkHelper +import com.minres.structural.ui.hyperlink.MyHyperlinkHelper +import org.eclipse.xtext.ui.editor.hyperlinking.XtextHyperlink +import com.minres.structural.ui.hyperlink.MyXtextHyperlink /** * Use this class to register components to be used within the Eclipse IDE. @@ -21,4 +28,20 @@ class RDLUiModule extends AbstractRDLUiModule { typeof(RDLEObjectDocumentationProvider); } + override Class bindIProjectCreator() { + return JDTFreeStructuralProjectCreator; + } + + override Class bindIResourceSetProvider() { + return SimpleResourceSetProvider + } + + def Class bindHyperlinkHelper() { + return MyHyperlinkHelper + } + + def Class bindHyperlink() { + return MyXtextHyperlink + } + } diff --git a/com.minres.rdl.parent/com.minres.rdl.ui/src/com/minres/structural/ui/hyperlink/MyHyperlinkHelper.xtend b/com.minres.rdl.parent/com.minres.rdl.ui/src/com/minres/structural/ui/hyperlink/MyHyperlinkHelper.xtend new file mode 100644 index 0000000..ab20f90 --- /dev/null +++ b/com.minres.rdl.parent/com.minres.rdl.ui/src/com/minres/structural/ui/hyperlink/MyHyperlinkHelper.xtend @@ -0,0 +1,52 @@ +package com.minres.structural.ui.hyperlink + +import com.google.inject.Inject +import org.eclipse.emf.common.util.URI +import org.eclipse.emf.ecore.util.EcoreUtil +import org.eclipse.jface.text.Region +import org.eclipse.xtext.EcoreUtil2 +import org.eclipse.xtext.nodemodel.util.NodeModelUtils +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.util.TextRegion + +class MyHyperlinkHelper extends HyperlinkHelper { + + @Inject ImportUriResolver resolver; + + override createHyperlinksByOffset(XtextResource resource, int offset, IHyperlinkAcceptor acceptor) { + val region = new TextRegion(offset, 0) + val crossRefNode = getEObjectAtOffsetHelper().getCrossReferenceNode(resource, region); + if (crossRefNode === null){ + val parseResult = resource.getParseResult(); + if (parseResult !== null) { + val leaf = NodeModelUtils.findLeafNodeAtOffset(parseResult.getRootNode(), region.getOffset()); + //val rule = EcoreUtil2.getContainerOfType(leaf.grammarElement, AbstractRule); + val semObj = NodeModelUtils.findActualSemanticObjectFor(leaf); + val importURI = resolver.resolve(semObj); + if (importURI !== null && EcoreUtil2.isValidUri(semObj, URI.createURI(importURI))) { + val referencedResource = EcoreUtil2.getResource(resource, importURI) + if(referencedResource !== null && referencedResource.contents.size>0){ + val top = referencedResource.contents.get(0) + val textRegion = leaf.getTextRegion(); + val uri = EcoreUtil.getURI(top); + val result = hyperlinkProvider.get(); + result.setHyperlinkRegion(new Region(textRegion.getOffset(), textRegion.getLength())); + result.setURI(if(uri.isPlatformResource()) uri else resource.getResourceSet().getURIConverter().normalize(uri)); + result.setHyperlinkText(labelProvider.getText(top)); + if(result instanceof MyXtextHyperlink) result.selectTarget=false + acceptor.accept(result); + } + } + } + } else { + val crossLinkedEObject = getEObjectAtOffsetHelper().getCrossReferencedElement(crossRefNode); + if (crossLinkedEObject !== null && !crossLinkedEObject.eIsProxy()) { + createHyperlinksTo(resource, crossRefNode, crossLinkedEObject, acceptor); + } + } + } + +} \ No newline at end of file diff --git a/com.minres.rdl.parent/com.minres.rdl.ui/src/com/minres/structural/ui/hyperlink/MyXtextHyperlink.xtend b/com.minres.rdl.parent/com.minres.rdl.ui/src/com/minres/structural/ui/hyperlink/MyXtextHyperlink.xtend new file mode 100644 index 0000000..9c83a70 --- /dev/null +++ b/com.minres.rdl.parent/com.minres.rdl.ui/src/com/minres/structural/ui/hyperlink/MyXtextHyperlink.xtend @@ -0,0 +1,24 @@ +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 + +class MyXtextHyperlink extends XtextHyperlink { + + var boolean select = true + + @Inject var IURIEditorOpener uriEditorOpener; + + override void open() { + uriEditorOpener.open(getURI(), select); + } + + def boolean getSelectTarget(){ + return select + } + + def void setSelectTarget(boolean select){ + this.select=select + } +} \ No newline at end of file diff --git a/com.minres.rdl.parent/com.minres.rdl.ui/xtend-gen/com/minres/rdl/ui/RDLUiModule.java b/com.minres.rdl.parent/com.minres.rdl.ui/xtend-gen/com/minres/rdl/ui/RDLUiModule.java index 048b771..3ca590d 100644 --- a/com.minres.rdl.parent/com.minres.rdl.ui/xtend-gen/com/minres/rdl/ui/RDLUiModule.java +++ b/com.minres.rdl.parent/com.minres.rdl.ui/xtend-gen/com/minres/rdl/ui/RDLUiModule.java @@ -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 bindIProjectCreator() { + return JDTFreeStructuralProjectCreator.class; + } + + @Override + public Class bindIResourceSetProvider() { + return SimpleResourceSetProvider.class; + } + + public Class bindHyperlinkHelper() { + return MyHyperlinkHelper.class; + } + + public Class bindHyperlink() { + return MyXtextHyperlink.class; + } + public RDLUiModule(final AbstractUIPlugin arg0) { super(arg0); } diff --git a/com.minres.rdl.parent/com.minres.rdl.ui/xtend-gen/com/minres/structural/ui/hyperlink/MyHyperlinkHelper.java b/com.minres.rdl.parent/com.minres.rdl.ui/xtend-gen/com/minres/structural/ui/hyperlink/MyHyperlinkHelper.java new file mode 100644 index 0000000..545637e --- /dev/null +++ b/com.minres.rdl.parent/com.minres.rdl.ui/xtend-gen/com/minres/structural/ui/hyperlink/MyHyperlinkHelper.java @@ -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); + } + } + } +} diff --git a/com.minres.rdl.parent/com.minres.rdl.ui/xtend-gen/com/minres/structural/ui/hyperlink/MyXtextHyperlink.java b/com.minres.rdl.parent/com.minres.rdl.ui/xtend-gen/com/minres/structural/ui/hyperlink/MyXtextHyperlink.java new file mode 100644 index 0000000..f4d13dd --- /dev/null +++ b/com.minres.rdl.parent/com.minres.rdl.ui/xtend-gen/com/minres/structural/ui/hyperlink/MyXtextHyperlink.java @@ -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; + } +} diff --git a/com.minres.rdl.parent/com.minres.rdl/META-INF/MANIFEST.MF b/com.minres.rdl.parent/com.minres.rdl/META-INF/MANIFEST.MF index 12f0bec..2d88a9b 100644 --- a/com.minres.rdl.parent/com.minres.rdl/META-INF/MANIFEST.MF +++ b/com.minres.rdl.parent/com.minres.rdl/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Automatic-Module-Name: com.minres.rdl Bundle-ManifestVersion: 2 Bundle-Name: com.minres.rdl -Bundle-Vendor: My Company +Bundle-Vendor: MINRES Technologies GmbH Bundle-Version: 1.1.0.qualifier Bundle-SymbolicName: com.minres.rdl; singleton:=true Bundle-ActivationPolicy: lazy diff --git a/com.minres.rdl.parent/com.minres.rdl/src/com/minres/rdl/generator/Main.xtend b/com.minres.rdl.parent/com.minres.rdl/src/com/minres/rdl/generator/Main.xtend index 45c3521..cef6f52 100644 --- a/com.minres.rdl.parent/com.minres.rdl/src/com/minres/rdl/generator/Main.xtend +++ b/com.minres.rdl.parent/com.minres.rdl/src/com/minres/rdl/generator/Main.xtend @@ -23,7 +23,7 @@ import org.eclipse.xtext.generator.IFileSystemAccess class Main { - private val USAGE_STR = "RDL2code [-h] [-v] [-I ] "; + val USAGE_STR = "RDL2code [-h] [-v] [-I ] "; def static main(String[] args) { if (args.empty) {