Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » accessing user defined templates at runtime
accessing user defined templates at runtime [message #1011492] Tue, 19 February 2013 16:22 Go to next message
n d is currently offline n dFriend
Messages: 11
Registered: February 2013
Junior Member
Hi all,

I would like to know if there is anyway to access the templates defined in the templates.xml from the MyDslProposalProvider class.

The reason is I would like to (de)activate them at runtime according to the rule/Eobject the parser is in.

Thanks to all.
Nuno
Re: accessing user defined templates at runtime [message #1011745 is a reply to message #1011492] Wed, 20 February 2013 07:26 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

you would not do that in the <Language>ProposalProvider. Bind your own implementation of ITemplateProposalProvider (probably extending DefaultTemplateProposalProvider).
The validate-Methods seem to be good points for including or excluding templates...

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: accessing user defined templates at runtime [message #1012278 is a reply to message #1011745] Thu, 21 February 2013 09:02 Go to previous messageGo to next message
n d is currently offline n dFriend
Messages: 11
Registered: February 2013
Junior Member
Hi Alexander,

Thank you very much for your reply.
I have followed your suggestion and defined my own template provider.
If I understood you correctly, you suggested that the call for the (de)activation call to be done in the validation methods (ex. org.xtext.example.mydsl.validation). If so, can you give me tell me if there is a clean way to access the template provider from there.

Thanks a lot,
Nuno
Re: accessing user defined templates at runtime [message #1012285 is a reply to message #1012278] Thu, 21 February 2013 09:16 Go to previous messageGo to next message
n d is currently offline n dFriend
Messages: 11
Registered: February 2013
Junior Member
Hi again,

Nevermind, just solved it in another way Smile

Thanks again,
Nuno
Re: accessing user defined templates at runtime [message #1012288 is a reply to message #1012278] Thu, 21 February 2013 09:19 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

have you bound your implementation in the UIModule? If you override the validate methods, you should have everything you need available.
The context allows you to determine at which position content assist is invoked (what is to be completed), the template is the candidate template that is to be proposed.

So you check whether you want to show the template at that point and return true or false accordingly... (Breakpoints and debug mode are always helpful.)

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: accessing user defined templates at runtime [message #1012822 is a reply to message #1011492] Fri, 22 February 2013 09:31 Go to previous messageGo to next message
n d is currently offline n dFriend
Messages: 11
Registered: February 2013
Junior Member
Hi,

My grammar is basically a generic JSon parser which uses a JSon schema in the background for validation. So, in my createTemplates method, I check the current node's parent and (de)activate the templates based on his key before the actual template proposal creation (i.e. the super method)

Thanks again for the help.
Nuno

Ps. Perhaps you have some idea concerning another problem that I've encountered
http://www.eclipse.org/forums/index.php/t/455949/
Re: accessing user defined templates at runtime [message #1012834 is a reply to message #1012822] Fri, 22 February 2013 09:59 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

i think you still missed that alex was talking about
org.eclipse.xtext.ui.editor.templates.AbstractTemplateProposalProvider.validate(Template, ContentAssistContext)
and not the normal java validator

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: accessing user defined templates at runtime [message #1012945 is a reply to message #1011492] Fri, 22 February 2013 13:59 Go to previous message
n d is currently offline n dFriend
Messages: 11
Registered: February 2013
Junior Member
Hi,

Right. Thanks for the heads up Wink

Nuno
Previous Topic:error when generating my language
Next Topic:Left recursion
Goto Forum:
  


Current Time: Thu Mar 28 16:32:32 GMT 2024

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

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

Back to the top