litesoft
@ 947
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 |
// This Source Code is in the Public Domain per: http://unlicense.org package org.litesoft.GWT.forms.client.nonpublic; import java.io.*; import org.litesoft.GWT.forms.client.components.*; import org.litesoft.GWT.client.*; import org.litesoft.commonfoundation.typeutils.*; import org.litesoft.ui.def.nonpublic.support.*; import com.google.gwt.user.client.ui.*; public abstract class AbstractFormAttributeAdapter extends AbstractFormComponentAdapter implements FormAttributeAdapter, IFormComponent.Listener { private Integer mUniqueID; private String mAttributeReference; private IFormComponent mComponent; private String mErrorText = null; private Object mPublishedComponentValue = null; private Object mErrorComponentValue = null; private Object mBaseComponentValue = null; public AbstractFormAttributeAdapter( FormInstanceComponentHandler pComponentHandler, AttributeMetaData pMD, IFormComponent pComponent ) { super( pComponentHandler ); mUniqueID = pMD.getUniqueID(); mAttributeReference = pMD.getAttributeReference(); mComponent = pComponent; if ( pMD.isDisabled() ) { mComponent.setEnabled( false ); } } public final Widget init() { mComponent.addFormComponentListener( this ); mComponentFormHandler.addAttributeAdapter( this ); Widget widget = initWidget(); Object zComponentCurrentValue = getComponentCurrentValue(); Serializable zSendableCurrentValue = convertComponentValueToSendable( zComponentCurrentValue ); LLsetErrorText( null, zSendableCurrentValue, zComponentCurrentValue ); return widget; } public void add( IFormComponent pComponent ) { // As we already have the Component, we can ignore this call... } public void remove( IFormComponent pComponent ) { // Our Components life cycle is managed differently, we can ignore this call... } protected Widget initWidget() { return (Widget) mComponent; } // FormAttributeAdapter public Integer getUniqueID() { return mUniqueID; } public String getAttributeReference() { return mAttributeReference; } public boolean isErrorState() { return mErrorText != null; } public String getErrorText() { return mErrorText; } public void setErrorText( String pErrorText ) { Object zComponentCurrentValue = getComponentCurrentValue(); Serializable zSendableCurrentValue = convertComponentValueToSendable( zComponentCurrentValue ); setErrorTextAndPublish( pErrorText, zSendableCurrentValue, zComponentCurrentValue ); } public boolean isChangedState() { return !areEqual( mBaseComponentValue, getComponentCurrentValue() ); } public Serializable getBaseValue() { return convertComponentValueToSendable( mBaseComponentValue ); } public void setBaseValue( Serializable pBaseValue ) { mBaseComponentValue = convertSendableToComponentValue( pBaseValue ); setComponentCurrentValue( mPublishedComponentValue = mBaseComponentValue ); chkChangeOccurred( pBaseValue, mBaseComponentValue ); } public Serializable getCurrentValue() { return convertComponentValueToSendable( getComponentCurrentValue() ); } public void setCurrentValue( Serializable pCurrentValue ) { Object zComponentCurrentValue = convertSendableToComponentValue( pCurrentValue ); setComponentCurrentValue( zComponentCurrentValue ); chkChangeOccurred( pCurrentValue, zComponentCurrentValue ); } public String getUserValue() { return convertComponentValueToString( getComponentCurrentValue() ); } public void setUserValue( String pValue ) { setComponentUserValue( convertStringToComponentValue( pValue ) ); // handle change Object zComponentCurrentValue = getComponentCurrentValue(); Serializable zSendableCurrentValue = convertComponentValueToSendable( zComponentCurrentValue ); chkChangeOccurred( zSendableCurrentValue, zComponentCurrentValue ); // handle update if ( !areEqual( mPublishedComponentValue, zComponentCurrentValue ) ) { mPublishedComponentValue = zComponentCurrentValue; publishUpdatedValue( zSendableCurrentValue ); } } protected void setComponentUserValue( Object pComponentValue ) { setComponentCurrentValue( pComponentValue ); } public void publishAnyPendingChanges() { mComponent.publishAnyPendingChanges(); } public void updateValidOptions( Serializable[] pValidOptions ) { // Do nothing as most components do NOT support valid Options } // FormComponentAdapter public boolean isVisible() { return mComponent.isVisible(); } public boolean setFocus() { return mComponent.setFocus(); } protected void setWidgetEnabled( boolean pEnabled ) { mComponent.setEnabled( pEnabled ); } public boolean isEnabled() { return mComponent.isEnabled(); } // IFormComponent.Listener public void changeOccurred() { Object zComponentCurrentValue = getComponentCurrentValue(); // System.out.println( "changeOccurred: " + this + " | " + zComponentCurrentValue ); Serializable zSendableCurrentValue = convertComponentValueToSendable( zComponentCurrentValue ); chkChangeOccurred( zSendableCurrentValue, zComponentCurrentValue ); } public void blurOccurred() { // System.out.println( "blurOccurred: " + this ); mComponent.setFocused( false ); optionallyPublishUpdatedValue(); } public void focusOccured() { // System.out.println( "focusOccured: " + this ); mComponent.setFocused( true ); } // Support... protected Object getComponentCurrentValue() { return mComponent.getCurrentValue(); } protected void setComponentCurrentValue( Object pNewComponentCurrentValue ) { mComponent.setCurrentValue( pNewComponentCurrentValue ); } protected void setErrorTextAndPublish( String pErrorText, Serializable pSendableCurrentValue, Object pComponentCurrentValue ) { LLsetErrorText( pErrorText, pSendableCurrentValue, pComponentCurrentValue ); mErrorComponentValue = pComponentCurrentValue; publishErrorState( isErrorState() ); } protected void LLsetErrorText( String pErrorText, Serializable pSendableCurrentValue, Object pComponentCurrentValue ) { mComponent.setError( mErrorText = transformErrorText( pErrorText, // pSendableCurrentValue, // pComponentCurrentValue ) ); } protected String transformErrorText( String pErrorText, Serializable pSendableCurrentValue, Object pComponentCurrentValue ) { pErrorText = Strings.noEmpty( pErrorText ); if ( (pErrorText == null) && (pComponentCurrentValue instanceof FormTextInputErrorValue) ) { return ((FormTextInputErrorValue)pComponentCurrentValue).getErrorMessage(); } return pErrorText; } protected void chkChangeOccurred( Serializable pSendableCurrentValue, Object pComponentCurrentValue ) { boolean changedFromBaseCV = !areEqual( mBaseComponentValue, pComponentCurrentValue ); boolean changedFromErrorCV = !areEqual( mErrorComponentValue, pComponentCurrentValue ); if ( changedFromErrorCV ) { resetErrorOnChangeOccurred( pSendableCurrentValue, pComponentCurrentValue ); } mComponent.setValueChanged( changedFromBaseCV ); publishChangedState( changedFromBaseCV ); } protected void optionallyPublishUpdatedValue() { Object zComponentCurrentValue = getComponentCurrentValue(); Serializable zSendableCurrentValue = convertComponentValueToSendable( zComponentCurrentValue ); if ( !areEqual( mPublishedComponentValue, zComponentCurrentValue ) ) { mPublishedComponentValue = zComponentCurrentValue; publishUpdatedValue( zSendableCurrentValue ); } } protected void publishErrorState( boolean pErrorState ) { mComponentFormHandler.componentErrorState( pErrorState ); } protected void publishChangedState( boolean pChangedState ) { mComponentFormHandler.componentChangedState( pChangedState ); } protected void publishUpdatedValue( Serializable pCurrentValue ) { mComponentFormHandler.componentUpdatedValue( this, pCurrentValue ); } protected void resetErrorOnChangeOccurred( Serializable pSendableCurrentValue, Object pComponentCurrentValue ) { setErrorTextAndPublish( null, pSendableCurrentValue, pComponentCurrentValue ); // Turn off error - assume no error } protected Serializable convertComponentValueToSendable( Object pValue ) { if ( (pValue == null) || (pValue instanceof FormTextInputErrorValue) ) { return null; } return LLconvertNonNullComponentValueToSendable( pValue ); } protected Serializable LLconvertNonNullComponentValueToSendable( Object pValue ) { return (Serializable) pValue; } abstract protected Object convertSendableToComponentValue( Serializable pValue ); abstract protected String convertComponentValueToString( Object pValue ); abstract protected Object convertStringToComponentValue( String pValue ); public String toString() { return "FormAttributeAdapter(" + getAttributeReference() + ")"; } @Override public void enterPressed( KeyboardKeyModifier pModifiers ) { // todo: Implement! } } |
Commits for litesoft/trunk/Java/GWT/OldClient/src/org/litesoft/GWT/forms/client/nonpublic/AbstractFormAttributeAdapter.java
Revision | Author | Commited | Message |
---|---|---|---|
947 Diff | GeorgeS | Fri 06 Jun, 2014 23:36:56 +0000 | Correct Spelling of package! |
939 Diff | GeorgeS | Mon 02 Jun, 2014 21:30:31 +0000 | Extracting commonfoundation |
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 |