Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Custom TemplateNewFileWizard(Having a customized TemplateFileInfo like the IExtendedProjectInfo)
Custom TemplateNewFileWizard [message #1803869] Tue, 12 March 2019 17:11 Go to next message
Marie-Saphira Flug is currently offline Marie-Saphira FlugFriend
Messages: 21
Registered: January 2019
Junior Member
Hello,

I am creating a custom TemplateNewFileWizard, so I created a class MyNewFileWizard that extends TemplateNewFileWizard.
I already made a customized TemplateNewProjectWizard the same way. There I created a custom ProjectInformation that implements IExtendedProjectInfo so I could pass all the acquired information (wizard input) to the template creation in MyDSLProjectTemplateProvider.xtend .
In the FileWizard the information about the file to be created is stored in org.eclipse.xtext.ui.wizard.template.TemplateFileInfo. I created my own MyTemplateFileInfo class to store the user input and noticed that setTemplateInfo(TemplateFileInfo info) in org.eclipse.xtext.ui.wizard.template.AbstractFileTemplate is package protected. So I can't set the TemplateInfo, which is usually done in TemplateNewFileWizard.getNextPage(page). Here the method getFileInfo() (returns TemplateFileInfo) is called, instead of my getFileInfo() (returns MyTemplateFileInfo) in the subclass. So the template ends up without info.

The problem is that everything is connected and that I can't use the @FileTemplate annotation with anything other than AbstractFileTemplate. Do I really need to create my own annotation (if yes, how?) to access the user input or is there another way?

I hope I asked my question so you can understand the problem. Thanks a lot in advance.

[Updated on: Thu, 14 March 2019 10:20]

Report message to a moderator

Re: Custom TemplateNewFileWizard [message #1803960 is a reply to message #1803869] Thu, 14 March 2019 11:09 Go to previous messageGo to next message
Arne Deutsch is currently offline Arne DeutschFriend
Messages: 12
Registered: July 2009
Junior Member
I understand that making setFileInfo package projected was a mistake. Would you agree that you would have no issue if that would be protected? If so I would make it so with the next release.

For the meantime I see two ways for you to workaround the issue.
1. Use reflection to call setFileInfo method.
2. Create your own subclass of AbstractFileTemplate. Appart from the automatic internationalization everything should work. The annotation does only three things for you: automatically extending the AbstractFileTemplate (you can do that yourself), providing description and icon path (you should be able to override the correct methods and return strings from code), updateing the internationalization files (you would then have to do it manually).

Does this work for you?
Re: Custom TemplateNewFileWizard [message #1803974 is a reply to message #1803960] Thu, 14 March 2019 15:59 Go to previous messageGo to next message
Marie-Saphira Flug is currently offline Marie-Saphira FlugFriend
Messages: 21
Registered: January 2019
Junior Member
Thanks for your reply. Yes I think my problem would be solved if setFileInfo was not package protected.
Your second workaround works for me, thanks.

Since you're allready here, I have a second question about the TemplateNewFileWizard: Access to the grammar happens via the Guice Injection Factory
(class="MyDSLExecutableExtensionFactory:org.eclipse.xtext.ui.wizard.template.TemplateNewFileWizard" in plugin.xml)
I want my Wizard to be opened through a command extension point
(defaultHandler="MyDSLExecutableExtensionFactory:SomeHandler")
Do you have a tip how I could pass grammarAccess, labelProvider and fileOpener to the TemplateNewFileWizard?

Thanks a lot!
Re: Custom TemplateNewFileWizard [message #1803986 is a reply to message #1803974] Thu, 14 March 2019 20:20 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
you should be able to @Inject MyService all services into a handler or wizard class if it is created via class="MyDSLExecutableExtensionFactory:MyService"
you can inject a Provider<YourClass> myProvider and call myProvider.get() to get instances with injected services too.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Cross reference to duplicate items in the model
Next Topic:Content Assist for Hidden Terminal Rules
Goto Forum:
  


Current Time: Thu Apr 18 06:06:29 GMT 2024

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

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

Back to the top