|
|
Re: Creating hyperlinks in Xtext [message #1763539 is a reply to message #1763522] |
Wed, 17 May 2017 08:23 |
Nouredine Hamri Messages: 3 Registered: May 2017 |
Junior Member |
|
|
Hi,
thank you for the answer,
Here is my HyperlinkHelper class, but it does not work with,
public class AlsHyperlinkHelper extends HyperlinkHelper {
@Inject
private Provider<XtextHyperlink> hyperlinkProvider;
@Inject
private EObjectAtOffsetHelper eObjectAtOffsetHelper;
@Override
public void createHyperlinksByOffset(XtextResource resource, int offset, IHyperlinkAcceptor acceptor) {
super.createHyperlinksByOffset(resource, offset, acceptor);
EObject eObject = eObjectAtOffsetHelper.resolveElementAt(resource, offset);
if (eObject instanceof OpenName) {
List<INode> nodes = NodeModelUtils.findNodesForFeature(eObject,
AlsPackage.Literals.OPEN_NAME__IMPORT_URI);
if (!nodes.isEmpty()) {
INode node = nodes.get(0);
XtextHyperlink hyperlink = hyperlinkProvider.get();
hyperlink.setHyperlinkRegion(new Region(node.getOffset(), node.getLength()));
hyperlink.setHyperlinkText("Open included file");
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject myProject = root.getProject(eObject.eResource().getURI().segment(1));
String location;
if (myProject.getFile(
"/" + ((OpenName) eObject).getImportURI() + ".als").exists()) {
location = "platform:/resource/"
+ eObject.eResource().getURI().segment(1) + "/"
+ ((OpenName) eObject).getImportURI() + ".als";
} else {
location = "platform:/resource/" + "A4 models library"
+ "/" + ((OpenName) eObject).getImportURI()
+ ".als";
}
URI importUri = URI.createURI(location);
hyperlink.setURI(importUri);
acceptor.accept(hyperlink);
}
}
}
}
thank you,
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03193 seconds