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 23116
Collapse All | Expand All

(-)src/org/openide/WizardDescriptor.java (+41 lines)
Lines 1002-1007 Link Here
1002
    public interface FinishPanel extends Panel {
1002
    public interface FinishPanel extends Panel {
1003
    }
1003
    }
1004
1004
1005
    /** A special interface for panels that need to do additional
1006
     * validation when Next or Finish button is clicked.
1007
     */
1008
    public interface ValidatingPanel extends Panel {
1009
        /** Is called when Next of Finish buttons are clicked and 
1010
         * allows deeper check to find out that panel is in valid 
1011
         * state and it is ok to leave it.
1012
         *
1013
         * @return null if everything is ok or a localized message to show to
1014
         *   user
1015
         */
1016
        public String validate ();
1017
    }
1018
    
1005
    /** Special iterator that works on an array of <code>Panel</code>s.
1019
    /** Special iterator that works on an array of <code>Panel</code>s.
1006
    */
1020
    */
1007
    public static class ArrayIterator extends Object implements Iterator {
1021
    public static class ArrayIterator extends Object implements Iterator {
Lines 1111-1116 Link Here
1111
        public void actionPerformed (ActionEvent ev) {
1125
        public void actionPerformed (ActionEvent ev) {
1112
            if (ev.getSource () == nextButton) {
1126
            if (ev.getSource () == nextButton) {
1113
                Dimension previousSize = panels.current().getComponent().getSize();
1127
                Dimension previousSize = panels.current().getComponent().getSize();
1128
                
1129
                if (panels.current() instanceof ValidatingPanel) {
1130
                    ValidatingPanel v = (ValidatingPanel)panels.current ();
1131
                    String msg = v.validate();
1132
                    if ("xtest-fail-without-msg".equals (msg)) {
1133
                        return;
1134
                    }
1135
                    
1136
                    if (msg != null) {
1137
                        DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(msg));
1138
                        return;
1139
                    }
1140
                }
1141
                
1114
                panels.nextPanel ();
1142
                panels.nextPanel ();
1115
                try {
1143
                try {
1116
                    // change UI to show next step, show wait cursor during
1144
                    // change UI to show next step, show wait cursor during
Lines 1140-1145 Link Here
1140
            }
1168
            }
1141
1169
1142
            if (ev.getSource () == finishButton) {
1170
            if (ev.getSource () == finishButton) {
1171
                if (panels.current() instanceof ValidatingPanel) {
1172
                    ValidatingPanel v = (ValidatingPanel)panels.current ();
1173
                    String msg = v.validate();
1174
                    if ("xtest-fail-without-msg".equals (msg)) {
1175
                        return;
1176
                    }
1177
                    
1178
                    if (msg != null) {
1179
                        DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(msg));
1180
                        return;
1181
                    }
1182
                }
1183
                
1143
                Object oldValue = getValue ();
1184
                Object oldValue = getValue ();
1144
                setValueWithoutPCH (OK_OPTION);
1185
                setValueWithoutPCH (OK_OPTION);
1145
                if (Arrays.asList(getClosingOptions()).contains(finishButton)) {
1186
                if (Arrays.asList(getClosingOptions()).contains(finishButton)) {
(-)test/unit/src/org/openide/WizardDescTest.java (-2 / +52 lines)
Lines 102-117 Link Here
102
        assertEquals ("Closed with cancel option.", WizardDescriptor.CANCEL_OPTION, wd.getValue ());
102
        assertEquals ("Closed with cancel option.", WizardDescriptor.CANCEL_OPTION, wd.getValue ());
103
    }
103
    }
104
104
105
    public void testNextOptionWhenLazyValidationFails () throws Exception {
106
        Panel panels[] = new Panel[3];
107
        
108
        class MyPanel extends Panel implements WizardDescriptor.ValidatingPanel {
109
            public String validateMsg;
110
            
111
            public MyPanel () {
112
                super ("enhanced panel");
113
            }
114
            
115
            public String validate () {
116
                return validateMsg;
117
            }
118
        }
119
        
120
        class MyFinishPanel extends MyPanel implements WizardDescriptor.FinishPanel {
121
        }
122
        
123
        MyPanel mp = new MyPanel ();
124
        MyFinishPanel mfp = new MyFinishPanel ();
125
        panels[0] = mp;
126
        panels[1] = mfp;
127
        panels[2] = new Panel ("Last one");
128
        wd = new WizardDescriptor(panels);
129
        
130
        assertNull ("Component has not been yet initialized", panels[1].component);
131
        mp.validateMsg = "xtest-fail-without-msg";
132
        wd.doNextClick ();
133
        assertNull ("The lazy validation failed, still no initialiaation", panels[1].component);
134
        assertNull ("The lazy validation failed, still no initialiaation", panels[2].component);
135
        mp.validateMsg = null;
136
        wd.doNextClick ();
137
        assertNotNull ("Now we switched to another panel", panels[1].component);
138
        assertNull ("The lazy validation failed, still no initialiaation", panels[2].component);
139
        
140
        // remember previous state
141
        Object state = wd.getValue();
142
        mfp.validateMsg = "xtest-fail-without-msg";
143
        wd.doFinishClick();
144
        assertNull ("The validation failed, still no initialiaation", panels[2].component);
145
        assertEquals ("State has not changed", state, wd.getValue ());
146
        
147
        mfp.validateMsg = null;
148
        wd.doFinishClick ();
149
        assertNull ("Finish was clicked, no initialization either", panels[2].component);
150
        assertEquals ("The state is finish", WizardDescriptor.FINISH_OPTION, wd.getValue ());
151
    }
105
    
152
    
106
    public class Panel implements WizardDescriptor.Panel, WizardDescriptor.FinishPanel {
153
    public class Panel implements WizardDescriptor.Panel, WizardDescriptor.FinishPanel {
107
154
        private JLabel component;
108
        private String text;
155
        private String text;
109
        public Panel(String text) {
156
        public Panel(String text) {
110
            this.text = text;
157
            this.text = text;
111
        }
158
        }
112
        
159
        
113
        public Component getComponent() {
160
        public Component getComponent() {
114
            return new JLabel(text);
161
            if (component == null) {
162
                component = new JLabel (text);
163
            }
164
            return component;
115
        }
165
        }
116
        
166
        
117
        public void addChangeListener(ChangeListener l) {
167
        public void addChangeListener(ChangeListener l) {

Return to bug 23116