This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 7706
Collapse All | Expand All

(-)src/org/openide/WizardDescriptor.java (-4 / +50 lines)
Lines 492-501 Link Here
492
492
493
        nextButton.setEnabled (next && valid);
493
        nextButton.setEnabled (next && valid);
494
        previousButton.setEnabled (prev);
494
        previousButton.setEnabled (prev);
495
        finishButton.setEnabled (
495
        
496
            valid &&
496
        if (current instanceof FinishablePanel) {
497
            (!next || (current instanceof FinishPanel))
497
            // check if isFinishPanel
498
        );
498
            if (((FinishablePanel)current).isFinishPanel ()) {
499
                finishButton.setEnabled (valid);
500
            } else {
501
                // XXX What if the last panel is not FinishPanel ??? enabled ?
502
                finishButton.setEnabled (valid && !next);
503
            }
504
        } else {
505
            // original way
506
            finishButton.setEnabled (
507
                valid &&
508
                (!next || (current instanceof FinishPanel))
509
            );
510
        }
499
511
500
        //    nextButton.setVisible (next);
512
        //    nextButton.setVisible (next);
501
        //    finishButton.setVisible (!next || (current instanceof FinishPanel));
513
        //    finishButton.setVisible (!next || (current instanceof FinishPanel));
Lines 1009-1020 Link Here
1009
    * iterators path that would like to have the finish button
1021
    * iterators path that would like to have the finish button
1010
    * enabled. So both Next and Finish are enabled on panel
1022
    * enabled. So both Next and Finish are enabled on panel
1011
    * implementing this interface.
1023
    * implementing this interface.
1024
    * @deprecated XXX
1012
    */
1025
    */
1013
    public interface FinishPanel extends Panel {
1026
    public interface FinishPanel extends Panel {
1014
    }
1027
    }
1015
1028
1016
    /** A special interface for panels that need to do additional
1029
    /** A special interface for panels that need to do additional
1017
     * validation when Next or Finish button is clicked.
1030
     * validation when Next or Finish button is clicked.
1031
     * @since XXX
1018
     */
1032
     */
1019
    public interface ValidatingPanel extends Panel {
1033
    public interface ValidatingPanel extends Panel {
1020
1034
Lines 1024-1033 Link Here
1024
         * state and it is ok to leave it.
1038
         * state and it is ok to leave it.
1025
         *
1039
         *
1026
         * @throws WizardValidationException when validation fails
1040
         * @throws WizardValidationException when validation fails
1041
         * @since XXX
1027
         */
1042
         */
1028
        public void validate () throws WizardValidationException;
1043
        public void validate () throws WizardValidationException;
1029
    }
1044
    }
1030
    
1045
    
1046
    /** A special interface for panels that need to dynamically enabled
1047
     *  Finish button.
1048
     * @since XXX
1049
     */
1050
    public interface FinishablePanel extends Panel {
1051
        
1052
        /** Specify if this panel would enable Finish button. Finish button is 
1053
         * enabled if and only if isValid() returns true and isFinishPanel() 
1054
         * returns true. 
1055
         *
1056
         * @return Finish button could be enabled
1057
         * @since XXX
1058
         */        
1059
        boolean isFinishPanel();
1060
    }
1061
1062
1063
    
1031
    /** Special iterator that works on an array of <code>Panel</code>s.
1064
    /** Special iterator that works on an array of <code>Panel</code>s.
1032
    */
1065
    */
1033
    public static class ArrayIterator extends Object implements Iterator {
1066
    public static class ArrayIterator extends Object implements Iterator {
Lines 1850-1855 Link Here
1850
            cancelButton.doClick ();
1883
            cancelButton.doClick ();
1851
        }
1884
        }
1852
    }
1885
    }
1886
    
1887
    // helper method, might be removed from code
1888
    // returns false if Next button is disabled
1889
    boolean isNextEnabled () {
1890
        return nextButton.isEnabled ();
1891
    }
1892
    
1893
    // helper method, might be removed from code
1894
    // returns false if Finish button is disabled
1895
    boolean isFinishEnabled () {
1896
        return finishButton.isEnabled ();
1897
    }
1898
1853
    
1899
    
1854
    // helper, make possible close wizard as finish
1900
    // helper, make possible close wizard as finish
1855
    static class FinishAction extends Object {
1901
    static class FinishAction extends Object {
(-)test/unit/src/org/openide/WizardDescTest.java (+83 lines)
Lines 163-168 Link Here
163
        assertEquals ("The state is finish", WizardDescriptor.FINISH_OPTION, wd.getValue ());
163
        assertEquals ("The state is finish", WizardDescriptor.FINISH_OPTION, wd.getValue ());
164
    }
164
    }
165
    
165
    
166
    public void testDynamicallyEnabledFinish () throws Exception {
167
        WizardDescriptor.Panel panels[] = new WizardDescriptor.Panel [2];
168
        
169
        class MaybeFinishPanel implements WizardDescriptor.Panel, WizardDescriptor.FinishablePanel {
170
            private JLabel component;
171
            private String text;
172
            
173
            public boolean isValid = true;
174
            public boolean isFinishPanel = true;
175
            
176
            public MaybeFinishPanel () {
177
                text = "maybe finish panel";
178
            }
179
            
180
            public boolean isFinishPanel () {
181
                return isFinishPanel;
182
            }
183
            
184
            public boolean isValid () {
185
                return isValid;
186
            }
187
            
188
            public MaybeFinishPanel (String text) {
189
                this.text = text;
190
            }
191
192
            public Component getComponent() {
193
                if (component == null) {
194
                    component = new JLabel (text);
195
                }
196
                return component;
197
            }
198
199
            public void addChangeListener(ChangeListener l) {
200
            }
201
202
            public HelpCtx getHelp() {
203
                return null;
204
            }
205
206
            public void readSettings(Object settings) {
207
            }
208
209
            public void removeChangeListener(ChangeListener l) {
210
            }
211
212
            public void storeSettings(Object settings) {
213
            }
214
        }
215
        
216
        MaybeFinishPanel firstPanel = new MaybeFinishPanel ();
217
        Panel normalPanel = new Panel ("normal panel");
218
        panels[0] = firstPanel;
219
        panels[1] = normalPanel;
220
        wd = new WizardDescriptor(panels);
221
        
222
        // if 1. panel is not valid then both button are disabled
223
        firstPanel.isValid = false;
224
        firstPanel.isFinishPanel = false;
225
        wd.updateState ();
226
        assertFalse ("Panel is not valid and Next button is disabled.", wd.isNextEnabled ());
227
        assertFalse ("Panel is not valid and Finish button is disabled as well.", wd.isFinishEnabled ());
228
        
229
        // now will be panel valid => next will be enabled and finish 
230
        // button disabled because this panel doesn't implement WD.FinishPanel
231
        firstPanel.isValid = true;
232
        wd.updateState ();
233
        assertTrue ("Panel is valid then Next button is enabled.", wd.isNextEnabled ());
234
        assertFalse ("Panel doesn't implement WD.FinishPanel.", panels[0] instanceof WizardDescriptor.FinishPanel);
235
        assertFalse ("Panel is valid but Finish button is disabled because not FinishPanel.", wd.isFinishEnabled ());
236
237
        // panel is valid and finish is enabled => next will be enabled and finish 
238
        // button enabled too because this panel implements WD.FinishablePanel
239
        // isFinishEnabled() returns true despite doesn't implement WD.FinishPanel
240
        firstPanel.isValid = true;
241
        firstPanel.isFinishPanel = true;
242
        wd.updateState ();
243
        assertTrue ("Panel is valid then Next button is enabled.", wd.isNextEnabled ());
244
        assertFalse ("Panel doesn't implement WD.FinishPanel.", panels[0] instanceof WizardDescriptor.FinishPanel);
245
        assertTrue ("Panel implements WD.FinishablePanel.", panels[0] instanceof WizardDescriptor.FinishablePanel);
246
        assertTrue ("Panel is enabled because implements FinishablePanel.", wd.isFinishEnabled ());
247
    }
248
    
166
    public class Panel implements WizardDescriptor.Panel, WizardDescriptor.FinishPanel {
249
    public class Panel implements WizardDescriptor.Panel, WizardDescriptor.FinishPanel {
167
        private JLabel component;
250
        private JLabel component;
168
        private String text;
251
        private String text;

Return to bug 7706