Friday Mar 21, 2014

Entity Expander for NetBeans IDE 8 (Part 2)

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.


Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.


« March 2014 »