New Wizard Tutorial for the NetBeans Platform

Bartek Zdanowski (pictured left), one of the students who attended the recent NetBeans Platform Certified Training in Warsaw, and who won a copy of Rich Client Programming: Plugging into the NetBeans Platform because of all the good questions he asked, seemed to be interested in the NetBeans Wizard infrastructure. I mentioned it at the end of the training, while listing several other APIs that might also be interesting, but that had not been covered during the two days of training.

One of the great questions he asked was: "How do I localize the texts in a wizard?" And then I realized that, although various resources are available for creating wizards for NetBeans Platform applications, there isn't yet an official tutorial. So today I created it:

NetBeans Wizard Module Tutorial

Note: If anyone is aware of any other resources that should be linked into the above tutorial, PLEASE let me know. It would be great if the above document were to become a central reference point for everything relating to wizards created for NetBeans Platform applications.

It definitely covers most of the common use cases and questions relating to the Wizard API classes. One big area is missing, relating to validation of user input in the wizard, although the reference to Tom's sample at the end of the tutorial should be sufficient until I add that section.

In an e-mail to me yesterday, Bartek writes: "I plan to write a Jabber chat plugin that integrates with NetBeans. It should be a very nice addition for team work." Definitely! That would also qualify you as a "NetBeans Platform Certified Engineer"!

Comments:

Regarding the validation: Besides the way proposed by Tom Wheeler, you can also use WizardDescriptor.ValidatingPanel interface, it defines "void validate() throws WizardValidationException" method. This method is called when the next/finish button is pressed. You can do the validation in it and throw that exception, which will display a red error message (with text specified as the exception's constructor parameter) in the bottom part of the panel. It does not, however, enable/disable next/finish buttons and the message is displayed until the next validation.

You can also put a message in that bottom part by using WizardDescriptor.putProperty method with one of the following properties:
- WizardDescriptor.PROP_ERROR_MESSAGE
- WizardDescriptor.PROP_WARNING_MESSAGE
- WizardDescriptor.PROP_INFO_MESSAGE
null value clears the displayed message

Btw. is the NetBeans javadocs web down now? I'm getting 404 for everything I try to look up there. I can open http://bits.netbeans.org/dev/javadoc/ but the rest is 404.

Posted by Honza Pozivil on March 31, 2009 at 04:23 AM PDT #

Awesome tutorial..

Posted by Varun Nischal on March 31, 2009 at 06:14 PM PDT #

Hi,

I am doing some experiments in custom file creation wizards (to be used within the IDE).
Maybe the question is of general interest : How can I write a wizard, that retrieves current project information from netbeans IDE, in the same way as new TopComponent wizard does ?

So where is the problem ?
Wizard generation and a lot of examples are out there ... while studing the code of

org.netbeans.modules.apisupport.project.ui.wizard.common.BasicWizardIterator
(+friends ie NewTCIterator)

I found the retrieval of NbModuleProvider via lookup within initialize :

Project tmpProject = Templates.getProject(wiz);
boolean isValidPrj = (tmpProject != null && tmpProject.getLookup().lookup(NbModuleProvider.class) != null);

The NbModuleProvider seems to be important for assignment of the replacement variables that are need for codegeneration via file templates (see. generateFileChanges within NewTCIterator). Which is of interest to me.

I extracted that code and put it into my own wizard's initizialize function ( which was created by "new wizard" wizard, registration type "New File" enabled, IDE Version 7.3). Looks like :

@Override
public void initialize(WizardDescriptor wizard) {
this.wizard = wizard;
Project tmpProject = Templates.getProject(wizard);
boolean isValidPrj = (tmpProject != null && tmpProject.getLookup().lookup(NbModuleProvider.class) != null);
System.out.println("ValidProject "+isValidPrj);
JOptionPane.showMessageDialog(null, "ValidProject "+isValidPrj);
}

Finaly I discovered that NbModuleProvider is not present within projects lookup ... but why ? I expected to be in the same situation as the new TopComponentWizard is.

Thanks in advance.

Posted by guest on April 08, 2013 at 07:10 AM PDT #

Why don't you just look up the Project.class instead of that one, which is probably some internal class and not a public API?

Posted by Geertjan on April 08, 2013 at 12:06 PM PDT #

My idea is to build a custom TopComponent say "MyTopComponent".
MyTopComponent provides some interfaces my GUI components depends on. Simliar to ExplorerManagerProvider behavior.

Now I think about a wizard that will use a MyTopComponent based template instead of TopComponent. (The file will result in a form, which can be edited by matisse, too) I have done this for JPanel Forms. That was easy. When starting to repeat this with MyTopComponent I came to the idea to use some annotations to register MyTopComponent at custom folders within layer.xml together with additional informations.

So I want some other template for the new TopComponent wizard and some new pages that configure the additional Annotations. Because I had no idea where to start, i started to read the "NewTopComponentWizard" code.

While doing so, I felt like I have to reconstruct its behavior to get my wizards realized. To do so, I have to set the replace variables for the code template, which -within "NewTopComponentWizard"- seem to be obtained by asking NbModuleProvider for things like "getCodeNameBase()". Project simply provides its lookup and getProjectDirectory. No codeBase or something like that.
While trying to obtain the same information from the project lookup, I found an interfaces list on (blue box):

http://bits.netbeans.org/dev/javadoc/org-netbeans-modules-projectapi/org/netbeans/api/project/Project.html

But I didn't find the one that is equivalent to NbModuleProvider yet :-(
May be I am going to complete wrong way to get such a wizard ?

Posted by guest on April 08, 2013 at 01:40 PM PDT #

OK, this is really the wrong place for long discussions. Join the dev@platform.netbeans.org mailing list and ask your questions there.

Posted by Geertjan on April 08, 2013 at 02:52 PM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

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.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today