Sep 022013
 

Creating a wizard in a NetBeans Platform Application is quite easy since there is a NetBeans IDE new file wizard that creates all of the scaffolding for you. Have a look at theĀ NetBeans Wizard Module Tutorial for a step by step description of how to work with the normal, modal wizards.

In the above tutorial, the DemoWizardAction class contains the sample code for calling the wizard. The relevant code for displaying the modal wizard is duplicated below for easy reference:

WizardDescriptor wiz = new WizardDescriptor(
        new WizardDescriptor.ArrayIterator<WizardDescriptor>(panels));
if (DialogDisplayer.getDefault().notify(wiz) == WizardDescriptor.FINISH_OPTION) {
    // do something
}

I recently ran into a use case where it was required that the wizard must be non-modal. Whether this is a desirable behaviour for a wizard is a topic all of its own, so lets just assume that we want to be able to do this. The code to display the wizard as non-modal is shown below:

WizardDescriptor wiz = new WizardDescriptor(
        new WizardDescriptor.ArrayIterator<WizardDescriptor>(panels));
Dialog wizardDialog = DialogDisplayer.getDefault().createDialog(wiz);
wizardDialog.setModal(false);
wizardDialog.setVisible(true);

Now the remaining complication is being able to catch the event that indicates that the wizard completed with the option WizardDescriptor.FINISH_OPTION as in the original code. I noticed that the WizardDescriptor allows for the registration of property change listeners. And so by debugging into the propertyChange method, I was able to determine what must be handled to catch this particular event:

WizardDescriptor wiz = new WizardDescriptor(
        new WizardDescriptor.ArrayIterator<WizardDescriptor>(panels));
wiz.addPropertyChangeListener(new PropertyChangeListener() {

    @Override
    public void propertyChange(PropertyChangeEvent evt) {
        if (evt.getNewValue() != null && "org.openide.WizardDescriptor.FinishAction".
                 equals(evt.getNewValue().getClass().getCanonicalName())) {
            // do something
        }
    }
});

Dialog wizardDialog = DialogDisplayer.getDefault().createDialog(wiz);
wizardDialog.setModal(false);
wizardDialog.setVisible(true);

  3 Responses to “Non-Modal Wizards”

  1. Oh, this is great !
    Also, is there a way of putting the wizard dialog into a TopComponent?

  2. Thanx lot for explanations. I want to add a Key Action(Enter) on WizardDescriptor. If I press on Enter, it should do same thing as Finish button. Could you please help me? How can I register or add such a action?

 Leave a Reply

(required)

(required)


7 − five =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>