Subversion Repository Public Repository

litesoft

Diff Revisions 949 vs 950 for /trunk/Java/GWT/OldClient/src/org/litesoft/GWT/forms/client/nonpublic/RenderedFormHandlerImpl.java

Diff revisions: vs.
  @@ -1,407 +1,408 @@
1 - // This Source Code is in the Public Domain per: http://unlicense.org
2 - package org.litesoft.GWT.forms.client.nonpublic;
3 -
4 - import org.litesoft.GWT.client.*;
5 - import org.litesoft.GWT.eventbus.client.*;
6 - import org.litesoft.GWT.forms.client.*;
7 - import org.litesoft.GWT.forms.client.components.nonpublic.*;
8 - import org.litesoft.commonfoundation.typeutils.*;
9 - import org.litesoft.core.simpletypes.*;
10 - import org.litesoft.ui.def.nonpublic.support.*;
11 -
12 - import java.io.*;
13 -
14 - public class RenderedFormHandlerImpl implements RenderedFormHandler,
15 - UberFormInstanceComponentHandler,
16 - AsyncFormServicePeerChannel.OperationalListener {
17 - private UiFormHandler mUiFormHandler;
18 - private UiFormListener mListener;
19 - private String mRootType, mRootObjectKey = null;
20 - private AsyncFormServicePeerChannel mFormServicePeerChannel;
21 - private boolean mAnyAttributesChanged = false;
22 - private boolean mAnyAttributesInError = false;
23 - private boolean mMassUpdateChanged = true;
24 - private boolean mMassUpdateInError = true;
25 - private boolean mMassUpdateStaleChanged = true;
26 - private boolean mMassUpdateStaleInError = true;
27 - private AbstractFormContainer mFormContainer = null;
28 - private RFHMessageManager mManager;
29 - private BaseFormComponentHandlerImpl mBaseComponentHandler = null;
30 -
31 - public RenderedFormHandlerImpl( UiFormHandler pUiFormHandler, UiFormListener pListener, String pRootType,
32 - AsyncFormServicePeerChannel pFormServicePeerChannel ) {
33 - mUiFormHandler = pUiFormHandler;
34 - mListener = pListener;
35 - mRootType = pRootType;
36 - mFormServicePeerChannel = pFormServicePeerChannel;
37 - mManager = new RFHMessageManager( mFormServicePeerChannel, LOGGER );
38 - }
39 -
40 - public void formRendered( AbstractFormContainer pFormContainer, Serializable pServicePeerXtra ) {
41 - chkMethodOK( "formRendered", pServicePeerXtra );
42 - mFormContainer = pFormContainer;
43 - massUpdateComplete();
44 - mListener.formRendered( mUiFormHandler, pServicePeerXtra );
45 - }
46 -
47 - private boolean isDisposed() {
48 - return (mFormServicePeerChannel == null);
49 - }
50 -
51 - private void chkMethodOK( String pMethod, String pLogData, boolean pDisabled ) {
52 - LOGGER.debug.log( pMethod, ":", pLogData, "-", pDisabled ? "Disabled" : "Enabled" );
53 - LLchkMethodOK( pMethod );
54 - }
55 -
56 - private void chkMethodOK( String pMethod, Object pLogData1, Object pLogData2 ) {
57 - LOGGER.debug.log( pMethod, ":", pLogData1, "=", pLogData2 );
58 - LLchkMethodOK( pMethod );
59 - }
60 -
61 - private void chkMethodOK( String pMethod, Object pPlusLogData ) {
62 - LOGGER.debug.log( pMethod, ":", pPlusLogData );
63 - LLchkMethodOK( pMethod );
64 - }
65 -
66 - private void chkMethodOK( String pMethod ) {
67 - LOGGER.debug.log( pMethod );
68 - LLchkMethodOK( pMethod );
69 - }
70 -
71 - private void LLchkMethodOK( String pMethod ) {
72 - if ( isDisposed() ) {
73 - throw new IllegalStateException( pMethod + " unavailable. This form has been disposed" );
74 - }
75 - }
76 -
77 - private void clearContainerErrorsAndWarnings() {
78 - LOGGER.debug.log( "clearContainerErrorsAndWarnings" );
79 - if ( mFormContainer != null ) {
80 - mFormContainer.clearErrorOrWarning();
81 - }
82 - }
83 -
84 - // RenderedFormHandler:
85 -
86 - public void requestValues( String pRootTypeKeyOrNullForNew ) {
87 - Integer zAsyncMessageNumber = mManager.getNextAsyncMessageNumber();
88 - chkMethodOK( "requestValues", zAsyncMessageNumber, pRootTypeKeyOrNullForNew );
89 - mRootObjectKey = pRootTypeKeyOrNullForNew;
90 - mManager.indicateSendForRequestValues( zAsyncMessageNumber );
91 - mFormServicePeerChannel.requestValues( zAsyncMessageNumber, pRootTypeKeyOrNullForNew );
92 - }
93 -
94 - public String getCurrentRootType() {
95 - return mRootType;
96 - }
97 -
98 - public String getCurrentRootTypeKey() {
99 - return mRootObjectKey;
100 - }
101 -
102 - public void dispose() {
103 - LOGGER.debug.log( "dispose" );
104 - if ( mFormServicePeerChannel != null ) {
105 - mFormServicePeerChannel.dispose();
106 - mFormServicePeerChannel = null;
107 - mUiFormHandler = null;
108 - mListener = null;
109 - mFormContainer = null;
110 - }
111 - if ( mManager != null ) {
112 - mManager.dispose();
113 - mManager = null;
114 - }
115 - if ( mBaseComponentHandler != null ) {
116 - mBaseComponentHandler.dispose( this );
117 - mBaseComponentHandler = null;
118 - }
119 - }
120 -
121 - public boolean setFocus() {
122 - chkMethodOK( "setFocus" );
123 - return mBaseComponentHandler.setFocus();
124 - }
125 -
126 - public void setInputDisabled( FormDataRowKey pFormDataRowKey, String pAttributeName, boolean pDisabled ) {
127 - chkMethodOK( "setInputDisabled", pAttributeName, pDisabled );
128 - mBaseComponentHandler.setInputDisabled( pFormDataRowKey, pAttributeName, pDisabled );
129 - }
130 -
131 - public void setActionDisabled( FormDataRowKey pFormDataRowKey, String pActionID, boolean pDisabled ) {
132 - chkMethodOK( "setActionDisabled", pActionID, pDisabled );
133 - mBaseComponentHandler.setActionDisabled( pFormDataRowKey, pActionID, pDisabled );
134 - }
135 -
136 - public void clearErrorsAndWarnings() {
137 - chkMethodOK( "clearErrorsAndWarnings" );
138 - clearContainerErrorsAndWarnings();
139 - }
140 -
141 - public void sendAttibuteValue( FormDataRowKey pFormDataRowKey, Integer pAttributeUniqueID,
142 - String pAttributeReference, Serializable pCurrentValue ) {
143 - chkMethodOK( "sendAttibuteValue", pAttributeReference, pCurrentValue );
144 - LLsendAttibuteValue( new ValueUpdatedFormData( pFormDataRowKey, //
145 - pAttributeUniqueID, pAttributeReference, //
146 - pCurrentValue ) );
147 - }
148 -
149 - public void sendActionRequest( FormDataRowKey pFormDataRowKey, String pActionID ) {
150 - chkMethodOK( "sendActionRequest", pActionID );
151 - LLsendActionRequest( new ActionRequestFormData( pFormDataRowKey, pActionID, false, null ) );
152 - }
153 -
154 - public void captureUserState( ParamMap pParamMap ) {
155 - chkMethodOK( "captureUserState" );
156 - mBaseComponentHandler.captureUserState( mRootType, pParamMap );
157 - }
158 -
159 - public void restoreUserState( ParamMap pParamMap ) {
160 - chkMethodOK( "restoreUserState" );
161 - mBaseComponentHandler.restoreUserState( mRootType, pParamMap );
162 - }
163 -
164 - // UberFormInstanceComponentHandler
165 -
166 - // Component Handler Management
167 -
168 - public void setBaseComponentHandler( BaseFormComponentHandlerImpl pComponentHandler ) {
169 - mBaseComponentHandler = pComponentHandler;
170 - }
171 -
172 - // Bridge to Rendered Form Button State Management
173 - public void componentErrorState( boolean pErrorState ) {
174 - LOGGER.trace.log( "componentErrorState:", pErrorState );
175 - if ( !isDisposed() && (mAnyAttributesInError != pErrorState) ) {
176 - if ( mMassUpdateInError ) {
177 - mMassUpdateStaleInError = true;
178 - } else {
179 - updateAnyAttributesInError();
180 - }
181 - }
182 - }
183 -
184 - public void componentChangedState( boolean pChangedState ) {
185 - LOGGER.trace.log( "componentChangedState:", pChangedState );
186 - if ( !isDisposed() && (mAnyAttributesChanged != pChangedState) ) {
187 - if ( mMassUpdateChanged ) {
188 - mMassUpdateStaleChanged = true;
189 - } else {
190 - updateAnyAttributesChanged();
191 - }
192 - }
193 - }
194 -
195 - // Bridge to FormServicePeer
196 - public void componentUpdatedValue( FormDataRowKey pFormDataRowKey, FormAttributeAdapter pAttributeAdapter,
197 - Serializable pCurrentValue ) {
198 - LOGGER.debug.log( "componentUpdatedValue[", pFormDataRowKey, "]:", pAttributeAdapter, "=",
199 - pCurrentValue );
200 - if ( !isDisposed() ) {
201 - LLsendAttibuteValue( new ValueUpdatedFormData( pFormDataRowKey, //
202 - pAttributeAdapter.getUniqueID(),
203 - pAttributeAdapter.getAttributeReference(),
204 - pCurrentValue ) );
205 - }
206 - }
207 -
208 - public void requestResourceKeyNameURLs( FormDataRowKey pFormDataRowKey,
209 - FormAttributeAdapter pAttributeAdapter,
210 - ResourceKeyNameURLsAvailableCallback pCallback ) {
211 - LOGGER.debug.log( "requestResourceKeyNameURLs[", pFormDataRowKey, "]:", pAttributeAdapter );
212 - if ( !isDisposed() ) {
213 - mFormServicePeerChannel.requestResources( pCallback, //
214 - new AttributeResourceOptionsRequestData( pFormDataRowKey, //
215 - pAttributeAdapter.getUniqueID(), //
216 - pAttributeAdapter.getAttributeReference() ) );
217 - }
218 - }
219 -
220 - public void actionRequested( FormDataRowKey pFormDataRowKey, FormActionAdapter pActionAdapter,
221 - boolean pInputAction, FormDataRowKey pParentFormDataRow ) {
222 - LOGGER.debug.log( "actionRequested[", pFormDataRowKey, "]:", pActionAdapter,
223 - pInputAction ? ",Input" : "" );
224 - if ( !isDisposed() && pActionAdapter.isEnabled() ) {
225 - getCollector();
226 - String actionID = pActionAdapter.getActionID();
227 - if ( mListener.formActionRequested( mUiFormHandler, actionID ) ) {
228 - sendCollector( "actionRequested" );
229 - } else {
230 - clearContainerErrorsAndWarnings();
231 - LLsendActionRequest( new ActionRequestFormData( pFormDataRowKey, actionID, pInputAction,
232 - pParentFormDataRow ) );
233 - }
234 - }
235 - }
236 -
237 - // OperationalListener:
238 -
239 - public void responseFromRequestValues( ServicePeerToFormData pFormData ) {
240 - LOGGER.debug.log( "responseFromRequestValues:", pFormData );
241 - if ( !isDisposed() ) {
242 - process( pFormData );
243 - mListener.formValuesApplied( mUiFormHandler, pFormData.getServicePeerXtra() );
244 - // an action may have been triggered programmatically on the server
245 - if ( pFormData.getSuccessfulTriggeringActionID() != null ) {
246 - mListener.formActionSucceeded( mUiFormHandler, pFormData.getSuccessfulTriggeringActionID(),
247 - pFormData.getServicePeerXtra() );
248 - }
249 - }
250 - }
251 -
252 - public void unsolicitedData( ServicePeerToFormData pFormData ) {
253 - LOGGER.debug.log( "unsolicitedData:", pFormData );
254 - if ( !isDisposed() ) {
255 - process( pFormData );
256 - if ( pFormData.getSuccessfulTriggeringActionID() != null ) {
257 - mListener.formActionSucceeded( mUiFormHandler, pFormData.getSuccessfulTriggeringActionID(),
258 - pFormData.getServicePeerXtra() );
259 - }
260 - if ( pFormData.isCloseRequested() ) {
261 - mListener.formCloseRequested( mUiFormHandler, pFormData.getServicePeerXtra() );
262 - }
263 - }
264 - }
265 -
266 - // Impl:
267 -
268 - private void LLsendAttibuteValue( ValueUpdatedFormData pValueUpdatedFormData ) {
269 - LOGGER.debug.log( "LLsendAttibuteValue:", pValueUpdatedFormData );
270 - boolean collecting = isCollecting();
271 - getCollector().add( pValueUpdatedFormData );
272 - if ( !collecting ) {
273 - sendCollector( "LLsendAttibuteValue" );
274 - }
275 - }
276 -
277 - private void LLsendActionRequest( ActionRequestFormData pActionRequest ) {
278 - LOGGER.debug.log( "LLsendActionRequest:", pActionRequest );
279 - getCollector().setActionRequest( pActionRequest );
280 -
281 - mBaseComponentHandler.publishAnyPendingAttributeChanges();
282 -
283 - sendCollector( "LLsendActionRequest" );
284 - }
285 -
286 - private void process( ServicePeerToFormData pFormData ) {
287 - if ( pFormData == null ) {
288 - System.out.println( "process null ServicePeerToFormData" );
289 - return;
290 - }
291 - receivedAsyncMessageNumber( pFormData.getAsyncMessageNumber() );
292 - if ( pFormData.getRootType() != null ) {
293 - mRootType = pFormData.getRootType();
294 - }
295 - if ( pFormData.getRootObjectKey() != null ) {
296 - mRootObjectKey = pFormData.getRootObjectKey();
297 - }
298 - setContainerErrorsAndWarnings( pFormData.getFormErrors(), pFormData.getFormWarnings() );
299 - if ( mBaseComponentHandler != null ) {
300 - mBaseComponentHandler.apply( pFormData.getActionUpdates() );
301 -
302 - RelSubFormRowKeys[] zRelSubFormRowKeysList = pFormData.getRelSubFormRowKeysList();
303 - AttributeUpdateFormData[] zAttributeUpdates = pFormData.getAttributeUpdates();
304 -
305 - if ( Objects.isNotNullOrEmpty( zRelSubFormRowKeysList ) ||
306 - Objects.isNotNullOrEmpty( zAttributeUpdates ) ) {
307 - mMassUpdateChanged = mMassUpdateInError = true;
308 - boolean zUserInitiatedAddOrRemoveRow = //
309 - "AddRow".equals( pFormData.getSuccessfulTriggeringActionID() ) || //
310 - "RemoveRow".equals( pFormData.getSuccessfulTriggeringActionID() );
311 - mBaseComponentHandler.apply( zRelSubFormRowKeysList, pFormData.isFullUpdate(),
312 - zUserInitiatedAddOrRemoveRow );
313 - mBaseComponentHandler.apply( zAttributeUpdates );
314 - massUpdateComplete();
315 - }
316 - }
317 -
318 - FormPopupMessage[] popups = pFormData.getPopups();
319 - if ( popups != null ) {
320 - for ( int i = 0; i < popups.length; i++ ) {
321 - // the title and message are used together as the key that the popup manager
322 - // will use to filter duplicate messages
323 - String combined = popups[i].getTitle() + popups[i].getMessage();
324 - if ( popups[i].isAlert() ) {
325 - AlertManager.alert( combined, popups[i].getTitle(), popups[i].getMessage() );
326 - } else {
327 - InfoManager.info( combined, popups[i].getTitle(), popups[i].getMessage() );
328 - }
329 - }
330 - }
331 - }
332 -
333 - private void updateAnyAttributesChanged() {
334 - if ( mBaseComponentHandler != null ) {
335 - boolean zAnyChanged = mBaseComponentHandler.anyUserInitiatedRowChange() ||
336 - mBaseComponentHandler.recalcAnyAttributes( FormAttributeAdapter.CHANGED );
337 - if ( zAnyChanged != mAnyAttributesChanged ) {
338 - mBaseComponentHandler.updateInputState( mAnyAttributesChanged = zAnyChanged,
339 - mAnyAttributesInError );
340 - mListener.formChangeState( mUiFormHandler, mAnyAttributesChanged );
341 - }
342 - }
343 - }
344 -
345 - private void updateAnyAttributesInError() {
346 - if ( mBaseComponentHandler != null ) {
347 - boolean zAnyInError = mBaseComponentHandler.recalcAnyAttributes( FormAttributeAdapter.ERRORED );
348 - if ( zAnyInError != mAnyAttributesInError ) {
349 - mBaseComponentHandler.updateInputState( mAnyAttributesChanged,
350 - mAnyAttributesInError = zAnyInError );
351 - mListener.formErrorState( mUiFormHandler, mAnyAttributesInError );
352 - }
353 - }
354 - }
355 -
356 - private void massUpdateComplete() {
357 - mMassUpdateChanged = false;
358 - if ( mMassUpdateStaleChanged ) {
359 - mMassUpdateStaleChanged = false;
360 - updateAnyAttributesChanged();
361 - }
362 - mMassUpdateInError = false;
363 - if ( mMassUpdateStaleInError ) {
364 - mMassUpdateStaleInError = false;
365 - updateAnyAttributesInError();
366 - }
367 - }
368 -
369 - private void setContainerErrorsAndWarnings( String[] pFormErrors, String[] pFormWarnings ) {
370 - if ( mFormContainer != null ) {
371 - String formErrors = Strings.noEmpty( Strings.linesToString( pFormErrors ) );
372 - if ( formErrors != null ) {
373 - mFormContainer.setError( formErrors );
374 - } else {
375 - String formWarnings = Strings.noEmpty( Strings.linesToString( pFormWarnings ) );
376 - if ( formWarnings != null ) {
377 - mFormContainer.setWarning( formWarnings );
378 - } else {
379 - mFormContainer.clearErrorOrWarning();
380 - }
381 - }
382 - }
383 - }
384 -
385 - private FormToServicePeerDataCollector mCollector = null;
386 -
387 - private boolean isCollecting() {
388 - return (mCollector != null);
389 - }
390 -
391 - private FormToServicePeerDataCollector getCollector() {
392 - if ( mCollector == null ) {
393 - mCollector = new FormToServicePeerDataCollector( mManager.getNextAsyncMessageNumber() );
394 - }
395 - return mCollector;
396 - }
397 -
398 - private void sendCollector( String pWho ) {
399 - FormToServicePeerDataCollector zCollector = mCollector;
400 - mCollector = null;
401 - mManager.sendCollector( pWho, zCollector );
402 - }
403 -
404 - private void receivedAsyncMessageNumber( Integer pAsyncMessageNumber ) {
405 - mManager.receivedAsyncMessageNumber( pAsyncMessageNumber );
406 - }
407 - }
1 + // This Source Code is in the Public Domain per: http://unlicense.org
2 + package org.litesoft.GWT.forms.client.nonpublic;
3 +
4 + import org.litesoft.GWT.client.*;
5 + import org.litesoft.GWT.eventbus.client.*;
6 + import org.litesoft.GWT.forms.client.*;
7 + import org.litesoft.GWT.forms.client.components.nonpublic.*;
8 + import org.litesoft.commonfoundation.base.*;
9 + import org.litesoft.commonfoundation.typeutils.*;
10 + import org.litesoft.core.simpletypes.*;
11 + import org.litesoft.ui.def.nonpublic.support.*;
12 +
13 + import java.io.*;
14 +
15 + public class RenderedFormHandlerImpl implements RenderedFormHandler,
16 + UberFormInstanceComponentHandler,
17 + AsyncFormServicePeerChannel.OperationalListener {
18 + private UiFormHandler mUiFormHandler;
19 + private UiFormListener mListener;
20 + private String mRootType, mRootObjectKey = null;
21 + private AsyncFormServicePeerChannel mFormServicePeerChannel;
22 + private boolean mAnyAttributesChanged = false;
23 + private boolean mAnyAttributesInError = false;
24 + private boolean mMassUpdateChanged = true;
25 + private boolean mMassUpdateInError = true;
26 + private boolean mMassUpdateStaleChanged = true;
27 + private boolean mMassUpdateStaleInError = true;
28 + private AbstractFormContainer mFormContainer = null;
29 + private RFHMessageManager mManager;
30 + private BaseFormComponentHandlerImpl mBaseComponentHandler = null;
31 +
32 + public RenderedFormHandlerImpl( UiFormHandler pUiFormHandler, UiFormListener pListener, String pRootType,
33 + AsyncFormServicePeerChannel pFormServicePeerChannel ) {
34 + mUiFormHandler = pUiFormHandler;
35 + mListener = pListener;
36 + mRootType = pRootType;
37 + mFormServicePeerChannel = pFormServicePeerChannel;
38 + mManager = new RFHMessageManager( mFormServicePeerChannel, LOGGER );
39 + }
40 +
41 + public void formRendered( AbstractFormContainer pFormContainer, Serializable pServicePeerXtra ) {
42 + chkMethodOK( "formRendered", pServicePeerXtra );
43 + mFormContainer = pFormContainer;
44 + massUpdateComplete();
45 + mListener.formRendered( mUiFormHandler, pServicePeerXtra );
46 + }
47 +
48 + private boolean isDisposed() {
49 + return (mFormServicePeerChannel == null);
50 + }
51 +
52 + private void chkMethodOK( String pMethod, String pLogData, boolean pDisabled ) {
53 + LOGGER.debug.log( pMethod, ":", pLogData, "-", pDisabled ? "Disabled" : "Enabled" );
54 + LLchkMethodOK( pMethod );
55 + }
56 +
57 + private void chkMethodOK( String pMethod, Object pLogData1, Object pLogData2 ) {
58 + LOGGER.debug.log( pMethod, ":", pLogData1, "=", pLogData2 );
59 + LLchkMethodOK( pMethod );
60 + }
61 +
62 + private void chkMethodOK( String pMethod, Object pPlusLogData ) {
63 + LOGGER.debug.log( pMethod, ":", pPlusLogData );
64 + LLchkMethodOK( pMethod );
65 + }
66 +
67 + private void chkMethodOK( String pMethod ) {
68 + LOGGER.debug.log( pMethod );
69 + LLchkMethodOK( pMethod );
70 + }
71 +
72 + private void LLchkMethodOK( String pMethod ) {
73 + if ( isDisposed() ) {
74 + throw new IllegalStateException( pMethod + " unavailable. This form has been disposed" );
75 + }
76 + }
77 +
78 + private void clearContainerErrorsAndWarnings() {
79 + LOGGER.debug.log( "clearContainerErrorsAndWarnings" );
80 + if ( mFormContainer != null ) {
81 + mFormContainer.clearErrorOrWarning();
82 + }
83 + }
84 +
85 + // RenderedFormHandler:
86 +
87 + public void requestValues( String pRootTypeKeyOrNullForNew ) {
88 + Integer zAsyncMessageNumber = mManager.getNextAsyncMessageNumber();
89 + chkMethodOK( "requestValues", zAsyncMessageNumber, pRootTypeKeyOrNullForNew );
90 + mRootObjectKey = pRootTypeKeyOrNullForNew;
91 + mManager.indicateSendForRequestValues( zAsyncMessageNumber );
92 + mFormServicePeerChannel.requestValues( zAsyncMessageNumber, pRootTypeKeyOrNullForNew );
93 + }
94 +
95 + public String getCurrentRootType() {
96 + return mRootType;
97 + }
98 +
99 + public String getCurrentRootTypeKey() {
100 + return mRootObjectKey;
101 + }
102 +
103 + public void dispose() {
104 + LOGGER.debug.log( "dispose" );
105 + if ( mFormServicePeerChannel != null ) {
106 + mFormServicePeerChannel.dispose();
107 + mFormServicePeerChannel = null;
108 + mUiFormHandler = null;
109 + mListener = null;
110 + mFormContainer = null;
111 + }
112 + if ( mManager != null ) {
113 + mManager.dispose();
114 + mManager = null;
115 + }
116 + if ( mBaseComponentHandler != null ) {
117 + mBaseComponentHandler.dispose( this );
118 + mBaseComponentHandler = null;
119 + }
120 + }
121 +
122 + public boolean setFocus() {
123 + chkMethodOK( "setFocus" );
124 + return mBaseComponentHandler.setFocus();
125 + }
126 +
127 + public void setInputDisabled( FormDataRowKey pFormDataRowKey, String pAttributeName, boolean pDisabled ) {
128 + chkMethodOK( "setInputDisabled", pAttributeName, pDisabled );
129 + mBaseComponentHandler.setInputDisabled( pFormDataRowKey, pAttributeName, pDisabled );
130 + }
131 +
132 + public void setActionDisabled( FormDataRowKey pFormDataRowKey, String pActionID, boolean pDisabled ) {
133 + chkMethodOK( "setActionDisabled", pActionID, pDisabled );
134 + mBaseComponentHandler.setActionDisabled( pFormDataRowKey, pActionID, pDisabled );
135 + }
136 +
137 + public void clearErrorsAndWarnings() {
138 + chkMethodOK( "clearErrorsAndWarnings" );
139 + clearContainerErrorsAndWarnings();
140 + }
141 +
142 + public void sendAttibuteValue( FormDataRowKey pFormDataRowKey, Integer pAttributeUniqueID,
143 + String pAttributeReference, Serializable pCurrentValue ) {
144 + chkMethodOK( "sendAttibuteValue", pAttributeReference, pCurrentValue );
145 + LLsendAttibuteValue( new ValueUpdatedFormData( pFormDataRowKey, //
146 + pAttributeUniqueID, pAttributeReference, //
147 + pCurrentValue ) );
148 + }
149 +
150 + public void sendActionRequest( FormDataRowKey pFormDataRowKey, String pActionID ) {
151 + chkMethodOK( "sendActionRequest", pActionID );
152 + LLsendActionRequest( new ActionRequestFormData( pFormDataRowKey, pActionID, false, null ) );
153 + }
154 +
155 + public void captureUserState( ParamMap pParamMap ) {
156 + chkMethodOK( "captureUserState" );
157 + mBaseComponentHandler.captureUserState( mRootType, pParamMap );
158 + }
159 +
160 + public void restoreUserState( ParamMap pParamMap ) {
161 + chkMethodOK( "restoreUserState" );
162 + mBaseComponentHandler.restoreUserState( mRootType, pParamMap );
163 + }
164 +
165 + // UberFormInstanceComponentHandler
166 +
167 + // Component Handler Management
168 +
169 + public void setBaseComponentHandler( BaseFormComponentHandlerImpl pComponentHandler ) {
170 + mBaseComponentHandler = pComponentHandler;
171 + }
172 +
173 + // Bridge to Rendered Form Button State Management
174 + public void componentErrorState( boolean pErrorState ) {
175 + LOGGER.trace.log( "componentErrorState:", pErrorState );
176 + if ( !isDisposed() && (mAnyAttributesInError != pErrorState) ) {
177 + if ( mMassUpdateInError ) {
178 + mMassUpdateStaleInError = true;
179 + } else {
180 + updateAnyAttributesInError();
181 + }
182 + }
183 + }
184 +
185 + public void componentChangedState( boolean pChangedState ) {
186 + LOGGER.trace.log( "componentChangedState:", pChangedState );
187 + if ( !isDisposed() && (mAnyAttributesChanged != pChangedState) ) {
188 + if ( mMassUpdateChanged ) {
189 + mMassUpdateStaleChanged = true;
190 + } else {
191 + updateAnyAttributesChanged();
192 + }
193 + }
194 + }
195 +
196 + // Bridge to FormServicePeer
197 + public void componentUpdatedValue( FormDataRowKey pFormDataRowKey, FormAttributeAdapter pAttributeAdapter,
198 + Serializable pCurrentValue ) {
199 + LOGGER.debug.log( "componentUpdatedValue[", pFormDataRowKey, "]:", pAttributeAdapter, "=",
200 + pCurrentValue );
201 + if ( !isDisposed() ) {
202 + LLsendAttibuteValue( new ValueUpdatedFormData( pFormDataRowKey, //
203 + pAttributeAdapter.getUniqueID(),
204 + pAttributeAdapter.getAttributeReference(),
205 + pCurrentValue ) );
206 + }
207 + }
208 +
209 + public void requestResourceKeyNameURLs( FormDataRowKey pFormDataRowKey,
210 + FormAttributeAdapter pAttributeAdapter,
211 + ResourceKeyNameURLsAvailableCallback pCallback ) {
212 + LOGGER.debug.log( "requestResourceKeyNameURLs[", pFormDataRowKey, "]:", pAttributeAdapter );
213 + if ( !isDisposed() ) {
214 + mFormServicePeerChannel.requestResources( pCallback, //
215 + new AttributeResourceOptionsRequestData( pFormDataRowKey, //
216 + pAttributeAdapter.getUniqueID(), //
217 + pAttributeAdapter.getAttributeReference() ) );
218 + }
219 + }
220 +
221 + public void actionRequested( FormDataRowKey pFormDataRowKey, FormActionAdapter pActionAdapter,
222 + boolean pInputAction, FormDataRowKey pParentFormDataRow ) {
223 + LOGGER.debug.log( "actionRequested[", pFormDataRowKey, "]:", pActionAdapter,
224 + pInputAction ? ",Input" : "" );
225 + if ( !isDisposed() && pActionAdapter.isEnabled() ) {
226 + getCollector();
227 + String actionID = pActionAdapter.getActionID();
228 + if ( mListener.formActionRequested( mUiFormHandler, actionID ) ) {
229 + sendCollector( "actionRequested" );
230 + } else {
231 + clearContainerErrorsAndWarnings();
232 + LLsendActionRequest( new ActionRequestFormData( pFormDataRowKey, actionID, pInputAction,
233 + pParentFormDataRow ) );
234 + }
235 + }
236 + }
237 +
238 + // OperationalListener:
239 +
240 + public void responseFromRequestValues( ServicePeerToFormData pFormData ) {
241 + LOGGER.debug.log( "responseFromRequestValues:", pFormData );
242 + if ( !isDisposed() ) {
243 + process( pFormData );
244 + mListener.formValuesApplied( mUiFormHandler, pFormData.getServicePeerXtra() );
245 + // an action may have been triggered programmatically on the server
246 + if ( pFormData.getSuccessfulTriggeringActionID() != null ) {
247 + mListener.formActionSucceeded( mUiFormHandler, pFormData.getSuccessfulTriggeringActionID(),
248 + pFormData.getServicePeerXtra() );
249 + }
250 + }
251 + }
252 +
253 + public void unsolicitedData( ServicePeerToFormData pFormData ) {
254 + LOGGER.debug.log( "unsolicitedData:", pFormData );
255 + if ( !isDisposed() ) {
256 + process( pFormData );
257 + if ( pFormData.getSuccessfulTriggeringActionID() != null ) {
258 + mListener.formActionSucceeded( mUiFormHandler, pFormData.getSuccessfulTriggeringActionID(),
259 + pFormData.getServicePeerXtra() );
260 + }
261 + if ( pFormData.isCloseRequested() ) {
262 + mListener.formCloseRequested( mUiFormHandler, pFormData.getServicePeerXtra() );
263 + }
264 + }
265 + }
266 +
267 + // Impl:
268 +
269 + private void LLsendAttibuteValue( ValueUpdatedFormData pValueUpdatedFormData ) {
270 + LOGGER.debug.log( "LLsendAttibuteValue:", pValueUpdatedFormData );
271 + boolean collecting = isCollecting();
272 + getCollector().add( pValueUpdatedFormData );
273 + if ( !collecting ) {
274 + sendCollector( "LLsendAttibuteValue" );
275 + }
276 + }
277 +
278 + private void LLsendActionRequest( ActionRequestFormData pActionRequest ) {
279 + LOGGER.debug.log( "LLsendActionRequest:", pActionRequest );
280 + getCollector().setActionRequest( pActionRequest );
281 +
282 + mBaseComponentHandler.publishAnyPendingAttributeChanges();
283 +
284 + sendCollector( "LLsendActionRequest" );
285 + }
286 +
287 + private void process( ServicePeerToFormData pFormData ) {
288 + if ( pFormData == null ) {
289 + System.out.println( "process null ServicePeerToFormData" );
290 + return;
291 + }
292 + receivedAsyncMessageNumber( pFormData.getAsyncMessageNumber() );
293 + if ( pFormData.getRootType() != null ) {
294 + mRootType = pFormData.getRootType();
295 + }
296 + if ( pFormData.getRootObjectKey() != null ) {
297 + mRootObjectKey = pFormData.getRootObjectKey();
298 + }
299 + setContainerErrorsAndWarnings( pFormData.getFormErrors(), pFormData.getFormWarnings() );
300 + if ( mBaseComponentHandler != null ) {
301 + mBaseComponentHandler.apply( pFormData.getActionUpdates() );
302 +
303 + RelSubFormRowKeys[] zRelSubFormRowKeysList = pFormData.getRelSubFormRowKeysList();
304 + AttributeUpdateFormData[] zAttributeUpdates = pFormData.getAttributeUpdates();
305 +
306 + if ( Currently.isNotNullOrEmpty( zRelSubFormRowKeysList ) ||
307 + Currently.isNotNullOrEmpty( zAttributeUpdates ) ) {
308 + mMassUpdateChanged = mMassUpdateInError = true;
309 + boolean zUserInitiatedAddOrRemoveRow = //
310 + "AddRow".equals( pFormData.getSuccessfulTriggeringActionID() ) || //
311 + "RemoveRow".equals( pFormData.getSuccessfulTriggeringActionID() );
312 + mBaseComponentHandler.apply( zRelSubFormRowKeysList, pFormData.isFullUpdate(),
313 + zUserInitiatedAddOrRemoveRow );
314 + mBaseComponentHandler.apply( zAttributeUpdates );
315 + massUpdateComplete();
316 + }
317 + }
318 +
319 + FormPopupMessage[] popups = pFormData.getPopups();
320 + if ( popups != null ) {
321 + for ( int i = 0; i < popups.length; i++ ) {
322 + // the title and message are used together as the key that the popup manager
323 + // will use to filter duplicate messages
324 + String combined = popups[i].getTitle() + popups[i].getMessage();
325 + if ( popups[i].isAlert() ) {
326 + AlertManager.alert( combined, popups[i].getTitle(), popups[i].getMessage() );
327 + } else {
328 + InfoManager.info( combined, popups[i].getTitle(), popups[i].getMessage() );
329 + }
330 + }
331 + }
332 + }
333 +
334 + private void updateAnyAttributesChanged() {
335 + if ( mBaseComponentHandler != null ) {
336 + boolean zAnyChanged = mBaseComponentHandler.anyUserInitiatedRowChange() ||
337 + mBaseComponentHandler.recalcAnyAttributes( FormAttributeAdapter.CHANGED );
338 + if ( zAnyChanged != mAnyAttributesChanged ) {
339 + mBaseComponentHandler.updateInputState( mAnyAttributesChanged = zAnyChanged,
340 + mAnyAttributesInError );
341 + mListener.formChangeState( mUiFormHandler, mAnyAttributesChanged );
342 + }
343 + }
344 + }
345 +
346 + private void updateAnyAttributesInError() {
347 + if ( mBaseComponentHandler != null ) {
348 + boolean zAnyInError = mBaseComponentHandler.recalcAnyAttributes( FormAttributeAdapter.ERRORED );
349 + if ( zAnyInError != mAnyAttributesInError ) {
350 + mBaseComponentHandler.updateInputState( mAnyAttributesChanged,
351 + mAnyAttributesInError = zAnyInError );
352 + mListener.formErrorState( mUiFormHandler, mAnyAttributesInError );
353 + }
354 + }
355 + }
356 +
357 + private void massUpdateComplete() {
358 + mMassUpdateChanged = false;
359 + if ( mMassUpdateStaleChanged ) {
360 + mMassUpdateStaleChanged = false;
361 + updateAnyAttributesChanged();
362 + }
363 + mMassUpdateInError = false;
364 + if ( mMassUpdateStaleInError ) {
365 + mMassUpdateStaleInError = false;
366 + updateAnyAttributesInError();
367 + }
368 + }
369 +
370 + private void setContainerErrorsAndWarnings( String[] pFormErrors, String[] pFormWarnings ) {
371 + if ( mFormContainer != null ) {
372 + String formErrors = ConstrainTo.significantOrNull( Strings.linesToString( pFormErrors ) );
373 + if ( formErrors != null ) {
374 + mFormContainer.setError( formErrors );
375 + } else {
376 + String formWarnings = ConstrainTo.significantOrNull( Strings.linesToString( pFormWarnings ) );
377 + if ( formWarnings != null ) {
378 + mFormContainer.setWarning( formWarnings );
379 + } else {
380 + mFormContainer.clearErrorOrWarning();
381 + }
382 + }
383 + }
384 + }
385 +
386 + private FormToServicePeerDataCollector mCollector = null;
387 +
388 + private boolean isCollecting() {
389 + return (mCollector != null);
390 + }
391 +
392 + private FormToServicePeerDataCollector getCollector() {
393 + if ( mCollector == null ) {
394 + mCollector = new FormToServicePeerDataCollector( mManager.getNextAsyncMessageNumber() );
395 + }
396 + return mCollector;
397 + }
398 +
399 + private void sendCollector( String pWho ) {
400 + FormToServicePeerDataCollector zCollector = mCollector;
401 + mCollector = null;
402 + mManager.sendCollector( pWho, zCollector );
403 + }
404 +
405 + private void receivedAsyncMessageNumber( Integer pAsyncMessageNumber ) {
406 + mManager.receivedAsyncMessageNumber( pAsyncMessageNumber );
407 + }
408 + }