About FileTemplate Registration

Hi

I like to make my file templates appear under j2ee tab of FileTemplate dialogue. I've added a fileTemplateGroup by implementing FileTemplateGroupDescriptorFactory interface and it works fine; meaning my templates appears as it should be. BUT when I select them on FileTemplate dialogue, no contents are available for them. I searched through this forum and some other plugin source code. It seems that there should be some convention for contents of file templates in order to be presented under that dialogue. Those plugin's packaging structure contains a root package named fileTemplates having a j2ee package as a child. I tried it and placed my file templates under such directory, but it doesn't work.

I know from some other threads (http://intellij.net/forums/thread.jspa?messageID=5215371) that there is another method to register file templates on IntelliJ. It's possible using FileTemplateManager 's addTemplate method, calling it from an application component. In this manner, you should fill content of your newly created FileTemplate, using manually loaded template file (.ft file). I don't like to use such method (I prefer using more declarative approach like fileTemplateGroup ). But if there is no other method to do this, it would be ok. Of course there will be another question :)

The sample file template registration code (available at thread mentioned above) uses a utility class named JSSupportLoader to load templates file. I didn't find this class on my sdk classpath. I think it should be on some other plugins. However, I like to know what is the openapi utility class for opening such files as streams, readers, and so.

4 comments
Comment actions Permalink

A possible source for trouble on your first approach (which I prefer
too) is that .ft files are not treated as resources automatically and
therefore won't be copied into your output directory. If that's the case
then go to Settings -> Compiler -> Resource patterns and add ;?*.ft at
the end.

Ehsan Zaery Moghaddam wrote:

Hi

I like to make my file templates appear under j2ee tab of FileTemplate dialogue. I've added a fileTemplateGroup by implementing FileTemplateGroupDescriptorFactory interface and it works fine; meaning my templates appears as it should be. BUT when I select them on FileTemplate dialogue, no contents are available for them. I searched through this forum and some other plugin source code. It seems that there should be some convention for contents of file templates in order to be presented under that dialogue. Those plugin's packaging structure contains a root package named fileTemplates having a j2ee package as a child. I tried it and placed my file templates under such directory, but it doesn't work.

I know from some other threads (http://intellij.net/forums/thread.jspa?messageID=5215371) that there is another method to register file templates on IntelliJ. It's possible using FileTemplateManager 's addTemplate method, calling it from an application component. In this manner, you should fill content of your newly created FileTemplate, using manually loaded template file (.ft file). I don't like to use such method (I prefer using more declarative approach like fileTemplateGroup ). But if there is no other method to do this, it would be ok. Of course there will be another question :)

The sample file template registration code (available at thread mentioned above) uses a utility class named JSSupportLoader to load templates file. I didn't find this class on my sdk classpath. I think it should be on some other plugins. However, I like to know what is the openapi utility class for opening such files as streams, readers, and so.


--
Martin Fuhrer
Fuhrer Engineering AG
http://www.fuhrer.com

0
Comment actions Permalink

Thanks Martin

I've checked my plugin sandbox, and there exists my ft files. However I've done what you said, but unfortunately nothing new happened :(

0
Comment actions Permalink

Could it be that you misspelled something? If you created your
descriptor with 'new FileTemplateDescriptor("abc.xml", icon)', then you
have to provide a template file named "abc.xml.ft", not "abc.ft". And it
must be placed in your sandbox as
".../sandbox/plugins/]]>/classes/fileTemplates/j2ee/abc.xml.ft".

Ehsan Zaery Moghaddam wrote:

Thanks Martin

I've checked my plugin sandbox, and there exists my ft files. However I've done what you said, but unfortunately nothing new happened :(


--
Martin Fuhrer
Fuhrer Engineering AG
http://www.fuhrer.com

0
Comment actions Permalink

I used the second method and it works fine. It causes to have a new item on the context menu that appears when you right click on a module or source directory. Here is my code:

FileTemplate template = FileTemplateManager.getInstance().getJ2eeTemplate("abc.xyz");
if (template == null) {
template = FileTemplateManager.getInstance().addJ2eeTemplate("abc", "xyz");
template.setText(
FileUtil.loadTextAndClose(
new InputStreamReader(getClass().getResourceAsStream("/fileTemplates/j2ee/abc.xyz.ft")))
);
}

I have this code snippet on my application component. Also I used the other declarative method simultaniously. However I've chaned my code from

FileTemplateGroupDescriptor abcFileTemplateGroupDescriptor = new FileTemplateGroupDescriptor("ABC Templates", ABCIcons.ABC_FILE_TEMPLATE_GROUP_ICON);
abcFileTemplateGroupDescriptor.addTemplate(new FileTemplateGroupDescriptor("abc.xyz", ABCIcons.XYZ_FILE_ICON));

to

FileTemplateGroupDescriptor abcFileTemplateGroupDescriptor = new FileTemplateGroupDescriptor("ABC Templates", ABCIcons.ABC_FILE_TEMPLATE_GROUP_ICON);
abcFileTemplateGroupDescriptor.addTemplate("abc.xyz");


So my new file template first has registered by application component and then appears under "ABC Template" on j2ee tab of File Templates dialogue.
This way, I can not have a customized icon for my file type (as I used the single parameter addTemplate method), or at least I don't know how could I do that (thanks to nice documentations and tutorials from JetBrains guys)

0

Please sign in to leave a comment.