litesoft
@ 950
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 |
// This Source Code is in the Public Domain per: http://unlicense.org package org.litesoft.GWT.forms.client.nonpublic; import org.litesoft.GWT.eventbus.client.*; import org.litesoft.commonfoundation.base.*; import org.litesoft.core.simpletypes.*; import org.litesoft.ui.def.nonpublic.support.*; import java.util.*; public class AttributeAdapterManager { private FormAttributeAdapter[] mAttributeAdapters = FormAttributeAdapter.EMPTY_ARRAY; private Map mAttributeAdaptersByUniqueID = new HashMap(); private FormAttributeAdapter[] getAll() { return mAttributeAdapters; } public void dispose() { mAttributeAdapters = FormAttributeAdapter.EMPTY_ARRAY; mAttributeAdaptersByUniqueID.clear(); } public FormAttributeAdapter get( Integer pUniqueID ) { return (FormAttributeAdapter) mAttributeAdaptersByUniqueID.get( pUniqueID ); } public void add( FormAttributeAdapter pAttributeAdapter ) { mAttributeAdaptersByUniqueID.put( pAttributeAdapter.getUniqueID(), pAttributeAdapter ); mAttributeAdapters = FormAttributeAdapter.Helper.append( mAttributeAdapters, pAttributeAdapter ); } public void apply( FormDataRowKey pFormDataRowKey, AttributeUpdateFormData[] pAttributeUpdatesNonNullOrEmpty ) { for ( int i = 0; i < pAttributeUpdatesNonNullOrEmpty.length; i++ ) { AttributeUpdateFormData update = pAttributeUpdatesNonNullOrEmpty[i]; if ( Currently.areEqual( pFormDataRowKey, update.getFormDataRowKey() ) ) { apply( update ); } } } private void apply( AttributeUpdateFormData pUpdate ) { // todo: need to add a FormAttributeAdapter for the Tab Label FormAttributeAdapter adapter = get( pUpdate.getUniqueID() ); if ( adapter == null ) { System.out.println( "update '" + pUpdate + "', but no AttributeAdapter" ); return; } if ( pUpdate.hasValue() ) { adapter.setBaseValue( pUpdate.getValue() ); } if ( pUpdate.getDisable() != null ) { adapter.setDisabled( pUpdate.getDisable().booleanValue() ); } adapter.setErrorText( ConstrainTo.significantOrNull( pUpdate.getErrorText() ) ); if ( pUpdate instanceof ComboBoxAttributeUpdateFormData ) { SimpleKeyValuePair[] newValidOptions = ((ComboBoxAttributeUpdateFormData) pUpdate).getValidOptions(); if ( Currently.isNullOrEmpty( newValidOptions ) ) { System.out.println( "update '" + pUpdate + "', but no ValidOptions" ); } else { adapter.updateValidOptions( newValidOptions ); } } } public boolean recalcAnyAttributes( FormAttributeAdapter.BooleanValueAccessor pValueAccessor ) { FormAttributeAdapter[] adapters = getAll(); for ( int i = 0; i < adapters.length; i++ ) { if ( pValueAccessor.isBooleanValue( adapters[i] ) ) { return true; } } return false; } public void publishAnyPendingAttributeChanges() { FormAttributeAdapter[] adapters = getAll(); for ( int i = 0; i < adapters.length; i++ ) { adapters[i].publishAnyPendingChanges(); } } public boolean setInputDisabled( String pAttributeName, boolean pDisabled ) { boolean rv = false; if ( pAttributeName != null ) { FormAttributeAdapter[] all = getAll(); for ( int i = 0; i < all.length; i++ ) { FormAttributeAdapter adapter = all[i]; if ( pAttributeName.equals( adapter.getAttributeReference() ) ) { rv = true; adapter.setDisabled( pDisabled ); } } } return rv; } public boolean setFocus() { FormAttributeAdapter[] all = getAll(); for ( int i = 0; i < all.length; i++ ) { FormAttributeAdapter adapter = all[i]; if ( adapter.isVisible() && adapter.isEnabled() ) { if ( adapter.setFocus() ) { return true; } } } return false; } public static final String USER_STATE_PREFIX = "FORM-"; public static final String ENTRIES = "Entries"; public void captureUserState( String pRootType, ParamMap pParamMap ) { if ( pParamMap != null ) { pParamMap.add( USER_STATE_PREFIX + pRootType, captureUserState() ); } } public void restoreUserState( String pRootType, ParamMap pParamMap ) { if ( pParamMap != null ) { ParamMap map = pParamMap.getParamMap( USER_STATE_PREFIX + pRootType ); if ( map != null ) { restoreUserState( map ); } } } private String createEntrys() { StringBuilder sb = new StringBuilder(); for ( int i = 0; i < mAttributeAdapters.length; i++ ) { FormAttributeAdapter adapter = mAttributeAdapters[i]; sb.append( adapter.getAttributeReference() ).append( '|' ); } return sb.toString(); } private ParamMap captureUserState() { ParamMap map = new ParamMap(); map.add( ENTRIES, createEntrys() ); for ( int i = 0; i < mAttributeAdapters.length; i++ ) { FormAttributeAdapter adapter = mAttributeAdapters[i]; if ( adapter.isChangedState() ) { String value = adapter.getUserValue(); map.add( "" + i, value ); } } return map; } private void restoreUserState( ParamMap pParamMap ) { String expectedEntrys = createEntrys(); String actualEntrys = pParamMap.getString( ENTRIES ); if ( !expectedEntrys.equals( actualEntrys ) ) { System.err.println( "AttributeAdapterManager.restoreUserState entries\n" + // " Expected: " + expectedEntrys + "\n" + // " Actual: " + actualEntrys ); return; } for ( int i = 0; i < mAttributeAdapters.length; i++ ) { FormAttributeAdapter adapter = mAttributeAdapters[i]; String value = pParamMap.getString( "" + i ); if ( value != null ) { adapter.setUserValue( value ); } } } } |
Commits for litesoft/trunk/Java/GWT/OldClient/src/org/litesoft/GWT/forms/client/nonpublic/AttributeAdapterManager.java
Revision | Author | Commited | Message |
---|---|---|---|
950 Diff | GeorgeS | Thu 19 Jun, 2014 17:57:04 +0000 | New Lines |
948 Diff | GeorgeS | Sat 07 Jun, 2014 23:42:39 +0000 | Jusefuls Formatter Updated to New Code Format |
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 |
809 Diff | GeorgeS | Thu 16 Aug, 2012 04:10:46 +0000 | |
804 Diff | GeorgeS | Wed 15 Aug, 2012 12:48:51 +0000 | |
801 Diff | GeorgeS | Wed 15 Aug, 2012 03:59:02 +0000 | |
49 Diff | GeorgeS | Mon 12 Apr, 2010 02:59:10 +0000 | License Text |
2 | GeorgeS | Sun 07 Feb, 2010 12:50:58 +0000 |