|
@@ -1,31 +1,71 @@ |
1 |
1 |
|
package com.temp.client.foundation.widget.input.fieldsupport; |
2 |
2 |
|
|
|
3 |
+ |
import com.google.gwt.event.dom.client.*; |
|
4 |
+ |
import com.google.gwt.user.client.ui.*; |
3 |
5 |
|
import com.temp.client.foundation.widget.*; |
4 |
6 |
|
import com.temp.client.foundation.widget.input.support.*; |
5 |
7 |
|
import com.temp.shared.externalization.*; |
|
8 |
+ |
import com.temp.shared.utils.*; |
6 |
9 |
|
|
|
10 |
+ |
@SuppressWarnings("deprecation") |
7 |
11 |
|
public class CompleteInputFieldAccessor<T> extends InputFieldAccessor<T> |
8 |
12 |
|
{ |
9 |
13 |
|
private final E13nResolver e13nResolver; |
10 |
|
- |
private final TextLabel labelLabel; |
11 |
|
- |
private final TextLabel extendedLabel; |
12 |
|
- |
private final TextLabel exampleLabel; |
13 |
|
- |
private final TextLabel errorLabel; |
|
14 |
+ |
private final Widget labelLabel; |
|
15 |
+ |
private final Widget extendedLabel; |
|
16 |
+ |
private final Widget exampleLabel; |
|
17 |
+ |
private final Widget errorLabel; |
14 |
18 |
|
private final HelpWidget helpWidget; |
|
19 |
+ |
private final Boolean[] focusableFocused; |
|
20 |
+ |
private final Focusable focusable; |
|
21 |
+ |
private final boolean anyFocusTracking; |
|
22 |
+ |
private FocusChangedListener focusChangedListener; |
15 |
23 |
|
|
16 |
|
- |
private boolean changed = false; |
17 |
|
- |
private boolean baseValueValid = false; |
18 |
|
- |
private T baseValue = null; |
19 |
|
- |
|
20 |
|
- |
public CompleteInputFieldAccessor( E13nResolver e13nResolver, TextLabel labelLabel, TextLabel extendedLabel, InputFieldAccessor<T> inputFieldAccessor, HelpWidget helpWidget, TextLabel exampleLabel, TextLabel errorLabel ) |
|
24 |
+ |
public CompleteInputFieldAccessor( E13nResolver e13nResolver, TextLabel labelLabel, TextLabel extendedLabel, InputFieldAccessor<T> inputFieldAccessor, HelpWidget helpWidget, TextLabel exampleLabel, TextLabel errorLabel, Focusable... additionalFocusables ) |
21 |
25 |
|
{ |
22 |
|
- |
super( inputFieldAccessor.getInput(), inputFieldAccessor.getValidator(), inputFieldAccessor.getInputWidget() ); |
|
26 |
+ |
super( inputFieldAccessor.getInput(), inputFieldAccessor.getValidator(), inputFieldAccessor.getValueAdapter(), inputFieldAccessor.getInputWidget(), append( inputFieldAccessor.getFocusables(), additionalFocusables ) ); |
23 |
27 |
|
this.e13nResolver = e13nResolver; |
24 |
28 |
|
this.labelLabel = labelLabel; |
25 |
29 |
|
this.extendedLabel = extendedLabel; |
26 |
30 |
|
this.exampleLabel = exampleLabel; |
27 |
31 |
|
this.errorLabel = errorLabel; |
28 |
32 |
|
this.helpWidget = helpWidget; |
|
33 |
+ |
focusableFocused = new Boolean[focusables.length]; |
|
34 |
+ |
Focusable firstFocusable = null; |
|
35 |
+ |
boolean anyFocusTracking = false; |
|
36 |
+ |
for ( int i = 0; i < focusables.length; i++ ) |
|
37 |
+ |
{ |
|
38 |
+ |
Focusable focusable = focusables[i]; |
|
39 |
+ |
if ( focusable != null ) |
|
40 |
+ |
{ |
|
41 |
+ |
if ( firstFocusable == null ) |
|
42 |
+ |
{ |
|
43 |
+ |
firstFocusable = focusable; |
|
44 |
+ |
} |
|
45 |
+ |
if ( registerFocusTracking( i, focusable ) ) |
|
46 |
+ |
{ |
|
47 |
+ |
focusableFocused[i] = false; // Not currently Focused! |
|
48 |
+ |
anyFocusTracking = true; |
|
49 |
+ |
} |
|
50 |
+ |
} |
|
51 |
+ |
} |
|
52 |
+ |
this.focusable = firstFocusable; |
|
53 |
+ |
this.anyFocusTracking = anyFocusTracking; |
|
54 |
+ |
} |
|
55 |
+ |
|
|
56 |
+ |
private boolean registerFocusTracking( int index, Focusable focusable ) |
|
57 |
+ |
{ |
|
58 |
+ |
if ( focusable instanceof HasAllFocusHandlers ) |
|
59 |
+ |
{ |
|
60 |
+ |
createFocusHandler( index, (HasAllFocusHandlers) focusable ); |
|
61 |
+ |
return true; |
|
62 |
+ |
} |
|
63 |
+ |
if ( focusable instanceof SourcesFocusEvents ) |
|
64 |
+ |
{ |
|
65 |
+ |
createFocusListener( index, (SourcesFocusEvents) focusable ); |
|
66 |
+ |
return true; |
|
67 |
+ |
} |
|
68 |
+ |
return false; |
29 |
69 |
|
} |
30 |
70 |
|
|
31 |
71 |
|
public E13nResolver getE13nResolver() |
|
@@ -33,22 +73,22 @@ |
33 |
73 |
|
return e13nResolver; |
34 |
74 |
|
} |
35 |
75 |
|
|
36 |
|
- |
public TextLabel getLabelLabel() |
|
76 |
+ |
public Widget getLabelLabel() |
37 |
77 |
|
{ |
38 |
78 |
|
return labelLabel; |
39 |
79 |
|
} |
40 |
80 |
|
|
41 |
|
- |
public TextLabel getExtendedLabel() |
|
81 |
+ |
public Widget getExtendedLabel() |
42 |
82 |
|
{ |
43 |
83 |
|
return extendedLabel; |
44 |
84 |
|
} |
45 |
85 |
|
|
46 |
|
- |
public TextLabel getExampleLabel() |
|
86 |
+ |
public Widget getExampleLabel() |
47 |
87 |
|
{ |
48 |
88 |
|
return exampleLabel; |
49 |
89 |
|
} |
50 |
90 |
|
|
51 |
|
- |
public TextLabel getErrorLabel() |
|
91 |
+ |
public Widget getErrorLabel() |
52 |
92 |
|
{ |
53 |
93 |
|
return errorLabel; |
54 |
94 |
|
} |
|
@@ -57,4 +97,122 @@ |
57 |
97 |
|
{ |
58 |
98 |
|
return helpWidget; |
59 |
99 |
|
} |
|
100 |
+ |
|
|
101 |
+ |
public void init( boolean enabled, FocusChangedListener focusChangedListener ) |
|
102 |
+ |
{ |
|
103 |
+ |
setEnabled( enabled ); |
|
104 |
+ |
this.focusChangedListener = focusChangedListener; |
|
105 |
+ |
} |
|
106 |
+ |
|
|
107 |
+ |
/** |
|
108 |
+ |
* Return if the Field has Focus (or null indicating that the Focus state is not tracked) |
|
109 |
+ |
*/ |
|
110 |
+ |
public Boolean isFocused() |
|
111 |
+ |
{ |
|
112 |
+ |
if ( !anyFocusTracking ) |
|
113 |
+ |
{ |
|
114 |
+ |
return null; |
|
115 |
+ |
} |
|
116 |
+ |
if ( isEnabled() ) |
|
117 |
+ |
{ |
|
118 |
+ |
for ( Boolean focused : focusableFocused ) |
|
119 |
+ |
{ |
|
120 |
+ |
if ( Boolean.TRUE.equals( focused ) ) |
|
121 |
+ |
{ |
|
122 |
+ |
return true; |
|
123 |
+ |
} |
|
124 |
+ |
} |
|
125 |
+ |
} |
|
126 |
+ |
return false; |
|
127 |
+ |
} |
|
128 |
+ |
|
|
129 |
+ |
/** |
|
130 |
+ |
* Pull the Focus to this Field (return false if the field is "thought" to be currently un-focusable, e.g. has no Focusable components or disabled) |
|
131 |
+ |
*/ |
|
132 |
+ |
public boolean setFocused() |
|
133 |
+ |
{ |
|
134 |
+ |
if ( isEnabled() && (focusable != null) ) |
|
135 |
+ |
{ |
|
136 |
+ |
focusable.setFocus( true ); |
|
137 |
+ |
// We "should" get the appropriate events... |
|
138 |
+ |
return true; |
|
139 |
+ |
} |
|
140 |
+ |
return false; |
|
141 |
+ |
} |
|
142 |
+ |
|
|
143 |
+ |
private void focusChange( int index, boolean focused ) |
|
144 |
+ |
{ |
|
145 |
+ |
if ( focusableFocused[index] != focused ) |
|
146 |
+ |
{ |
|
147 |
+ |
focusableFocused[index] = focused; |
|
148 |
+ |
if ( focusChangedListener != null ) |
|
149 |
+ |
{ |
|
150 |
+ |
focusChangedListener.focusChanged(); |
|
151 |
+ |
} |
|
152 |
+ |
} |
|
153 |
+ |
} |
|
154 |
+ |
|
|
155 |
+ |
private void createFocusListener( final int index, SourcesFocusEvents focusable ) |
|
156 |
+ |
{ |
|
157 |
+ |
focusable.addFocusListener( new FocusListener() |
|
158 |
+ |
{ |
|
159 |
+ |
@Override |
|
160 |
+ |
public void onFocus( Widget sender ) |
|
161 |
+ |
{ |
|
162 |
+ |
focusChange( index, true ); |
|
163 |
+ |
} |
|
164 |
+ |
|
|
165 |
+ |
@Override |
|
166 |
+ |
public void onLostFocus( Widget sender ) |
|
167 |
+ |
{ |
|
168 |
+ |
focusChange( index, false ); |
|
169 |
+ |
} |
|
170 |
+ |
} ); |
|
171 |
+ |
} |
|
172 |
+ |
|
|
173 |
+ |
private void createFocusHandler( int index, HasAllFocusHandlers focusable ) |
|
174 |
+ |
{ |
|
175 |
+ |
FocusBlurHandler handler = new FocusBlurHandler( index ); |
|
176 |
+ |
focusable.addFocusHandler( handler ); |
|
177 |
+ |
focusable.addBlurHandler( handler ); |
|
178 |
+ |
} |
|
179 |
+ |
|
|
180 |
+ |
private class FocusBlurHandler implements FocusHandler, |
|
181 |
+ |
BlurHandler |
|
182 |
+ |
{ |
|
183 |
+ |
private final int index; |
|
184 |
+ |
|
|
185 |
+ |
public FocusBlurHandler( int index ) |
|
186 |
+ |
{ |
|
187 |
+ |
this.index = index; |
|
188 |
+ |
} |
|
189 |
+ |
|
|
190 |
+ |
@Override |
|
191 |
+ |
public void onFocus( FocusEvent event ) |
|
192 |
+ |
{ |
|
193 |
+ |
focusChange( index, true ); |
|
194 |
+ |
} |
|
195 |
+ |
|
|
196 |
+ |
@Override |
|
197 |
+ |
public void onBlur( BlurEvent event ) |
|
198 |
+ |
{ |
|
199 |
+ |
focusChange( index, false ); |
|
200 |
+ |
} |
|
201 |
+ |
} |
|
202 |
+ |
|
|
203 |
+ |
private static Focusable[] append( Focusable[] focusables1, Focusable[] focusables2 ) |
|
204 |
+ |
{ |
|
205 |
+ |
if ( CollectionsUtils.isEmpty( focusables2 ) ) |
|
206 |
+ |
{ |
|
207 |
+ |
return focusables1; |
|
208 |
+ |
} |
|
209 |
+ |
if ( CollectionsUtils.isEmpty( focusables1 ) ) |
|
210 |
+ |
{ |
|
211 |
+ |
return focusables2; |
|
212 |
+ |
} |
|
213 |
+ |
Focusable[] merged = new Focusable[focusables1.length + focusables2.length]; |
|
214 |
+ |
System.arraycopy( focusables1, 0, merged, 0, focusables1.length ); |
|
215 |
+ |
System.arraycopy( focusables2, 0, merged, focusables1.length, focusables2.length ); |
|
216 |
+ |
return merged; |
|
217 |
+ |
} |
60 |
218 |
|
} |