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