Index: src/org/openide/WizardDescriptor.java =================================================================== RCS file: /cvs/openide/src/org/openide/WizardDescriptor.java,v retrieving revision 1.94.2.3 retrieving revision 1.94.2.5 diff -u -r1.94.2.3 -r1.94.2.5 --- src/org/openide/WizardDescriptor.java 14 Mar 2004 23:44:52 -0000 1.94.2.3 +++ src/org/openide/WizardDescriptor.java 21 Mar 2004 20:58:26 -0000 1.94.2.5 @@ -492,10 +492,22 @@ nextButton.setEnabled (next && valid); previousButton.setEnabled (prev); - finishButton.setEnabled ( - valid && - (!next || (current instanceof FinishPanel)) - ); + + if (current instanceof FinishablePanel) { + // check if isFinishPanel + if (((FinishablePanel)current).isFinishPanel ()) { + finishButton.setEnabled (valid); + } else { + // XXX What if the last panel is not FinishPanel ??? enabled ? + finishButton.setEnabled (valid && !next); + } + } else { + // original way + finishButton.setEnabled ( + valid && + (!next || (current instanceof FinishPanel)) + ); + } // nextButton.setVisible (next); // finishButton.setVisible (!next || (current instanceof FinishPanel)); @@ -1009,12 +1021,14 @@ * iterators path that would like to have the finish button * enabled. So both Next and Finish are enabled on panel * implementing this interface. + * @deprecated XXX */ public interface FinishPanel extends Panel { } /** A special interface for panels that need to do additional * validation when Next or Finish button is clicked. + * @since XXX */ public interface ValidatingPanel extends Panel { @@ -1024,10 +1038,29 @@ * state and it is ok to leave it. * * @throws WizardValidationException when validation fails + * @since XXX */ public void validate () throws WizardValidationException; } + /** A special interface for panels that need to dynamically enabled + * Finish button. + * @since XXX + */ + public interface FinishablePanel extends Panel { + + /** Specify if this panel would enable Finish button. Finish button is + * enabled if and only if isValid() returns true and isFinishPanel() + * returns true. + * + * @return Finish button could be enabled + * @since XXX + */ + boolean isFinishPanel(); + } + + + /** Special iterator that works on an array of Panels. */ public static class ArrayIterator extends Object implements Iterator { @@ -1850,6 +1883,19 @@ cancelButton.doClick (); } } + + // helper method, might be removed from code + // returns false if Next button is disabled + boolean isNextEnabled () { + return nextButton.isEnabled (); + } + + // helper method, might be removed from code + // returns false if Finish button is disabled + boolean isFinishEnabled () { + return finishButton.isEnabled (); + } + // helper, make possible close wizard as finish static class FinishAction extends Object { Index: test/unit/src/org/openide/WizardDescTest.java =================================================================== RCS file: /cvs/openide/test/unit/src/org/openide/WizardDescTest.java,v retrieving revision 1.2.54.1 retrieving revision 1.2.54.2 diff -u -r1.2.54.1 -r1.2.54.2 --- test/unit/src/org/openide/WizardDescTest.java 14 Mar 2004 22:43:34 -0000 1.2.54.1 +++ test/unit/src/org/openide/WizardDescTest.java 21 Mar 2004 20:58:27 -0000 1.2.54.2 @@ -163,6 +163,89 @@ assertEquals ("The state is finish", WizardDescriptor.FINISH_OPTION, wd.getValue ()); } + public void testDynamicallyEnabledFinish () throws Exception { + WizardDescriptor.Panel panels[] = new WizardDescriptor.Panel [2]; + + class MaybeFinishPanel implements WizardDescriptor.Panel, WizardDescriptor.FinishablePanel { + private JLabel component; + private String text; + + public boolean isValid = true; + public boolean isFinishPanel = true; + + public MaybeFinishPanel () { + text = "maybe finish panel"; + } + + public boolean isFinishPanel () { + return isFinishPanel; + } + + public boolean isValid () { + return isValid; + } + + public MaybeFinishPanel (String text) { + this.text = text; + } + + public Component getComponent() { + if (component == null) { + component = new JLabel (text); + } + return component; + } + + public void addChangeListener(ChangeListener l) { + } + + public HelpCtx getHelp() { + return null; + } + + public void readSettings(Object settings) { + } + + public void removeChangeListener(ChangeListener l) { + } + + public void storeSettings(Object settings) { + } + } + + MaybeFinishPanel firstPanel = new MaybeFinishPanel (); + Panel normalPanel = new Panel ("normal panel"); + panels[0] = firstPanel; + panels[1] = normalPanel; + wd = new WizardDescriptor(panels); + + // if 1. panel is not valid then both button are disabled + firstPanel.isValid = false; + firstPanel.isFinishPanel = false; + wd.updateState (); + assertFalse ("Panel is not valid and Next button is disabled.", wd.isNextEnabled ()); + assertFalse ("Panel is not valid and Finish button is disabled as well.", wd.isFinishEnabled ()); + + // now will be panel valid => next will be enabled and finish + // button disabled because this panel doesn't implement WD.FinishPanel + firstPanel.isValid = true; + wd.updateState (); + assertTrue ("Panel is valid then Next button is enabled.", wd.isNextEnabled ()); + assertFalse ("Panel doesn't implement WD.FinishPanel.", panels[0] instanceof WizardDescriptor.FinishPanel); + assertFalse ("Panel is valid but Finish button is disabled because not FinishPanel.", wd.isFinishEnabled ()); + + // panel is valid and finish is enabled => next will be enabled and finish + // button enabled too because this panel implements WD.FinishablePanel + // isFinishEnabled() returns true despite doesn't implement WD.FinishPanel + firstPanel.isValid = true; + firstPanel.isFinishPanel = true; + wd.updateState (); + assertTrue ("Panel is valid then Next button is enabled.", wd.isNextEnabled ()); + assertFalse ("Panel doesn't implement WD.FinishPanel.", panels[0] instanceof WizardDescriptor.FinishPanel); + assertTrue ("Panel implements WD.FinishablePanel.", panels[0] instanceof WizardDescriptor.FinishablePanel); + assertTrue ("Panel is enabled because implements FinishablePanel.", wd.isFinishEnabled ()); + } + public class Panel implements WizardDescriptor.Panel, WizardDescriptor.FinishPanel { private JLabel component; private String text;