Using Netbeans Wizards
Wednesday Jun 27, 2007
With the help of Geertjan's blog series (part1, part2, part3, part4 and part5) about how to make use of Wizard API to define our own wizards, I created a wizard to create a new XML file in my own custom project. Thank you Geertjan for posting this wizard series. It helped a lot.
I used 'New Wizard' wizard to create a wizard with 4 panels for creating a new file. The wizard for 'New Wizard' generated bunch of files and updated the module layer file by registering itself as the "instantiatingIterator". I just copied this part in the required place under 'Template' folder defined for the new filetype, for which I want this wizard to be shown. More details on this and how to create 'New Wizard' using the wizard are in part4 of Geertjan's series as mentioned above.
Ok, so far, so good. now onto the next things. I need to :
- Collect all the user inputs from 4 wizard panels.
- Provide just-in-time validation for mandatory fields and disable 'Next' button if required during validation errors.
- Create a new XML file with user data filled in.
Ok, for the first, I am using WizardDescriptor to remember the user inputs across the panels. Here wizard descriptor is the data store and each 'WizardPanel' (not the visual panel) have methods to store/retrieve data from this data store. So when the user goes to next panel and comes back to the current panel, the entered value is retained. See the javadoc for WizardDescriptor.Panel for more details on how to use these methods.
On the second point I was looking for some examples on how to implement the just-in-time validation. I saw this happening in existing several places like, New File Wizard, New Project Wizard etc.. Here is the panel from 'New Project Wizard' showing just-in-time validation with an error icon and a message below the fields, but just above the navigation buttons.

So cool.. ok where should I look for the help? ask in mailing lists or search? Well.. best and quick way : look into the sources!! Yes, look into the corresponding sources..
"apisupport/project module" (org.netbeans.modules.apisupport.project.ui.wizard) is the one. Geertjan recently wrote about how to re-use the existing wizards and customize them. Another great series from Geertjan! (part1, part2 and part3). Nice, thank you Geertjan again. So going back to org.netbeans.modules.apisupport.project.ui.wizard, I could see how the whole new module wizards are created. There are two base classes : BasicWizardPanel.java and BasicVisualPanel.java. [both links point to repository source browser] The BasicVisualPanel class has the helper methods like setting the error message, setting warning message, marking the wizard state as invalid so that the 'Next' button is disabled and finally clearing any warning/error messages and making the wizard state valid. This is convenient as any wizard panel which extends BasicVisualPanel class, will have all these methods ready and available for use. There is a notification in the form of Property Change event to tell the wizard panel about validation results and enable/disable 'Next' button.
The Basic wizard panel listens to the property change events and updates the wizard state when required. This having two different classes for each wizard panel (wizard panel and a visual panel) is considered to be performance wise good. See details about why this is so here.
About the third, I need to construct a DOM tree or a JAXB stub with data read from wizard descriptor and filled into it and marshal the stub to a physical file.
Netbeans wizards are indeed mightier...










