Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Dynamic Template Variable Resolvers
Dynamic Template Variable Resolvers [message #1061101] Wed, 29 May 2013 18:08 Go to next message
Brad Riching is currently offline Brad Riching
Messages: 18
Registered: May 2012
Junior Member
Hello,

I've researched this as far as I know how and am stuck wondering if it is even possible. What I would like to do is propose a template that has two cross-referenced variables taking on the familiar form:


${var1:CrossReference('MyType1.ref1')} ${var2:CrossReference('MyType2.ref2')}



Where ref1 points to the container which declares objects that ref2 may point to.

My problem is that I cannot figure out if it is possible to create a variable resolver that resolves template variables on the fly, i.e. while the template is being edited. I want the available candidates to ref2 to be able to refresh after a candidate for ref1 has been chosen from the drop-down. Right now, ref2 contains all possible candidates for ref2, for all possible candidates for ref1 (in other words, everything). I want ref2 to only contain possible candidates for the currently selected candidate for ref1.

Does anyone know if template variable resolvers are capable of this dynamic behavior?

Re: Dynamic Template Variable Resolvers [message #1061113 is a reply to message #1061101] Thu, 30 May 2013 02:18 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander Nittka
Messages: 1151
Registered: July 2009
Senior Member
Hi,

See e.g. this blog entry. It is for Xtext1, but the general infrastructure should not have changed (much).

Note that regular code completion works within variables for arbitrary names, so if your scoping is according to the "container-declaration" semantics you want to capture, the minimal effort variant would be using no template variable resolution in the second case at all. The user has to invoke code completion to see the possibilities, though.

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: Dynamic Template Variable Resolvers [message #1061216 is a reply to message #1061113] Thu, 30 May 2013 10:48 Go to previous message
Brad Riching is currently offline Brad Riching
Messages: 18
Registered: May 2012
Junior Member
Thanks Alexander,

That's actually the blog post that I discovered prior to asking this question. I created my own template variable resolver, but

resolveValues(TemplateVariable variable, XtextTemplateContext xtextTemplateContext)


is only called once, when the template is created. I couldn't get it to resolve my variable again while I was editing the template. Also, I would have posted the link to that blog, but the last time I tried to post an outside link, the forum wouldn't let me due to my account privileges.

I like your solution for the time being, except it initially leaves my model file in an invalid state because it inserts a "dummy" variable that still needs to be resolved by code completion. I will continue to investigate and I'll post a cleaner solution if I am able to come up with one.

Thanks for the suggestion!

Brad
Previous Topic:Create "generator code"
Next Topic:Create Automatically elements when one element is created
Goto Forum:
  


Current Time: Tue Jul 22 17:51:02 EDT 2014

Powered by FUDForum. Page generated in 0.02271 seconds