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