Lines 7-13
Link Here
|
7 |
* http://www.sun.com/ |
7 |
* http://www.sun.com/ |
8 |
* |
8 |
* |
9 |
* The Original Code is NetBeans. The Initial Developer of the Original |
9 |
* The Original Code is NetBeans. The Initial Developer of the Original |
10 |
* Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun |
10 |
* Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun |
11 |
* Microsystems, Inc. All Rights Reserved. |
11 |
* Microsystems, Inc. All Rights Reserved. |
12 |
*/ |
12 |
*/ |
13 |
package org.openide; |
13 |
package org.openide; |
Lines 26-31
Link Here
|
26 |
import javax.swing.event.ChangeListener; |
26 |
import javax.swing.event.ChangeListener; |
27 |
import org.netbeans.junit.NbTestCase; |
27 |
import org.netbeans.junit.NbTestCase; |
28 |
import org.openide.WizardDescriptor; |
28 |
import org.openide.WizardDescriptor; |
|
|
29 |
import org.openide.WizardDescriptor.ValidatingPanel; |
30 |
import org.openide.WizardDescriptor.AsynchronousValidatingPanel; |
29 |
import org.openide.util.*; |
31 |
import org.openide.util.*; |
30 |
import org.openide.util.HelpCtx; |
32 |
import org.openide.util.HelpCtx; |
31 |
|
33 |
|
Lines 58-63
Link Here
|
58 |
//d.show(); |
60 |
//d.show(); |
59 |
} |
61 |
} |
60 |
|
62 |
|
|
|
63 |
public boolean runInEQ () { |
64 |
return true; |
65 |
} |
66 |
|
61 |
public void testNextOption () throws Exception { |
67 |
public void testNextOption () throws Exception { |
62 |
exceptedValue = "NEXT_OPTION"; |
68 |
exceptedValue = "NEXT_OPTION"; |
63 |
log ("Do click Next button."); |
69 |
log ("Do click Next button."); |
Lines 162-167
Link Here
|
162 |
mfp.validateMsg = null; |
168 |
mfp.validateMsg = null; |
163 |
mfp.failedMsg = null; |
169 |
mfp.failedMsg = null; |
164 |
wd.doFinishClick (); |
170 |
wd.doFinishClick (); |
|
|
171 |
assertNull ("Validation on Finish passes", mfp.failedMsg); |
172 |
assertNull ("Finish was clicked, no initialization either", panels[2].component); |
173 |
assertEquals ("The state is finish", WizardDescriptor.FINISH_OPTION, wd.getValue ()); |
174 |
} |
175 |
|
176 |
public void testAsynchronousLazyValidation () throws Exception { |
177 |
Panel panels[] = new Panel[3]; |
178 |
|
179 |
class MyPanel extends Panel implements WizardDescriptor.AsynchronousValidatingPanel { |
180 |
public String validateMsg; |
181 |
public String failedMsg; |
182 |
public boolean running; |
183 |
|
184 |
public MyPanel () { |
185 |
super ("enhanced panel"); |
186 |
} |
187 |
|
188 |
public void prepareValidation () { |
189 |
running = true; |
190 |
} |
191 |
|
192 |
public void validate () throws WizardValidationException { |
193 |
running = false; |
194 |
if (validateMsg != null) { |
195 |
failedMsg = validateMsg; |
196 |
throw new WizardValidationException (null, "MyPanel.validate() failed.", validateMsg); |
197 |
} |
198 |
return; |
199 |
} |
200 |
} |
201 |
|
202 |
class MyFinishPanel extends MyPanel implements WizardDescriptor.FinishablePanel { |
203 |
public boolean isFinishPanel () { |
204 |
return true; |
205 |
} |
206 |
} |
207 |
|
208 |
MyPanel mp = new MyPanel (); |
209 |
MyFinishPanel mfp = new MyFinishPanel (); |
210 |
panels[0] = mp; |
211 |
panels[1] = mfp; |
212 |
panels[2] = new Panel ("Last one"); |
213 |
wd = new WizardDescriptor(panels); |
214 |
|
215 |
assertNull ("Component has not been yet initialized", panels[1].component); |
216 |
mp.failedMsg = null; |
217 |
mp.validateMsg = "xtest-fail-without-msg"; |
218 |
assertTrue ("Next button must be enabled.", wd.isNextEnabled ()); |
219 |
wd.doNextClick (); |
220 |
assertTrue ("Validation runs.", mp.running); |
221 |
assertFalse ("Wizard is not valid now.", wd.isValid ()); |
222 |
// let's wait till wizard is valid |
223 |
while (mp.running) { |
224 |
assertFalse ("Wizard is not valid during validation.", wd.isValid ()); |
225 |
Thread.sleep (10); |
226 |
} |
227 |
assertFalse ("Wizard is not valid when validation fails.", wd.isValid ()); |
228 |
assertEquals ("The lazy validation failed on Next.", mp.validateMsg, mp.failedMsg); |
229 |
assertNull ("The lazy validation failed, still no initialiaation", panels[1].component); |
230 |
assertNull ("The lazy validation failed, still no initialiaation", panels[2].component); |
231 |
mp.failedMsg = null; |
232 |
mp.validateMsg = null; |
233 |
wd.doNextClick (); |
234 |
assertTrue ("Validation runs.", mp.running); |
235 |
while (mp.running) { |
236 |
assertFalse ("Wizard is not valid during validation.", wd.isValid ()); |
237 |
Thread.sleep (10); |
238 |
} |
239 |
assertTrue ("Wizard is valid when validation passes.", wd.isValid ()); |
240 |
assertNull ("Validation on Next passes", mp.failedMsg); |
241 |
assertNotNull ("Now we switched to another panel", panels[1].component); |
242 |
assertNull ("The lazy validation failed, still no initialiaation", panels[2].component); |
243 |
|
244 |
// remember previous state |
245 |
Object state = wd.getValue(); |
246 |
mfp.validateMsg = "xtest-fail-without-msg"; |
247 |
mfp.failedMsg = null; |
248 |
wd.doFinishClick(); |
249 |
while (mfp.running) { |
250 |
assertFalse ("Wizard is not valid during validation.", wd.isValid ()); |
251 |
Thread.sleep (10); |
252 |
} |
253 |
assertFalse ("Wizard is not valid when validation fails.", wd.isValid ()); |
254 |
assertEquals ("The lazy validation failed on Finish.", mfp.validateMsg, mfp.failedMsg); |
255 |
assertNull ("The validation failed, still no initialiaation", panels[2].component); |
256 |
assertEquals ("State has not changed", state, wd.getValue ()); |
257 |
|
258 |
mfp.validateMsg = null; |
259 |
mfp.failedMsg = null; |
260 |
wd.doFinishClick (); |
261 |
while (mfp.running) { |
262 |
assertFalse ("Wizard is not valid during validation.", wd.isValid ()); |
263 |
Thread.sleep (10); |
264 |
} |
265 |
assertTrue ("Wizard is valid when validation passes.", wd.isValid ()); |
165 |
assertNull ("Validation on Finish passes", mfp.failedMsg); |
266 |
assertNull ("Validation on Finish passes", mfp.failedMsg); |
166 |
assertNull ("Finish was clicked, no initialization either", panels[2].component); |
267 |
assertNull ("Finish was clicked, no initialization either", panels[2].component); |
167 |
assertEquals ("The state is finish", WizardDescriptor.FINISH_OPTION, wd.getValue ()); |
268 |
assertEquals ("The state is finish", WizardDescriptor.FINISH_OPTION, wd.getValue ()); |