{"id":766,"date":"2013-09-02T08:49:50","date_gmt":"2013-09-02T06:49:50","guid":{"rendered":"http:\/\/www.pellissier.co.za\/hermien\/?p=766"},"modified":"2013-09-02T08:49:50","modified_gmt":"2013-09-02T06:49:50","slug":"non-modal-wizards","status":"publish","type":"post","link":"https:\/\/www.pellissier.co.za\/hermien\/?p=766","title":{"rendered":"Non-Modal Wizards"},"content":{"rendered":"<p>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\u00a0<a href=\"https:\/\/platform.netbeans.org\/tutorials\/nbm-wizard.html\">NetBeans Wizard Module Tutorial<\/a> for a step by step description of how to work with the normal, modal wizards.<\/p>\n<p>In the above tutorial, the <a href=\"https:\/\/platform.netbeans.org\/tutorials\/nbm-wizard.html#action\">DemoWizardAction class<\/a> contains the sample code for calling the wizard. The relevant code for displaying the modal wizard is duplicated below for easy reference:<\/p>\n<p>[java]WizardDescriptor wiz = new WizardDescriptor(<br \/>\n        new WizardDescriptor.ArrayIterator<WizardDescriptor>(panels));<br \/>\nif (DialogDisplayer.getDefault().notify(wiz) == WizardDescriptor.FINISH_OPTION) {<br \/>\n    \/\/ do something<br \/>\n}[\/java]<\/p>\n<p>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:<\/p>\n<p>[java]WizardDescriptor wiz = new WizardDescriptor(<br \/>\n        new WizardDescriptor.ArrayIterator<WizardDescriptor>(panels));<br \/>\nDialog wizardDialog = DialogDisplayer.getDefault().createDialog(wiz);<br \/>\nwizardDialog.setModal(false);<br \/>\nwizardDialog.setVisible(true);[\/java]<\/p>\n<p>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:<\/p>\n<p>[java]WizardDescriptor wiz = new WizardDescriptor(<br \/>\n        new WizardDescriptor.ArrayIterator<WizardDescriptor>(panels));<br \/>\nwiz.addPropertyChangeListener(new PropertyChangeListener() {<\/p>\n<p>    @Override<br \/>\n    public void propertyChange(PropertyChangeEvent evt) {<br \/>\n        if (evt.getNewValue() != null &#038;&#038; &#8220;org.openide.WizardDescriptor.FinishAction&#8221;.<br \/>\n                 equals(evt.getNewValue().getClass().getCanonicalName())) {<br \/>\n            \/\/ do something<br \/>\n        }<br \/>\n    }<br \/>\n});<\/p>\n<p>Dialog wizardDialog = DialogDisplayer.getDefault().createDialog(wiz);<br \/>\nwizardDialog.setModal(false);<br \/>\nwizardDialog.setVisible(true);[\/java]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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\u00a0NetBeans Wizard Module Tutorial for a step by step description of how to work with the normal, modal wizards. In the above tutorial, &#8230; <a title=\"Non-Modal Wizards\" class=\"read-more\" href=\"https:\/\/www.pellissier.co.za\/hermien\/?p=766\" aria-label=\"More on Non-Modal Wizards\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[3,5],"tags":[],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p1v8WL-cm","_links":{"self":[{"href":"https:\/\/www.pellissier.co.za\/hermien\/index.php?rest_route=\/wp\/v2\/posts\/766"}],"collection":[{"href":"https:\/\/www.pellissier.co.za\/hermien\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pellissier.co.za\/hermien\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pellissier.co.za\/hermien\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pellissier.co.za\/hermien\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=766"}],"version-history":[{"count":11,"href":"https:\/\/www.pellissier.co.za\/hermien\/index.php?rest_route=\/wp\/v2\/posts\/766\/revisions"}],"predecessor-version":[{"id":844,"href":"https:\/\/www.pellissier.co.za\/hermien\/index.php?rest_route=\/wp\/v2\/posts\/766\/revisions\/844"}],"wp:attachment":[{"href":"https:\/\/www.pellissier.co.za\/hermien\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=766"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pellissier.co.za\/hermien\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=766"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pellissier.co.za\/hermien\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=766"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}