Skip to main content



      Home
Home » Modeling » TMF (Xtext) » dynamic template proposals in Xtext(dynamic template proposals in Xtext)
dynamic template proposals in Xtext [message #805930] Fri, 24 February 2012 05:07 Go to next message
Eclipse UserFriend
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 #806006 is a reply to message #805930] Fri, 24 February 2012 07:16 Go to previous messageGo to next message
Eclipse UserFriend
I am using.
EObject cm = context.getCurrentModel();


Andreas
Re: dynamic template proposals in Xtext [message #870920 is a reply to message #805930] Thu, 10 May 2012 05:11 Go to previous messageGo to next message
Eclipse UserFriend
hi Michal

If you have solved you can show me how?? I also have the same problem!
Thank you!
Re: dynamic template proposals in Xtext [message #870958 is a reply to message #870920] Thu, 10 May 2012 06:59 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: dynamic template proposals in Xtext [message #870989 is a reply to message #870958] Thu, 10 May 2012 09:31 Go to previous message
Eclipse UserFriend
Many thanks to Michal

[Updated on: Thu, 10 May 2012 09:31] by Moderator

Previous Topic:Xtext 2.3 M6 Grammar Editor can't resolve JavaVMTypes import correctly
Next Topic:[Solved] Custom content Assist
Goto Forum:
  


Current Time: Wed Jul 16 17:49:43 EDT 2025

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

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

Back to the top