Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Hyperlinking
Hyperlinking [message #853768] Mon, 23 April 2012 10:05 Go to next message
Antonio Metallo is currently offline Antonio MetalloFriend
Messages: 24
Registered: March 2012
Junior Member
Hi all,
I'm trying to create an hyperlink from an EObject to another in the same file. I bind the DefaultHyperlinkDetector and then set MyHyperlinkHelper, I override the createHyperlinksByOffset method and in it I add the XtextHyperlink, but can it link to an EObject in the file?
Re: Hyperlinking [message #854140 is a reply to message #853768] Mon, 23 April 2012 17:51 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

i do not understand your problem? could you elaborate a bit.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Hyperlinking [message #854214 is a reply to message #854140] Mon, 23 April 2012 19:31 Go to previous messageGo to next message
Antonio Metallo is currently offline Antonio MetalloFriend
Messages: 24
Registered: March 2012
Junior Member
I'm trying to have CTRL click on a VariableName to a VariableDeclaration. I bind the DefaultHyperlinkDetector

public Class<? extends DefaultHyperlinkDetector> bindDefaultHyperlinkDetector() { return MyLinkerService.class; }


this is MyLinkerService:

public class MyLinkerService extends DefaultHyperlinkDetector {

	
	
	@Override
	public IHyperlink[] detectHyperlinks(ITextViewer textViewer,
			IRegion region, boolean canShowMultipleHyperlinks) {
		this.setHelper(new MyHyperlink());
		return super.detectHyperlinks(textViewer, region, canShowMultipleHyperlinks);
	}
	
}


in MyLinkerService i set the helper to MyHyperlinkHelper:

public class MyHyperlinkHelper extends HyperlinkHelper {
    
    @Override
    public void createHyperlinksByOffset(XtextResource resource, int offset,
    		IHyperlinkAcceptor acceptor) {
    	super.createHyperlinksByOffset(resource, offset, acceptor);
    	
    	TextLocation loc = new TextLocation();
    	EObject eObject = EObjectAtOffsetHelper.resolveElementAt(resource, offset, loc);
    	if (eObject instanceof VariableName) {
    		VariableName varName = (VariableName) eObject;
    		
    		
    		CompositeNode adapter = NodeUtil.getNode(varName);
    		XtextHyperlink hyperlink = new XtextHyperlink();
    		hyperlink.setHyperlinkText("Variable");
    		hyperlink.setHyperlinkRegion(new Region(adapter.getOffset(), adapter.getLength()));
    		acceptor.accept(hyperlink);
    	}
    }
    
}


XtextHyperlink have a setURI() method but I want a link to the VariableDeclaration in the same file, how can I have this?
Re: Hyperlinking [message #854225 is a reply to message #854214] Mon, 23 April 2012 19:45 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
hi,

still do not understand org.eclipse.xtext.ui.editor.hyperlinking.HyperlinkHelper.createHyperlinksTo(XtextResource, Region, EObject, IHyperlinkAcceptor) contains all you need

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Hyperlinking [message #854229 is a reply to message #854225] Mon, 23 April 2012 19:51 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Btw why dont you simply bind HyperlinkHelper with guice means? your way of extension is not very Xtextish

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Hyperlinking [message #854292 is a reply to message #854229] Mon, 23 April 2012 21:20 Go to previous messageGo to next message
Antonio Metallo is currently offline Antonio MetalloFriend
Messages: 24
Registered: March 2012
Junior Member
I tried to override the createHyperlinksTo but this is never used, i try to put a simple syso in it but nothing happens:
@Override
    public void createHyperlinksTo(XtextResource from, Region region, EObject to, IHyperlinkAcceptor acceptor) {
    	System.out.println(HI_TO");
    	super.createHyperlinksTo(from, region, to, acceptor);
    }


I also have tried to bind only the HyperlinkHelper but the method in it aren't used:

public Class<? extends HyperlinkHelper> bindHyperlinkHelper() { return MyHyperlinkHelper.class; }

Re: Hyperlinking [message #854299 is a reply to message #854292] Mon, 23 April 2012 21:33 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

the method is of cource only called if YOU call it or you have a real cross ref and thus is called by the framework (in its out of the box config)
besides you missed an important point

	@Override
	public Class<? extends IHyperlinkHelper> bindIHyperlinkHelper() {
		return MyDslHyperlinkHelper.class;
	}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Hyperlinking [message #854313 is a reply to message #854299] Mon, 23 April 2012 21:49 Go to previous messageGo to next message
Antonio Metallo is currently offline Antonio MetalloFriend
Messages: 24
Registered: March 2012
Junior Member
I don't have a real cross ref and if I use the IHyperLinkHelper in binding I get this error:

1) A binding to org.eclipse.xtext.ui.editor.hyperlinking.IHyperlinkHelper was already configured at org.eclipse.xtext.service.BindModule.configure(BindModule.java:36).
  at org.eclipse.xtext.service.BindModule.configure(BindModule.java:36)

1 error
com.google.inject.CreationException: Guice creation errors:

1) A binding to org.eclipse.xtext.ui.editor.hyperlinking.IHyperlinkHelper was already configured at org.eclipse.xtext.service.BindModule.configure(BindModule.java:36).
  at org.eclipse.xtext.service.BindModule.configure(BindModule.java:36)


Is there a way to create an Hyperlink without a real cross ref?

[Updated on: Mon, 23 April 2012 22:02]

Report message to a moderator

Re: Hyperlinking [message #854328 is a reply to message #854313] Mon, 23 April 2012 22:01 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Where do you but your binding I override!!! The existing in the UI
module thus I do not get such strange errors


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Strage Memory leak in Semantic Highlighting
Next Topic:Single File Generation - IFileSystemAccess/JavaIoFileSytemAccess
Goto Forum:
  


Current Time: Thu Apr 18 21:22:47 GMT 2024

Powered by FUDForum. Page generated in 0.03135 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top