|
@@ -1,20 +1,18 @@ |
1 |
1 |
|
// This Source Code is in the Public Domain per: http://unlicense.org |
2 |
2 |
|
package org.litesoft.GWT.forms.client.components.nonpublic; |
3 |
3 |
|
|
4 |
|
- |
import org.litesoft.commonfoundation.typeutils.*; |
5 |
|
- |
|
6 |
|
- |
import java.util.*; |
7 |
|
- |
|
8 |
4 |
|
import org.litesoft.GWT.client.*; |
9 |
5 |
|
import org.litesoft.GWT.forms.client.components.*; |
|
6 |
+ |
import org.litesoft.commonfoundation.typeutils.Objects; |
|
7 |
+ |
import org.litesoft.commonfoundation.typeutils.*; |
10 |
8 |
|
import org.litesoft.core.delayed.*; |
11 |
9 |
|
|
12 |
10 |
|
import com.google.gwt.user.client.*; |
13 |
11 |
|
import com.google.gwt.user.client.ui.*; |
14 |
|
- |
import org.litesoft.commonfoundation.typeutils.Objects; |
15 |
12 |
|
|
16 |
|
- |
public abstract class AbstractFormElement extends Composite implements IFormComponent |
17 |
|
- |
{ |
|
13 |
+ |
import java.util.*; |
|
14 |
+ |
|
|
15 |
+ |
public abstract class AbstractFormElement extends Composite implements IFormComponent { |
18 |
16 |
|
public static final String BASE_STYLE_NAME = "litesoft-FormComponent"; |
19 |
17 |
|
public static final String FORM_COMPONENT_LABEL_STYLE = "litesoft-FormComponentLabel"; |
20 |
18 |
|
public static final String FORM_COMPONENT_LABEL_LEFT_STYLE = "litesoft-FormComponentLabelLeft"; |
|
@@ -27,42 +25,36 @@ |
27 |
25 |
|
protected FormHTMLpanel mInnerHTMLpanel; // Element is either a DIV / FieldSet |
28 |
26 |
|
protected String mFieldLabel, mTooltip; |
29 |
27 |
|
|
30 |
|
- |
protected AbstractFormElement( Element pElement ) |
31 |
|
- |
{ |
|
28 |
+ |
protected AbstractFormElement( Element pElement ) { |
32 |
29 |
|
VerticalPanel zConstrainingTable = new VerticalPanel(); |
33 |
30 |
|
initWidget( zConstrainingTable ); |
34 |
31 |
|
zConstrainingTable.add( mInnerHTMLpanel = new FormHTMLpanel( pElement ) ); |
35 |
32 |
|
super.setStyleName( BASE_STYLE_NAME ); |
36 |
33 |
|
} |
37 |
34 |
|
|
38 |
|
- |
protected void initializeHTML( String pHTML ) |
39 |
|
- |
{ |
|
35 |
+ |
protected void initializeHTML( String pHTML ) { |
40 |
36 |
|
mInnerHTMLpanel.setHTML( pHTML ); |
41 |
37 |
|
} |
42 |
38 |
|
|
43 |
39 |
|
// UIObject |
44 |
40 |
|
|
45 |
41 |
|
@Override |
46 |
|
- |
public void setStyleName( String style ) |
47 |
|
- |
{ |
|
42 |
+ |
public void setStyleName( String style ) { |
48 |
43 |
|
throw new IllegalStateException( "Can not use setStyleName, use addStyleName & removeStyleName" ); |
49 |
44 |
|
} |
50 |
45 |
|
|
51 |
46 |
|
@Override |
52 |
|
- |
protected Element getStyleElement() |
53 |
|
- |
{ |
|
47 |
+ |
protected Element getStyleElement() { |
54 |
48 |
|
return mInnerHTMLpanel.getElement(); |
55 |
49 |
|
} |
56 |
50 |
|
|
57 |
51 |
|
abstract public void simulateUserTextEntry( String pText ); |
58 |
52 |
|
|
59 |
|
- |
public String getFieldLabel() |
60 |
|
- |
{ |
|
53 |
+ |
public String getFieldLabel() { |
61 |
54 |
|
return mFieldLabel; |
62 |
55 |
|
} |
63 |
56 |
|
|
64 |
|
- |
public String getTooltip() |
65 |
|
- |
{ |
|
57 |
+ |
public String getTooltip() { |
66 |
58 |
|
return mTooltip; |
67 |
59 |
|
} |
68 |
60 |
|
|
|
@@ -73,64 +65,53 @@ |
73 |
65 |
|
*/ |
74 |
66 |
|
@Override |
75 |
67 |
|
public void setTitle( String title ) |
76 |
|
- |
throws UnsupportedOperationException |
77 |
|
- |
{ |
|
68 |
+ |
throws UnsupportedOperationException { |
78 |
69 |
|
throw new UnsupportedOperationException(); |
79 |
70 |
|
} |
80 |
71 |
|
|
81 |
72 |
|
// IFormComponent |
82 |
73 |
|
|
83 |
74 |
|
@Override |
84 |
|
- |
public boolean hasError() |
85 |
|
- |
{ |
|
75 |
+ |
public boolean hasError() { |
86 |
76 |
|
return false; |
87 |
77 |
|
} |
88 |
78 |
|
|
89 |
79 |
|
@Override |
90 |
80 |
|
public void setError( String pError ) |
91 |
|
- |
throws UnsupportedOperationException |
92 |
|
- |
{ |
93 |
|
- |
if ( Strings.isNotNullOrEmpty( pError ) ) |
94 |
|
- |
{ |
|
81 |
+ |
throws UnsupportedOperationException { |
|
82 |
+ |
if ( Strings.isNotNullOrEmpty( pError ) ) { |
95 |
83 |
|
throw new UnsupportedOperationException(); |
96 |
84 |
|
} |
97 |
85 |
|
} |
98 |
86 |
|
|
99 |
87 |
|
@Override |
100 |
|
- |
public void setFocused( boolean pFocused ) |
101 |
|
- |
{ |
|
88 |
+ |
public void setFocused( boolean pFocused ) { |
102 |
89 |
|
mFocused = pFocused; |
103 |
90 |
|
stateChanged(); |
104 |
91 |
|
} |
105 |
92 |
|
|
106 |
93 |
|
@Override |
107 |
|
- |
public void setValueChanged( boolean pChanged ) |
108 |
|
- |
{ |
|
94 |
+ |
public void setValueChanged( boolean pChanged ) { |
109 |
95 |
|
mChanged = pChanged; |
110 |
96 |
|
stateChanged(); |
111 |
97 |
|
} |
112 |
98 |
|
|
113 |
99 |
|
@Override |
114 |
|
- |
public boolean isEnabled() |
115 |
|
- |
{ |
|
100 |
+ |
public boolean isEnabled() { |
116 |
101 |
|
return mEnabled; |
117 |
102 |
|
} |
118 |
103 |
|
|
119 |
104 |
|
@Override |
120 |
|
- |
public void publishAnyPendingChanges() |
121 |
|
- |
{ |
|
105 |
+ |
public void publishAnyPendingChanges() { |
122 |
106 |
|
// Do nothing as most FormElements do not do defferred processing |
123 |
|
- |
if ( mFocused ) |
124 |
|
- |
{ |
|
107 |
+ |
if ( mFocused ) { |
125 |
108 |
|
LOGGER.error.log( "AbstractFormElement.publishAnyPendingChanges: Focused - ", simpleClassname( this ) ); |
126 |
109 |
|
} |
127 |
110 |
|
} |
128 |
111 |
|
|
129 |
112 |
|
@Override |
130 |
|
- |
public IFormComponent addFormComponentListener( Listener pFormComponentListener ) |
131 |
|
- |
{ |
132 |
|
- |
if ( pFormComponentListener != null ) |
133 |
|
- |
{ |
|
113 |
+ |
public IFormComponent addFormComponentListener( Listener pFormComponentListener ) { |
|
114 |
+ |
if ( pFormComponentListener != null ) { |
134 |
115 |
|
pFormComponentListener.add( this ); |
135 |
116 |
|
mFormComponentListeners.add( pFormComponentListener ); |
136 |
117 |
|
} |
|
@@ -138,10 +119,8 @@ |
138 |
119 |
|
} |
139 |
120 |
|
|
140 |
121 |
|
@Override |
141 |
|
- |
public IFormComponent removeFormComponentListener( Listener pFormComponentListener ) |
142 |
|
- |
{ |
143 |
|
- |
if ( pFormComponentListener != null ) |
144 |
|
- |
{ |
|
122 |
+ |
public IFormComponent removeFormComponentListener( Listener pFormComponentListener ) { |
|
123 |
+ |
if ( pFormComponentListener != null ) { |
145 |
124 |
|
pFormComponentListener.remove( this ); |
146 |
125 |
|
mFormComponentListeners.remove( pFormComponentListener ); |
147 |
126 |
|
} |
|
@@ -150,121 +129,94 @@ |
150 |
129 |
|
|
151 |
130 |
|
// Support... |
152 |
131 |
|
|
153 |
|
- |
protected static String simpleClassname( Object pObject ) |
154 |
|
- |
{ |
|
132 |
+ |
protected static String simpleClassname( Object pObject ) { |
155 |
133 |
|
return Objects.justClassNameOf( pObject ); |
156 |
134 |
|
} |
157 |
135 |
|
|
158 |
|
- |
protected void fireBlurListeners() |
159 |
|
- |
{ |
|
136 |
+ |
protected void fireBlurListeners() { |
160 |
137 |
|
trace( "fireBlurListeners" ); |
161 |
|
- |
for ( Listener zListener : mFormComponentListeners ) |
162 |
|
- |
{ |
|
138 |
+ |
for ( Listener zListener : mFormComponentListeners ) { |
163 |
139 |
|
zListener.blurOccurred(); |
164 |
140 |
|
} |
165 |
141 |
|
} |
166 |
142 |
|
|
167 |
|
- |
protected void fireChangeListeners() |
168 |
|
- |
{ |
|
143 |
+ |
protected void fireChangeListeners() { |
169 |
144 |
|
trace( "fireChangeListeners" ); |
170 |
|
- |
for ( Listener zListener : mFormComponentListeners ) |
171 |
|
- |
{ |
|
145 |
+ |
for ( Listener zListener : mFormComponentListeners ) { |
172 |
146 |
|
zListener.changeOccurred(); |
173 |
147 |
|
} |
174 |
148 |
|
} |
175 |
149 |
|
|
176 |
|
- |
protected void fireFocusListeners() |
177 |
|
- |
{ |
|
150 |
+ |
protected void fireFocusListeners() { |
178 |
151 |
|
trace( "fireFocusListeners" ); |
179 |
|
- |
for ( Listener zListener : mFormComponentListeners ) |
180 |
|
- |
{ |
|
152 |
+ |
for ( Listener zListener : mFormComponentListeners ) { |
181 |
153 |
|
zListener.focusOccured(); |
182 |
154 |
|
} |
183 |
155 |
|
} |
184 |
156 |
|
|
185 |
|
- |
protected void fireEnterPressedListeners( KeyboardKeyModifier pModifiers ) |
186 |
|
- |
{ |
|
157 |
+ |
protected void fireEnterPressedListeners( KeyboardKeyModifier pModifiers ) { |
187 |
158 |
|
trace( "fireenterPressedListeners" ); |
188 |
|
- |
for ( Listener zListener : mFormComponentListeners ) |
189 |
|
- |
{ |
|
159 |
+ |
for ( Listener zListener : mFormComponentListeners ) { |
190 |
160 |
|
zListener.enterPressed( pModifiers ); |
191 |
161 |
|
} |
192 |
162 |
|
} |
193 |
163 |
|
|
194 |
|
- |
protected boolean hasFocus() |
195 |
|
- |
{ |
|
164 |
+ |
protected boolean hasFocus() { |
196 |
165 |
|
return mFocused; |
197 |
166 |
|
} |
198 |
167 |
|
|
199 |
|
- |
protected boolean hasChanged() |
200 |
|
- |
{ |
|
168 |
+ |
protected boolean hasChanged() { |
201 |
169 |
|
return mChanged; |
202 |
170 |
|
} |
203 |
171 |
|
|
204 |
|
- |
protected void stateChanged() |
205 |
|
- |
{ |
206 |
|
- |
if ( isEnabled() ) |
207 |
|
- |
{ |
|
172 |
+ |
protected void stateChanged() { |
|
173 |
+ |
if ( isEnabled() ) { |
208 |
174 |
|
setEnabledStyles(); |
209 |
|
- |
} |
210 |
|
- |
else |
211 |
|
- |
{ |
|
175 |
+ |
} else { |
212 |
176 |
|
setDisabledStyles(); |
213 |
177 |
|
} |
214 |
178 |
|
} |
215 |
179 |
|
|
216 |
|
- |
protected void setDisabledStyles() |
217 |
|
- |
{ |
|
180 |
+ |
protected void setDisabledStyles() { |
218 |
181 |
|
StringBuilder style = new StringBuilder( "-Disabled" ); |
219 |
|
- |
if ( hasError() ) |
220 |
|
- |
{ |
|
182 |
+ |
if ( hasError() ) { |
221 |
183 |
|
style.append( "-Error" ); |
222 |
184 |
|
} |
223 |
185 |
|
updateStatefulStyleName( style.toString() ); |
224 |
186 |
|
} |
225 |
187 |
|
|
226 |
|
- |
protected void setEnabledStyles() |
227 |
|
- |
{ |
|
188 |
+ |
protected void setEnabledStyles() { |
228 |
189 |
|
StringBuilder style = new StringBuilder(); |
229 |
|
- |
if ( hasFocus() ) |
230 |
|
- |
{ |
|
190 |
+ |
if ( hasFocus() ) { |
231 |
191 |
|
style.append( "-Focused" ); |
232 |
192 |
|
} |
233 |
|
- |
if ( hasError() ) |
234 |
|
- |
{ |
|
193 |
+ |
if ( hasError() ) { |
235 |
194 |
|
style.append( "-Error" ); |
236 |
195 |
|
} |
237 |
|
- |
if ( hasChanged() ) |
238 |
|
- |
{ |
|
196 |
+ |
if ( hasChanged() ) { |
239 |
197 |
|
style.append( "-Changed" ); |
240 |
198 |
|
} |
241 |
199 |
|
updateStatefulStyleName( style.toString() ); |
242 |
200 |
|
} |
243 |
201 |
|
|
244 |
|
- |
private void updateStatefulStyleName( String pNewStyleState ) |
245 |
|
- |
{ |
246 |
|
- |
if ( !pNewStyleState.equals( mCurStyleState ) ) |
247 |
|
- |
{ |
248 |
|
- |
if ( !mCurStyleState.equals( "" ) ) |
249 |
|
- |
{ |
|
202 |
+ |
private void updateStatefulStyleName( String pNewStyleState ) { |
|
203 |
+ |
if ( !pNewStyleState.equals( mCurStyleState ) ) { |
|
204 |
+ |
if ( !mCurStyleState.equals( "" ) ) { |
250 |
205 |
|
removeStyleName( BASE_STYLE_NAME + mCurStyleState ); |
251 |
206 |
|
} |
252 |
|
- |
if ( !(mCurStyleState = pNewStyleState).equals( "" ) ) |
253 |
|
- |
{ |
|
207 |
+ |
if ( !(mCurStyleState = pNewStyleState).equals( "" ) ) { |
254 |
208 |
|
addStyleName( BASE_STYLE_NAME + mCurStyleState ); |
255 |
209 |
|
} |
256 |
210 |
|
} |
257 |
211 |
|
} |
258 |
212 |
|
|
259 |
|
- |
protected static class FormHTMLpanel extends ComplexPanel |
260 |
|
- |
{ |
|
213 |
+ |
protected static class FormHTMLpanel extends ComplexPanel { |
261 |
214 |
|
/** |
262 |
215 |
|
* Creates an HTML panel with NO specified HTML contents. The element is the wrapping element. |
263 |
216 |
|
* |
264 |
217 |
|
* @param pElement either the Div or the FieldSet |
265 |
218 |
|
*/ |
266 |
|
- |
public FormHTMLpanel( Element pElement ) |
267 |
|
- |
{ |
|
219 |
+ |
public FormHTMLpanel( Element pElement ) { |
268 |
220 |
|
setElement( pElement ); |
269 |
221 |
|
} |
270 |
222 |
|
|
|
@@ -274,8 +226,7 @@ |
274 |
226 |
|
* |
275 |
227 |
|
* @param pHtml the panel's HTML |
276 |
228 |
|
*/ |
277 |
|
- |
public void setHTML( String pHtml ) |
278 |
|
- |
{ |
|
229 |
+ |
public void setHTML( String pHtml ) { |
279 |
230 |
|
DOM.setInnerHTML( getElement(), pHtml ); |
280 |
231 |
|
} |
281 |
232 |
|
|
|
@@ -286,11 +237,9 @@ |
286 |
237 |
|
* @param pWidget the widget to be added |
287 |
238 |
|
* @param pId the id of the element within which it will be contained |
288 |
239 |
|
*/ |
289 |
|
- |
public void add( Widget pWidget, String pId ) |
290 |
|
- |
{ |
|
240 |
+ |
public void add( Widget pWidget, String pId ) { |
291 |
241 |
|
Element elem = getElementById( getElement(), pId ); |
292 |
|
- |
if ( elem == null ) |
293 |
|
- |
{ |
|
242 |
+ |
if ( elem == null ) { |
294 |
243 |
|
throw new NoSuchElementException( pId ); |
295 |
244 |
|
} |
296 |
245 |
|
|
|
@@ -302,20 +251,16 @@ |
302 |
251 |
|
* this because {@link #add(Widget, String)} must often be called before the |
303 |
252 |
|
* panel is attached to the DOM, so {@link Dom#getElementById} won't yet work. |
304 |
253 |
|
*/ |
305 |
|
- |
private Element getElementById( Element pElement, String pId ) |
306 |
|
- |
{ |
|
254 |
+ |
private Element getElementById( Element pElement, String pId ) { |
307 |
255 |
|
String elemId = DOM.getElementProperty( pElement, "id" ); |
308 |
|
- |
if ( (elemId != null) && elemId.equals( pId ) ) |
309 |
|
- |
{ |
|
256 |
+ |
if ( (elemId != null) && elemId.equals( pId ) ) { |
310 |
257 |
|
return pElement; |
311 |
258 |
|
} |
312 |
259 |
|
|
313 |
260 |
|
Element child = DOM.getFirstChild( pElement ); |
314 |
|
- |
while ( child != null ) |
315 |
|
- |
{ |
|
261 |
+ |
while ( child != null ) { |
316 |
262 |
|
Element ret = getElementById( child, pId ); |
317 |
|
- |
if ( ret != null ) |
318 |
|
- |
{ |
|
263 |
+ |
if ( ret != null ) { |
319 |
264 |
|
return ret; |
320 |
265 |
|
} |
321 |
266 |
|
child = DOM.getNextSibling( child ); |
|
@@ -325,23 +270,17 @@ |
325 |
270 |
|
} |
326 |
271 |
|
} |
327 |
272 |
|
|
328 |
|
- |
protected void trace( String pMethod ) |
329 |
|
- |
{ |
330 |
|
- |
if ( LOGGER.trace.isEnabled() ) |
331 |
|
- |
{ |
|
273 |
+ |
protected void trace( String pMethod ) { |
|
274 |
+ |
if ( LOGGER.trace.isEnabled() ) { |
332 |
275 |
|
LOGGER.trace.log( pMethod + " - " + simpleClassname( this ) ); |
333 |
276 |
|
} |
334 |
277 |
|
} |
335 |
278 |
|
|
336 |
|
- |
protected void pullFocusTo( final Focusable pFocusable ) |
337 |
|
- |
{ |
338 |
|
- |
TimedRunnableManager.INSTANCE.runIn( new TimedRunnable() |
339 |
|
- |
{ |
|
279 |
+ |
protected void pullFocusTo( final Focusable pFocusable ) { |
|
280 |
+ |
TimedRunnableManager.INSTANCE.runIn( new TimedRunnable() { |
340 |
281 |
|
@Override |
341 |
|
- |
public Again runOnce() |
342 |
|
- |
{ |
343 |
|
- |
if ( !UtilsGwt.isRecursiveVisible( (Widget) pFocusable ) ) |
344 |
|
- |
{ |
|
282 |
+ |
public Again runOnce() { |
|
283 |
+ |
if ( !UtilsGwt.isRecursiveVisible( (Widget) pFocusable ) ) { |
345 |
284 |
|
return new RunAgainIn( 50 ); |
346 |
285 |
|
} |
347 |
286 |
|
pFocusable.setFocus( true ); |