Geertjan's Blog

  • March 21, 2014

Entity Expander for NetBeans IDE 8 (Part 2)

Geertjan Wielenga
Product Manager

Let's imagine you read my blog entry yesterday where I showed how to create a template that generates a Vaadin Form from a plain old Java object. However, while reading that blog entry you might have thought to yourself: "Hmmm, what a pity that the template is hardcoded within the module, i.e., the end user isn't going to be able to change the template and so this story is only relevant for Vaadin users."

Well, you couldn't be more wrong, if you thought the above. Install the module and then go to Tools | Templates, as shown below. 

The Template Manager shows "vaadinForm" in the "EntityTemplates" folder, as you can see here:

When you select "vaadinForm", the "Open in Editor" button, shown above, becomes enabled. Click it... and then the template opens into the editor, as you can see here: 

And now you can change the template! In fact, you can even completely rewrite the template, so long as you bear in mind the relevance of the FreeMarker variables you see above:

  • ${object} - the name of the POJO from which the new class will be generated
  • ${package} - the name of the package where the new class will be put
  • ${fields} - this gives you access to all the fields in the POJO, with which you can do whatever you need

As you can see below, I changed "TextField" to "Something":

As soon as you have saved the above template (i.e., just click Save), whenever you use "Generate Vaadin Form" the changed template will be used, i.e., whatever changes you make will be applied the very next time you invoke the Action shown below:

What this means is that the Vaadin Form template could be the basis of generating anything at all from your entity classes. I think that's pretty awesome.

Now, think about what all this means. The above is the basis of a far more generic solution. I'm going to work on a more general plugin that exposes not only the fields, but also the methods, and any other class members, to the template. Then the user, i.e., a developer that has a POJO that should be treated as the basis of something else, will be able to generate something else, anything they want, from the fields and methods (and constructor and anything else) in any POJO in their application.

Join the discussion

Comments ( 1 )
  • Guy Daniel Friday, March 21, 2014

    Wow! This is something I have to study in more detail. You have my vote for a more general plugin!

    I have written reflective code for my POJOs that creates java code for the model (essentially a map with change events) and persistance/REST layers for my Presenter object. I do use annotations though, to indicate key, primary, autoincrement fields etc... as well as view hints (order, num decimals), so if these were exposed in the template too, this would be great!

    An editor template solution would be good, it would stop me from having to do the psvm for code generation.

Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.