Extended Java Project Sample - plugin detail

New sample, in the New Project wizard's Samples > NetBeans Modules category. It is called "Extended Java Project".

NetBeans Plugin - Extended Java Project Sample
Plugin owner: geertjan
Website:
Added: 2008-03-26
License: CDDL
Category: NetBeans Rich Client Platform
Downloaded: 1,329 times
Rating:
 0, by 0 users

Plugin Log Show log

Versions available

Download plugin   Download size: 0.05 MB   Last Update: 2008-03-30

What's new in this version

FreeMarker templating language used.

Verifications for NetBeans versions

Plugin is not subject to any verification



Introduction

New sample, in the New Project wizard's Samples > NetBeans Modules category. It is called "Extended Java Project":

ext-anagram-5.png

Finish the wizard and you will have this module. The two highlighted classes below constitute the new "Specify Words" panel that you will see later, the highlighted file with the FTL extension is the FreeMarker template that will be used to generate the WordLibrary.java file based on the entries in the "Specify Words" panel.

ext-anagram-6.png

This is the relevant part of the WordLibrary template, showing FreeMarker iterator tags that will be replaced by the words that are set in the "Specify Words" panel:

ext-anagram-3.png

Install the above module. Then go to the New Project wizard. In the Java category, you will find "Extended Anagram Application":

ext-anagram-7.png

That's a Java application with the extra "Specify Words" panel'. Choose that wizard and click Next. You will see the standard first panel, for specifying the application's name and location.

But there's more! Click Next again and you will see your new panel, which you can fill in, as shown below:

ext-anagram-1.png

When you complete the wizard, you'll have the Anagram Game sample:

extended-jp-6.png

But... the WordLibrary.java file will have the words you specified in the "Specify Words" panel:

ext-anagram-2.png

In summary, the Extended Java Project sample illustrates that you can change the wizard that creates a Java application.

How to do this yourself:

  1. Create a Java application that contains the files that you want the user to have when they complete the wizard that you will create for them.

  2. Remove the files that the user should be able to influence from the wizard. Don't worry if removing one of these files causes error marks and compilation problems.

  3. Create a new module project.

  4. Use the Project Template wizard to put the Java application from step 1 above into the module as a template.

  5. When you complete the wizard above, you will have several files, including a wizard class and its visual JPanel class. Make a copy of each of the latter two. Change the iterator to create them. See the Extended Java Project's iterator if you need help here.

  6. Create a new empty file with a unique extension such as ".template" or ".javax". Copy the content of the class(es) that you want the user to influence via the wizard and paste the content into the file (as many files as you want to have templates for). Replace the parts of the file that should be changed by the wizard with FreeMarker tags, as shown above. Register the file as a FreeMarker file in the layer.xml file.

  7. How to use the second panel to let the user create additional files for their project? Look in the sources of the "Select Words" visual panel, the wizard panel, and the iterator. Especially look at insertSpecifiedWords() in the iterator.

[ You have to be logged in to be able to comment. ]

User Comments

There are no comments yet.

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo