dynamic template proposals in Xtext [message #805930] |
Fri, 24 February 2012 05:07  |
Eclipse User |
|
|
|
Hello,
I followed the manual here: http://blogs.itemis.de/stundzig/archives/750 to create dynamic templates and it works as expected. My question is, how can I access the EObject of the context?
E.g.
lets have grammar:
Entity1: name=ID parameters=Parameters ;
Parmeters: '(' parameters+=VAL (',' parameters+=VAL)* ')' ;
Entity2: name=ID reference=[Entity1] parameters=Parameters ;
I want my template proposal shows when Parameters are expected, but only when the container of Parameters object is Entity2 (not Entity1) and I need to access referenced Entity1 to prepare the template.
I would need something like "templateContext.getEObject()" and then I would be able to scope as it is common in scopes provider.
I would expect this ability, when I need dynamic (context content dependent) template proposal, but I don't know, how/where to get it.
Thank you & Best regards,
Michal
|
|
|
|
|
Re: dynamic template proposals in Xtext [message #870958 is a reply to message #870920] |
Thu, 10 May 2012 06:59   |
Eclipse User |
|
|
|
Hi Gianluca,
let's have a look at following example
String id=helper.getId(ga.getSomeEntity());
if(templateContext.getContextType().getId().equals(id)){
// you can access here the model in the context using context.getCurrentModel()
SomeEntity someEntity = (SomeEntity) context.getCurrentModel();
Template template = new Template("SomeName", "${"+someEntity.getName()+"}", "someId1", someEntity.getName(), true);
//create a proposal
TemplateProposal tp = createProposal(template, templateContext, context, getImage(template), getRelevance(template));
//make it available
acceptor.accept(tp);
}
}
The behaviour can be well adjusted. I use dynamic templates for "best practices" content assist in my DSL...
Regards,
Michal
|
|
|
|
Powered by
FUDForum. Page generated in 0.04044 seconds