FileTemplates and fileTemplateManager

Hi there!
I'm trying to delevop a simple IntelliJ IDEA plugin that will create different classes to skip boilerplating.

Once my fileTemplates are correctly registered with the FileTemplateGroupDescriptorFactory and plugin.xml and when I'm trying to get the file template like this :

        final FileTemplateManager fileTemplateManager = FileTemplateManager.getInstance();
        FileTemplate fileTemplate = fileTemplateManager.getJ2eeTemplate(templateName);

the second line keeps returning me : template not found when I run the plugin action.


Note : when I go in File>Settings>FileTemplate>"MyTemplateGroup">templateName, the fileTemplate exists but the body is empty.

5 comments
Comment actions Permalink

Please make sure that *.ft is includes in Settings | Compiler | Resource file patterns.

0
Comment actions Permalink

Already done..!

I currently do this like the following code and it seems to work but I know that this isn't the clear way to do this. I still don't understand why the body of my J2ee templates are empty after registering.

        final FileTemplateManager fileTemplateManager = FileTemplateManager.getInstance();         FileTemplate fileTemplate = fileTemplateManager.getJ2eeTemplate(templateName);         if (fileTemplate == null){             fileTemplate = fileTemplateManager.addTemplate(templateName,"java");             String text = FileUtil.loadTextAndClose(new InputStreamReader(getClass().getClassLoader().getResourceAsStream("/fileTemplates/j2ee/" + templateName + ".ft")));             fileTemplate.setText(text);         }         Properties properties = fileTemplateManager.getDefaultProperties();         return FileTemplateUtil.createFromTemplate(fileTemplate, newFileName, properties, directory)



It seems to work but the getJ2eeTemplate still throws : template not found
Once this part of the action is exectuded, a new template appear in the Settings>File Templates> but in the templates tab and not in the Java EE which I guess it's normal.
0
Comment actions Permalink

This shouldn't be necessary at all; if you place the .ft file in the correct directory (corresponding to the package "fileTemplates.j2ee", all you need to do is call addTemplate() in your implementation of FileTemplateGroupDescriptorFactory.getFileTemplatesDescriptor(). The text will be loaded automatically.

0
Comment actions Permalink

It was my first step, so it's already done to..
here is the code

    @Override     public FileTemplateGroupDescriptor getFileTemplatesDescriptor() {         final FileTemplateGroupDescriptor groupDescriptor = new FileTemplateGroupDescriptor("myGroup",null);         groupDescriptor.addTemplate(new FileTemplateDescriptor("template1", StdFileTypes.JAVA.getIcon()));         groupDescriptor.addTemplate(new FileTemplateDescriptor("template2", StdFileTypes.JAVA.getIcon()));         return groupDescriptor;     } }




Remember that the fileTemplates are correctly added but their body are empty...
0
Comment actions Permalink

I'm getting the same problem, the templates are added but without content.
Also I found that adding the files to "fileTemplates" package (not fileTemplates.j2ee) with .ft extension and adding the .ft to the compiler options, the template is added automatically (and with content) to the "Templates" tab, even more, I don't need the extension point.
I think I can live with that workaround, but it would be nice to have a custom tab and a custom group with custom icons, etc (hence, use the extension point...)

0

Please sign in to leave a comment.