|
@@ -1,19 +1,13 @@ |
1 |
1 |
|
package com.temp.client.foundation.widget.input; |
2 |
2 |
|
|
3 |
|
- |
import com.google.gwt.user.client.ui.HasEnabled; |
4 |
|
- |
import com.google.gwt.user.client.ui.Panel; |
5 |
|
- |
import com.temp.client.foundation.widget.NameToID; |
6 |
|
- |
import com.temp.client.foundation.widget.input.fieldsupport.AbstractInputField; |
7 |
|
- |
import com.temp.client.foundation.widget.input.fieldsupport.FocusChangedListener; |
8 |
|
- |
import com.temp.client.foundation.widget.input.fieldsupport.StateInputField; |
9 |
|
- |
import org.litesoft.core.util.externalization.E13nData; |
10 |
|
- |
import org.litesoft.core.util.externalization.E13nResolver; |
11 |
|
- |
import org.litesoft.core.util.externalization.OptionallyPrefixingE13nResolver; |
12 |
|
- |
import com.temp.shared.utils.ObjectUtils; |
13 |
|
- |
import com.temp.shared.utils.StringUtils; |
|
3 |
+ |
import org.litesoft.core.util.externalization.*; |
14 |
4 |
|
|
15 |
|
- |
import java.util.ArrayList; |
16 |
|
- |
import java.util.List; |
|
5 |
+ |
import com.google.gwt.user.client.ui.*; |
|
6 |
+ |
import com.temp.client.foundation.widget.*; |
|
7 |
+ |
import com.temp.client.foundation.widget.input.fieldsupport.*; |
|
8 |
+ |
import com.temp.shared.utils.*; |
|
9 |
+ |
|
|
10 |
+ |
import java.util.*; |
17 |
11 |
|
|
18 |
12 |
|
/** |
19 |
13 |
|
* This is not a "real" Widget backed InputField, but a Proxy to a number of RadioButtonInputFields |
|
@@ -25,24 +19,24 @@ |
25 |
19 |
|
|
26 |
20 |
|
private E13nResolver resolver = null; |
27 |
21 |
|
|
28 |
|
- |
public RadioButtonGroupInputField(Panel container, // |
29 |
|
- |
RadioButtonInputField radioButton1, // |
30 |
|
- |
RadioButtonInputField radioButton2, // |
31 |
|
- |
RadioButtonInputField... additionalRadioButtons) { |
|
22 |
+ |
public RadioButtonGroupInputField( Panel container, // |
|
23 |
+ |
RadioButtonInputField radioButton1, // |
|
24 |
+ |
RadioButtonInputField radioButton2, // |
|
25 |
+ |
RadioButtonInputField... additionalRadioButtons ) { |
32 |
26 |
|
this.container = container; |
33 |
|
- |
fieldAccessor = new FieldAccessor(radioButton1, radioButton2, additionalRadioButtons, // |
34 |
|
- |
new ChangeListener<Boolean>() { |
35 |
|
- |
@Override |
36 |
|
- |
public void changed(InputField<Boolean> radioButton) { |
37 |
|
- |
processDataChanged(); |
38 |
|
- |
} |
39 |
|
- |
}, // |
40 |
|
- |
new FocusChangedListener() { |
41 |
|
- |
@Override |
42 |
|
- |
public void focusChanged() { |
43 |
|
- |
processFocusChanged(); |
44 |
|
- |
} |
45 |
|
- |
} // |
|
27 |
+ |
fieldAccessor = new FieldAccessor( radioButton1, radioButton2, additionalRadioButtons, // |
|
28 |
+ |
new ChangeListener<Boolean>() { |
|
29 |
+ |
@Override |
|
30 |
+ |
public void changed( InputField<Boolean> radioButton ) { |
|
31 |
+ |
processDataChanged(); |
|
32 |
+ |
} |
|
33 |
+ |
}, // |
|
34 |
+ |
new FocusChangedListener() { |
|
35 |
+ |
@Override |
|
36 |
+ |
public void focusChanged() { |
|
37 |
+ |
processFocusChanged(); |
|
38 |
+ |
} |
|
39 |
+ |
} // |
46 |
40 |
|
); |
47 |
41 |
|
} |
48 |
42 |
|
|
|
@@ -62,14 +56,14 @@ |
62 |
56 |
|
} |
63 |
57 |
|
|
64 |
58 |
|
@Override |
65 |
|
- |
public void setName(String name) { |
66 |
|
- |
throw new IllegalStateException("Name Not Settable, Determined automatically"); |
|
59 |
+ |
public void setName( String name ) { |
|
60 |
+ |
throw new IllegalStateException( "Name Not Settable, Determined automatically" ); |
67 |
61 |
|
} |
68 |
62 |
|
|
69 |
63 |
|
@Override |
70 |
|
- |
public void init(E13nResolver parentResolver) { |
71 |
|
- |
resolver = new OptionallyPrefixingE13nResolver(getName(), parentResolver); |
72 |
|
- |
fieldAccessor.init(resolver); |
|
64 |
+ |
public void init( E13nResolver parentResolver ) { |
|
65 |
+ |
resolver = new OptionallyPrefixingE13nResolver( getName(), parentResolver ); |
|
66 |
+ |
fieldAccessor.init( resolver ); |
73 |
67 |
|
} |
74 |
68 |
|
|
75 |
69 |
|
@Override |
|
@@ -81,100 +75,100 @@ |
81 |
75 |
|
|
82 |
76 |
|
@Override |
83 |
77 |
|
public final void reset() { |
84 |
|
- |
checkRunMode("reset").setValue(null); |
|
78 |
+ |
checkRunMode( "reset" ).setValue( null ); |
85 |
79 |
|
} |
86 |
80 |
|
|
87 |
81 |
|
@Override |
88 |
|
- |
public final String setCurrentValue(String value) { |
89 |
|
- |
assertRunMode("setCurrentValue"); |
90 |
|
- |
fieldAccessor.setValue(value); |
|
82 |
+ |
public final String setCurrentValue( String value ) { |
|
83 |
+ |
assertRunMode( "setCurrentValue" ); |
|
84 |
+ |
fieldAccessor.setValue( value ); |
91 |
85 |
|
return fieldAccessor.getValue(); |
92 |
86 |
|
} |
93 |
87 |
|
|
94 |
88 |
|
@Override |
95 |
89 |
|
public final String getCurrentValue() { |
96 |
|
- |
return checkRunMode("getCurrentValue").getValue(); |
|
90 |
+ |
return checkRunMode( "getCurrentValue" ).getValue(); |
97 |
91 |
|
} |
98 |
92 |
|
|
99 |
93 |
|
@Override |
100 |
94 |
|
public final String getBaseValue() { |
101 |
|
- |
return checkRunMode("getBaseValue").getBaseValue(); |
|
95 |
+ |
return checkRunMode( "getBaseValue" ).getBaseValue(); |
102 |
96 |
|
} |
103 |
97 |
|
|
104 |
98 |
|
@Override |
105 |
99 |
|
public final void revert() { |
106 |
|
- |
assertRunMode("revert"); |
107 |
|
- |
fieldAccessor.setValue(fieldAccessor.getBaseValue()); |
|
100 |
+ |
assertRunMode( "revert" ); |
|
101 |
+ |
fieldAccessor.setValue( fieldAccessor.getBaseValue() ); |
108 |
102 |
|
} |
109 |
103 |
|
|
110 |
104 |
|
@Override |
111 |
105 |
|
public final boolean isChanged() { |
112 |
|
- |
return checkRunMode("isChanged").isChanged(); |
|
106 |
+ |
return checkRunMode( "isChanged" ).isChanged(); |
113 |
107 |
|
} |
114 |
108 |
|
|
115 |
109 |
|
@Override |
116 |
110 |
|
public final Boolean isFocused() { |
117 |
|
- |
assertRunMode("isFocused"); |
|
111 |
+ |
assertRunMode( "isFocused" ); |
118 |
112 |
|
Boolean focused = fieldAccessor.isFocused(); |
119 |
|
- |
return Boolean.TRUE.equals(focused) ? isVisible() : focused; |
|
113 |
+ |
return Boolean.TRUE.equals( focused ) ? isVisible() : focused; |
120 |
114 |
|
} |
121 |
115 |
|
|
122 |
116 |
|
@Override |
123 |
117 |
|
public final boolean isErrored() { |
124 |
|
- |
assertRunMode("isErrored"); |
|
118 |
+ |
assertRunMode( "isErrored" ); |
125 |
119 |
|
return false; |
126 |
120 |
|
} |
127 |
121 |
|
|
128 |
122 |
|
@Override |
129 |
123 |
|
public final E13nData getErrorData() { |
130 |
|
- |
assertRunMode("getErrorData"); |
|
124 |
+ |
assertRunMode( "getErrorData" ); |
131 |
125 |
|
return null; |
132 |
126 |
|
} |
133 |
127 |
|
|
134 |
128 |
|
@Override |
135 |
129 |
|
public final boolean validate() { |
136 |
|
- |
assertRunMode("validate"); |
137 |
|
- |
updateStyle(fieldAccessor); |
|
130 |
+ |
assertRunMode( "validate" ); |
|
131 |
+ |
updateStyle( fieldAccessor ); |
138 |
132 |
|
return true; |
139 |
133 |
|
} |
140 |
134 |
|
|
141 |
135 |
|
@Override |
142 |
136 |
|
public final boolean setFocused() { |
143 |
|
- |
assertRunMode("setFocused"); |
|
137 |
+ |
assertRunMode( "setFocused" ); |
144 |
138 |
|
return isVisible() && fieldAccessor.setFocused(); |
145 |
139 |
|
} |
146 |
140 |
|
|
147 |
141 |
|
@Override |
148 |
142 |
|
public final E13nResolver getE13nResolver() { |
149 |
|
- |
assertRunMode("E13nResolver"); |
|
143 |
+ |
assertRunMode( "E13nResolver" ); |
150 |
144 |
|
return resolver; |
151 |
145 |
|
} |
152 |
146 |
|
|
153 |
147 |
|
@Override |
154 |
|
- |
public NameToID addNamedWidgetsTo(NameToID nameToID) { |
155 |
|
- |
return checkRunMode("addNamedWidgetsTo").addNamedWidgetsTo(nameToID); |
|
148 |
+ |
public NameToID addNamedWidgetsTo( NameToID nameToID ) { |
|
149 |
+ |
return checkRunMode( "addNamedWidgetsTo" ).addNamedWidgetsTo( nameToID ); |
156 |
150 |
|
} |
157 |
151 |
|
|
158 |
152 |
|
// Support Methods... |
159 |
153 |
|
|
160 |
154 |
|
protected void processDataChanged() { |
161 |
|
- |
updateStyle(checkRunMode("processDataChanged")); |
|
155 |
+ |
updateStyle( checkRunMode( "processDataChanged" ) ); |
162 |
156 |
|
notifyChangeListeners(); |
163 |
157 |
|
} |
164 |
158 |
|
|
165 |
159 |
|
protected void processFocusChanged() { |
166 |
|
- |
updateStyle(checkRunMode("processFocusChanged")); |
|
160 |
+ |
updateStyle( checkRunMode( "processFocusChanged" ) ); |
167 |
161 |
|
notifyFocusChangeListeners(); |
168 |
162 |
|
} |
169 |
163 |
|
|
170 |
|
- |
protected void updateStyle(FieldAccessor fieldAccessor) { |
171 |
|
- |
updateStyle(StateInputField.BASE // |
172 |
|
- |
.focused(Boolean.TRUE.equals(fieldAccessor.isFocused())) // |
173 |
|
- |
.changed(fieldAccessor.isChanged())); |
|
164 |
+ |
protected void updateStyle( FieldAccessor fieldAccessor ) { |
|
165 |
+ |
updateStyle( StateInputField.BASE // |
|
166 |
+ |
.focused( Boolean.TRUE.equals( fieldAccessor.isFocused() ) ) // |
|
167 |
+ |
.changed( fieldAccessor.isChanged() ) ); |
174 |
168 |
|
} |
175 |
169 |
|
|
176 |
|
- |
protected final FieldAccessor checkRunMode(String method) { |
177 |
|
- |
assertRunMode(method); |
|
170 |
+ |
protected final FieldAccessor checkRunMode( String method ) { |
|
171 |
+ |
assertRunMode( method ); |
178 |
172 |
|
return fieldAccessor; |
179 |
173 |
|
} |
180 |
174 |
|
|
|
@@ -184,56 +178,56 @@ |
184 |
178 |
|
private RadioButtonInputField nullValue; |
185 |
179 |
|
private RadioButtonInputField baseValue; |
186 |
180 |
|
|
187 |
|
- |
public FieldAccessor(RadioButtonInputField radioButton1, // |
188 |
|
- |
RadioButtonInputField radioButton2, // |
189 |
|
- |
RadioButtonInputField[] additionalRadioButtons, // |
190 |
|
- |
ChangeListener<Boolean> changeListener, |
191 |
|
- |
FocusChangedListener focusChangedListener) { |
192 |
|
- |
|
193 |
|
- |
groupName = getGroup(radioButton1); |
194 |
|
- |
|
195 |
|
- |
add(radioButton1, changeListener, focusChangedListener); |
196 |
|
- |
add(radioButton2, changeListener, focusChangedListener); |
197 |
|
- |
if (additionalRadioButtons != null) { |
198 |
|
- |
for (RadioButtonInputField radioButton : additionalRadioButtons) { |
199 |
|
- |
add(radioButton, changeListener, focusChangedListener); |
|
181 |
+ |
public FieldAccessor( RadioButtonInputField radioButton1, // |
|
182 |
+ |
RadioButtonInputField radioButton2, // |
|
183 |
+ |
RadioButtonInputField[] additionalRadioButtons, // |
|
184 |
+ |
ChangeListener<Boolean> changeListener, |
|
185 |
+ |
FocusChangedListener focusChangedListener ) { |
|
186 |
+ |
|
|
187 |
+ |
groupName = getGroup( radioButton1 ); |
|
188 |
+ |
|
|
189 |
+ |
add( radioButton1, changeListener, focusChangedListener ); |
|
190 |
+ |
add( radioButton2, changeListener, focusChangedListener ); |
|
191 |
+ |
if ( additionalRadioButtons != null ) { |
|
192 |
+ |
for ( RadioButtonInputField radioButton : additionalRadioButtons ) { |
|
193 |
+ |
add( radioButton, changeListener, focusChangedListener ); |
200 |
194 |
|
} |
201 |
195 |
|
} |
202 |
196 |
|
} |
203 |
197 |
|
|
204 |
|
- |
private static String getGroup(RadioButtonInputField radioButton) { |
205 |
|
- |
String groupName = StringUtils.noEmpty(radioButton.getGroup()); |
206 |
|
- |
if (groupName != null) { |
|
198 |
+ |
private static String getGroup( RadioButtonInputField radioButton ) { |
|
199 |
+ |
String groupName = StringUtils.noEmpty( radioButton.getGroup() ); |
|
200 |
+ |
if ( groupName != null ) { |
207 |
201 |
|
return groupName; |
208 |
202 |
|
} |
209 |
|
- |
throw new IllegalStateException("RadioButton named '" + radioButton.getName() + "', had No Group (name)"); |
|
203 |
+ |
throw new IllegalStateException( "RadioButton named '" + radioButton.getName() + "', had No Group (name)" ); |
210 |
204 |
|
} |
211 |
205 |
|
|
212 |
|
- |
private void add(RadioButtonInputField radioButton, ChangeListener<Boolean> changeListener, FocusChangedListener focusChangedListener) { |
213 |
|
- |
String group = getGroup(radioButton); |
214 |
|
- |
if (!groupName.equals(group)) { |
215 |
|
- |
throw new IllegalArgumentException("RadioButton named '" + radioButton.getName() + "', " + // |
216 |
|
- |
"Group (name) mismatch, expected '" + groupName + "', but got '" + group + "'"); |
|
206 |
+ |
private void add( RadioButtonInputField radioButton, ChangeListener<Boolean> changeListener, FocusChangedListener focusChangedListener ) { |
|
207 |
+ |
String group = getGroup( radioButton ); |
|
208 |
+ |
if ( !groupName.equals( group ) ) { |
|
209 |
+ |
throw new IllegalArgumentException( "RadioButton named '" + radioButton.getName() + "', " + // |
|
210 |
+ |
"Group (name) mismatch, expected '" + groupName + "', but got '" + group + "'" ); |
217 |
211 |
|
} |
218 |
|
- |
radioButtons.add(radioButton); |
219 |
|
- |
radioButton.add(changeListener); |
220 |
|
- |
radioButton.add(focusChangedListener); |
|
212 |
+ |
radioButtons.add( radioButton ); |
|
213 |
+ |
radioButton.add( changeListener ); |
|
214 |
+ |
radioButton.add( focusChangedListener ); |
221 |
215 |
|
} |
222 |
216 |
|
|
223 |
|
- |
public void init(E13nResolver resolver) { |
224 |
|
- |
for (RadioButtonInputField radioButton : radioButtons) { |
225 |
|
- |
radioButton.init(resolver); |
226 |
|
- |
if (Boolean.TRUE.equals(radioButton.getCurrentValue())) { |
227 |
|
- |
if (nullValue == null) { |
|
217 |
+ |
public void init( E13nResolver resolver ) { |
|
218 |
+ |
for ( RadioButtonInputField radioButton : radioButtons ) { |
|
219 |
+ |
radioButton.init( resolver ); |
|
220 |
+ |
if ( Boolean.TRUE.equals( radioButton.getCurrentValue() ) ) { |
|
221 |
+ |
if ( nullValue == null ) { |
228 |
222 |
|
nullValue = radioButton; |
229 |
223 |
|
} else { |
230 |
|
- |
radioButton.setCurrentValue(false); |
|
224 |
+ |
radioButton.setCurrentValue( false ); |
231 |
225 |
|
} |
232 |
226 |
|
} |
233 |
227 |
|
} |
234 |
|
- |
if (nullValue == null) { |
235 |
|
- |
nullValue = radioButtons.get(0); |
236 |
|
- |
nullValue.setCurrentValue(true); |
|
228 |
+ |
if ( nullValue == null ) { |
|
229 |
+ |
nullValue = radioButtons.get( 0 ); |
|
230 |
+ |
nullValue.setCurrentValue( true ); |
237 |
231 |
|
} |
238 |
232 |
|
baseValue = nullValue; |
239 |
233 |
|
} |
|
@@ -250,24 +244,24 @@ |
250 |
244 |
|
return findSelected().getName(); |
251 |
245 |
|
} |
252 |
246 |
|
|
253 |
|
- |
public void setValue(String radioButtonName) { |
254 |
|
- |
baseValue = ObjectUtils.deNull(findByName(radioButtonName), nullValue); |
255 |
|
- |
baseValue.setCurrentValue(true); |
|
247 |
+ |
public void setValue( String radioButtonName ) { |
|
248 |
+ |
baseValue = ObjectUtils.deNull( findByName( radioButtonName ), nullValue ); |
|
249 |
+ |
baseValue.setCurrentValue( true ); |
256 |
250 |
|
} |
257 |
251 |
|
|
258 |
252 |
|
private RadioButtonInputField findSelected() { |
259 |
|
- |
for (RadioButtonInputField radioButton : radioButtons) { |
260 |
|
- |
if (Boolean.TRUE.equals(radioButton.getCurrentValue())) { |
|
253 |
+ |
for ( RadioButtonInputField radioButton : radioButtons ) { |
|
254 |
+ |
if ( Boolean.TRUE.equals( radioButton.getCurrentValue() ) ) { |
261 |
255 |
|
return radioButton; |
262 |
256 |
|
} |
263 |
257 |
|
} |
264 |
|
- |
nullValue.setCurrentValue(true); |
|
258 |
+ |
nullValue.setCurrentValue( true ); |
265 |
259 |
|
return nullValue; |
266 |
260 |
|
} |
267 |
261 |
|
|
268 |
|
- |
private RadioButtonInputField findByName(String radioButtonName) { |
269 |
|
- |
for (RadioButtonInputField radioButton : radioButtons) { |
270 |
|
- |
if (radioButton.getName().equals(radioButtonName)) { |
|
262 |
+ |
private RadioButtonInputField findByName( String radioButtonName ) { |
|
263 |
+ |
for ( RadioButtonInputField radioButton : radioButtons ) { |
|
264 |
+ |
if ( radioButton.getName().equals( radioButtonName ) ) { |
271 |
265 |
|
return radioButton; |
272 |
266 |
|
} |
273 |
267 |
|
} |
|
@@ -276,11 +270,11 @@ |
276 |
270 |
|
|
277 |
271 |
|
public Boolean isFocused() { |
278 |
272 |
|
boolean anyUnableToDetermineFocus = false; |
279 |
|
- |
for (RadioButtonInputField radioButton : radioButtons) { |
|
273 |
+ |
for ( RadioButtonInputField radioButton : radioButtons ) { |
280 |
274 |
|
Boolean focused = radioButton.isFocused(); |
281 |
|
- |
if (focused == null) { |
|
275 |
+ |
if ( focused == null ) { |
282 |
276 |
|
anyUnableToDetermineFocus = true; |
283 |
|
- |
} else if (focused) { |
|
277 |
+ |
} else if ( focused ) { |
284 |
278 |
|
return true; |
285 |
279 |
|
} |
286 |
280 |
|
} |
|
@@ -288,23 +282,23 @@ |
288 |
282 |
|
} |
289 |
283 |
|
|
290 |
284 |
|
public boolean setFocused() { |
291 |
|
- |
for (RadioButtonInputField radioButton : radioButtons) { |
|
285 |
+ |
for ( RadioButtonInputField radioButton : radioButtons ) { |
292 |
286 |
|
Boolean focused = radioButton.isFocused(); |
293 |
|
- |
if (Boolean.TRUE.equals(focused)) { |
|
287 |
+ |
if ( Boolean.TRUE.equals( focused ) ) { |
294 |
288 |
|
return true; |
295 |
289 |
|
} |
296 |
290 |
|
} |
297 |
|
- |
for (RadioButtonInputField radioButton : radioButtons) { |
298 |
|
- |
if (radioButton.setFocused()) { |
|
291 |
+ |
for ( RadioButtonInputField radioButton : radioButtons ) { |
|
292 |
+ |
if ( radioButton.setFocused() ) { |
299 |
293 |
|
return true; |
300 |
294 |
|
} |
301 |
295 |
|
} |
302 |
296 |
|
return false; |
303 |
297 |
|
} |
304 |
298 |
|
|
305 |
|
- |
public NameToID addNamedWidgetsTo(NameToID nameToID) { |
306 |
|
- |
for (RadioButtonInputField radioButton : radioButtons) { |
307 |
|
- |
radioButton.addNamedWidgetsTo(nameToID); |
|
299 |
+ |
public NameToID addNamedWidgetsTo( NameToID nameToID ) { |
|
300 |
+ |
for ( RadioButtonInputField radioButton : radioButtons ) { |
|
301 |
+ |
radioButton.addNamedWidgetsTo( nameToID ); |
308 |
302 |
|
} |
309 |
303 |
|
return nameToID; |
310 |
304 |
|
} |
|
@@ -312,8 +306,8 @@ |
312 |
306 |
|
@Override |
313 |
307 |
|
public boolean isEnabled() { |
314 |
308 |
|
int enabled = 0; |
315 |
|
- |
for (RadioButtonInputField radioButton : radioButtons) { |
316 |
|
- |
if (radioButton.isEnabled()) { |
|
309 |
+ |
for ( RadioButtonInputField radioButton : radioButtons ) { |
|
310 |
+ |
if ( radioButton.isEnabled() ) { |
317 |
311 |
|
enabled++; |
318 |
312 |
|
} |
319 |
313 |
|
} |
|
@@ -321,9 +315,9 @@ |
321 |
315 |
|
} |
322 |
316 |
|
|
323 |
317 |
|
@Override |
324 |
|
- |
public void setEnabled(boolean enabled) { |
325 |
|
- |
for (RadioButtonInputField radioButton : radioButtons) { |
326 |
|
- |
radioButton.setEnabled(enabled); |
|
318 |
+ |
public void setEnabled( boolean enabled ) { |
|
319 |
+ |
for ( RadioButtonInputField radioButton : radioButtons ) { |
|
320 |
+ |
radioButton.setEnabled( enabled ); |
327 |
321 |
|
} |
328 |
322 |
|
} |
329 |
323 |
|
} |