Subversion Repository Public Repository

litesoft

Diff Revisions 949 vs 950 for /trunk/GWT_Sandbox/FormEngine/src/com/temp/client/foundation/widget/input/fieldsupport/AbstractInputField.java

Diff revisions: vs.
  @@ -1,195 +1,195 @@
1 - package com.temp.client.foundation.widget.input.fieldsupport;
2 -
3 - import com.google.gwt.user.client.ui.*;
4 - import com.temp.client.foundation.util.*;
5 - import com.temp.client.foundation.widget.input.*;
6 - import com.temp.shared.utils.*;
7 -
8 - import java.util.*;
9 -
10 - /**
11 - * Common abstract helper for both the generated Widget and the Proxied versions of the InputField.
12 - */
13 - public abstract class AbstractInputField<T, C extends AbstractInputField<T, C>> implements InputField<T> {
14 - // Optionally set
15 - private Set<ChangeListener<T>> changeListeners = new HashSet<ChangeListener<T>>();
16 - private Set<FocusChangedListener> focusChangeListeners = new HashSet<FocusChangedListener>();
17 -
18 - protected boolean enabled = true;
19 -
20 - private State visibility = State.Visible;
21 - private StateInputField currentStyleState;
22 -
23 - @Override
24 - public final State getVisibility() {
25 - return visibility;
26 - }
27 -
28 - @Override
29 - public final void setVisibility( State visibility ) {
30 - visibility = ObjectUtils.deNull( visibility, State.Visible );
31 - Panel container = getContainer();
32 - if ( container != null ) {
33 - this.visibility = visibility;
34 - container.setVisible( visibility != State.Invisible );
35 - UtilsGwt.setHidden( container, visibility == State.Cloaked );
36 - }
37 - }
38 -
39 - // Configuration Methods
40 -
41 - @Override
42 - public final InputField<T> add( FocusChangedListener focusChangedListener ) {
43 -
44 - if ( focusChangedListener != null ) {
45 - focusChangeListeners.add( focusChangedListener );
46 - }
47 - return this;
48 - }
49 -
50 - @Override
51 - public final boolean remove( FocusChangedListener focusChangedListener ) {
52 - return (focusChangedListener == null) ? false : focusChangeListeners.remove( focusChangedListener );
53 - }
54 -
55 - @Override
56 - public final void removeAllFocusChangeListeners() {
57 - focusChangeListeners.clear();
58 - }
59 -
60 - @Override
61 - public final InputField<T> add( ChangeListener<T> changeListener ) {
62 - if ( changeListener != null ) {
63 - changeListeners.add( changeListener );
64 - }
65 - return this;
66 - }
67 -
68 - @Override
69 - public final boolean remove( ChangeListener<T> changeListener ) {
70 - return (changeListener == null) ? false : changeListeners.remove( changeListener );
71 - }
72 -
73 - @Override
74 - public final void removeAllChangeListeners() {
75 - changeListeners.clear();
76 - }
77 -
78 - abstract protected HasEnabled getEnableable();
79 -
80 - // Anytime Methods
81 -
82 - // For Enableable
83 -
84 - @Override
85 - public final boolean isEnabled() {
86 - HasEnabled enableable = getEnableable();
87 - return (enableable != null) ? enableable.isEnabled() : enabled;
88 - }
89 -
90 - @Override
91 - public final void setEnabled( boolean enable ) {
92 - enabled = enable;
93 - HasEnabled enableable = getEnableable();
94 - if ( enableable != null ) {
95 - enableable.setEnabled( enable );
96 - }
97 - }
98 -
99 - @Override
100 - public final InputField<T> enable() {
101 - setEnabled( true );
102 - return this;
103 - }
104 -
105 - @Override
106 - public final InputField<T> disable() {
107 - setEnabled( false );
108 - return this;
109 - }
110 -
111 - // For Visible
112 -
113 - @Override
114 - public final boolean isVisible() {
115 - return State.Visible == getVisibility();
116 - }
117 -
118 - @Override
119 - public final boolean isCloaked() {
120 - return State.Cloaked == getVisibility();
121 - }
122 -
123 - @Override
124 - public final boolean isInvisible() {
125 - return State.Invisible == getVisibility();
126 - }
127 -
128 - @Override
129 - public final InputField<T> visible() {
130 - setVisibility( State.Visible );
131 - return this;
132 - }
133 -
134 - @Override
135 - public final InputField<T> cloak() {
136 - setVisibility( State.Visible );
137 - return this;
138 - }
139 -
140 - @Override
141 - public final InputField<T> invisible() {
142 - setVisibility( State.Invisible );
143 - return this;
144 - }
145 -
146 - // Only callable in Run Mode
147 -
148 - protected final void updateStyle( StateInputField state ) {
149 - state = ObjectUtils.deNull( state, StateInputField.BASE );
150 - if ( state != currentStyleState ) {
151 - Panel panel = getContainer();
152 - if ( panel != null ) {
153 - if ( currentStyleState != null ) {
154 - panel.removeStyleName( currentStyleState.toCSS() );
155 - }
156 - panel.addStyleName( state.toCSS() );
157 - }
158 - currentStyleState = state;
159 - }
160 - }
161 -
162 - protected final void notifyFocusChangeListeners() {
163 - for ( FocusChangedListener zListener : focusChangeListeners ) {
164 - zListener.focusChanged();
165 - }
166 - }
167 -
168 - protected final void notifyChangeListeners() {
169 - for ( ChangeListener<T> zListener : changeListeners ) {
170 - zListener.changed( this );
171 - }
172 - }
173 -
174 - protected final void assertBuildMode( String method ) {
175 - assertMode( method, false );
176 - }
177 -
178 - protected final void assertRunMode( String method ) {
179 - assertMode( method, true );
180 - }
181 -
182 - private void assertMode( String method, boolean expectedRunMode ) {
183 - if ( isRunMode() != expectedRunMode ) {
184 - throw new IllegalStateException( "Unable to access component/method '" + method + "' of InputField Named '" + getName() + //
185 - (expectedRunMode ? "', because not in Run Mode (init NOT called)" :
186 - "', because no longer in Build Mode (init has already been called)") );
187 - }
188 - }
189 -
190 - protected final C inheritanceLeaf() {
191 - return ObjectUtils.cast( this );
192 - }
193 -
194 - abstract protected Panel getContainer();
195 - }
1 + package com.temp.client.foundation.widget.input.fieldsupport;
2 +
3 + import com.google.gwt.user.client.ui.*;
4 + import com.temp.client.foundation.util.*;
5 + import com.temp.client.foundation.widget.input.*;
6 + import com.temp.shared.utils.*;
7 +
8 + import java.util.*;
9 +
10 + /**
11 + * Common abstract helper for both the generated Widget and the Proxied versions of the InputField.
12 + */
13 + public abstract class AbstractInputField<T, C extends AbstractInputField<T, C>> implements InputField<T> {
14 + // Optionally set
15 + private Set<ChangeListener<T>> changeListeners = new HashSet<ChangeListener<T>>();
16 + private Set<FocusChangedListener> focusChangeListeners = new HashSet<FocusChangedListener>();
17 +
18 + protected boolean enabled = true;
19 +
20 + private State visibility = State.Visible;
21 + private StateInputField currentStyleState;
22 +
23 + @Override
24 + public final State getVisibility() {
25 + return visibility;
26 + }
27 +
28 + @Override
29 + public final void setVisibility( State visibility ) {
30 + visibility = ObjectUtils.deNull( visibility, State.Visible );
31 + Panel container = getContainer();
32 + if ( container != null ) {
33 + this.visibility = visibility;
34 + container.setVisible( visibility != State.Invisible );
35 + UtilsGwt.setHidden( container, visibility == State.Cloaked );
36 + }
37 + }
38 +
39 + // Configuration Methods
40 +
41 + @Override
42 + public final InputField<T> add( FocusChangedListener focusChangedListener ) {
43 +
44 + if ( focusChangedListener != null ) {
45 + focusChangeListeners.add( focusChangedListener );
46 + }
47 + return this;
48 + }
49 +
50 + @Override
51 + public final boolean remove( FocusChangedListener focusChangedListener ) {
52 + return (focusChangedListener == null) ? false : focusChangeListeners.remove( focusChangedListener );
53 + }
54 +
55 + @Override
56 + public final void removeAllFocusChangeListeners() {
57 + focusChangeListeners.clear();
58 + }
59 +
60 + @Override
61 + public final InputField<T> add( ChangeListener<T> changeListener ) {
62 + if ( changeListener != null ) {
63 + changeListeners.add( changeListener );
64 + }
65 + return this;
66 + }
67 +
68 + @Override
69 + public final boolean remove( ChangeListener<T> changeListener ) {
70 + return (changeListener == null) ? false : changeListeners.remove( changeListener );
71 + }
72 +
73 + @Override
74 + public final void removeAllChangeListeners() {
75 + changeListeners.clear();
76 + }
77 +
78 + abstract protected HasEnabled getEnableable();
79 +
80 + // Anytime Methods
81 +
82 + // For Enableable
83 +
84 + @Override
85 + public final boolean isEnabled() {
86 + HasEnabled enableable = getEnableable();
87 + return (enableable != null) ? enableable.isEnabled() : enabled;
88 + }
89 +
90 + @Override
91 + public final void setEnabled( boolean enable ) {
92 + enabled = enable;
93 + HasEnabled enableable = getEnableable();
94 + if ( enableable != null ) {
95 + enableable.setEnabled( enable );
96 + }
97 + }
98 +
99 + @Override
100 + public final InputField<T> enable() {
101 + setEnabled( true );
102 + return this;
103 + }
104 +
105 + @Override
106 + public final InputField<T> disable() {
107 + setEnabled( false );
108 + return this;
109 + }
110 +
111 + // For Visible
112 +
113 + @Override
114 + public final boolean isVisible() {
115 + return State.Visible == getVisibility();
116 + }
117 +
118 + @Override
119 + public final boolean isCloaked() {
120 + return State.Cloaked == getVisibility();
121 + }
122 +
123 + @Override
124 + public final boolean isInvisible() {
125 + return State.Invisible == getVisibility();
126 + }
127 +
128 + @Override
129 + public final InputField<T> visible() {
130 + setVisibility( State.Visible );
131 + return this;
132 + }
133 +
134 + @Override
135 + public final InputField<T> cloak() {
136 + setVisibility( State.Visible );
137 + return this;
138 + }
139 +
140 + @Override
141 + public final InputField<T> invisible() {
142 + setVisibility( State.Invisible );
143 + return this;
144 + }
145 +
146 + // Only callable in Run Mode
147 +
148 + protected final void updateStyle( StateInputField state ) {
149 + state = ObjectUtils.deNull( state, StateInputField.BASE );
150 + if ( state != currentStyleState ) {
151 + Panel panel = getContainer();
152 + if ( panel != null ) {
153 + if ( currentStyleState != null ) {
154 + panel.removeStyleName( currentStyleState.toCSS() );
155 + }
156 + panel.addStyleName( state.toCSS() );
157 + }
158 + currentStyleState = state;
159 + }
160 + }
161 +
162 + protected final void notifyFocusChangeListeners() {
163 + for ( FocusChangedListener zListener : focusChangeListeners ) {
164 + zListener.focusChanged();
165 + }
166 + }
167 +
168 + protected final void notifyChangeListeners() {
169 + for ( ChangeListener<T> zListener : changeListeners ) {
170 + zListener.changed( this );
171 + }
172 + }
173 +
174 + protected final void assertBuildMode( String method ) {
175 + assertMode( method, false );
176 + }
177 +
178 + protected final void assertRunMode( String method ) {
179 + assertMode( method, true );
180 + }
181 +
182 + private void assertMode( String method, boolean expectedRunMode ) {
183 + if ( isRunMode() != expectedRunMode ) {
184 + throw new IllegalStateException( "Unable to access component/method '" + method + "' of InputField Named '" + getName() + //
185 + (expectedRunMode ? "', because not in Run Mode (init NOT called)" :
186 + "', because no longer in Build Mode (init has already been called)") );
187 + }
188 + }
189 +
190 + protected final C inheritanceLeaf() {
191 + return ObjectUtils.cast( this );
192 + }
193 +
194 + abstract protected Panel getContainer();
195 + }