Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 10:07 Go to next message
Michal S is currently offline Michal SFriend
Messages: 74
Registered: July 2011
Member
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 12:16 Go to previous messageGo to next message
Andreas Graf is currently offline Andreas GrafFriend
Messages: 211
Registered: July 2009
Senior Member
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 09:11 Go to previous messageGo to next message
Gianluca Viscomi is currently offline Gianluca ViscomiFriend
Messages: 33
Registered: April 2012
Location: Italy
Member
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 10:59 Go to previous messageGo to next message
Michal S is currently offline Michal SFriend
Messages: 74
Registered: July 2011
Member
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 13:31 Go to previous message
Gianluca Viscomi is currently offline Gianluca ViscomiFriend
Messages: 33
Registered: April 2012
Location: Italy
Member
Many thanks to Michal

[Updated on: Thu, 10 May 2012 13:31]

Report message to a 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: Fri Apr 19 14:27:49 GMT 2024

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

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

Back to the top