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) { |