Subversion Repository Public Repository

litesoft

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

Diff revisions: vs.
  @@ -1,171 +1,170 @@
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.eventbus.client.*;
5 - import org.litesoft.commonfoundation.typeutils.Objects;
6 - import org.litesoft.commonfoundation.typeutils.*;
7 - import org.litesoft.core.simpletypes.*;
8 - import org.litesoft.ui.def.nonpublic.support.*;
9 -
10 - import java.util.*;
11 -
12 - public class AttributeAdapterManager {
13 - private FormAttributeAdapter[] mAttributeAdapters = FormAttributeAdapter.EMPTY_ARRAY;
14 - private Map mAttributeAdaptersByUniqueID = new HashMap();
15 -
16 - private FormAttributeAdapter[] getAll() {
17 - return mAttributeAdapters;
18 - }
19 -
20 - public void dispose() {
21 - mAttributeAdapters = FormAttributeAdapter.EMPTY_ARRAY;
22 - mAttributeAdaptersByUniqueID.clear();
23 - }
24 -
25 - public FormAttributeAdapter get( Integer pUniqueID ) {
26 - return (FormAttributeAdapter) mAttributeAdaptersByUniqueID.get( pUniqueID );
27 - }
28 -
29 - public void add( FormAttributeAdapter pAttributeAdapter ) {
30 - mAttributeAdaptersByUniqueID.put( pAttributeAdapter.getUniqueID(), pAttributeAdapter );
31 -
32 - mAttributeAdapters = FormAttributeAdapter.Helper.append( mAttributeAdapters, pAttributeAdapter );
33 - }
34 -
35 - public void apply( FormDataRowKey pFormDataRowKey, AttributeUpdateFormData[] pAttributeUpdatesNonNullOrEmpty ) {
36 - for ( int i = 0; i < pAttributeUpdatesNonNullOrEmpty.length; i++ ) {
37 - AttributeUpdateFormData update = pAttributeUpdatesNonNullOrEmpty[i];
38 - if ( Objects.areNonArraysEqual( pFormDataRowKey, update.getFormDataRowKey() ) ) {
39 - apply( update );
40 - }
41 - }
42 - }
43 -
44 - private void apply( AttributeUpdateFormData pUpdate ) {
45 - // todo: need to add a FormAttributeAdapter for the Tab Label
46 - FormAttributeAdapter adapter = get( pUpdate.getUniqueID() );
47 - if ( adapter == null ) {
48 - System.out.println( "update '" + pUpdate + "', but no AttributeAdapter" );
49 - return;
50 - }
51 - if ( pUpdate.hasValue() ) {
52 - adapter.setBaseValue( pUpdate.getValue() );
53 - }
54 - if ( pUpdate.getDisable() != null ) {
55 - adapter.setDisabled( pUpdate.getDisable().booleanValue() );
56 - }
57 - adapter.setErrorText( Strings.noEmpty( pUpdate.getErrorText() ) );
58 - if ( pUpdate instanceof ComboBoxAttributeUpdateFormData ) {
59 - SimpleKeyValuePair[] newValidOptions =
60 - ((ComboBoxAttributeUpdateFormData) pUpdate).getValidOptions();
61 - if ( Objects.isNullOrEmpty( newValidOptions ) ) {
62 - System.out.println( "update '" + pUpdate + "', but no ValidOptions" );
63 - } else {
64 - adapter.updateValidOptions( newValidOptions );
65 - }
66 - }
67 - }
68 -
69 - public boolean recalcAnyAttributes( FormAttributeAdapter.BooleanValueAccessor pValueAccessor ) {
70 - FormAttributeAdapter[] adapters = getAll();
71 - for ( int i = 0; i < adapters.length; i++ ) {
72 - if ( pValueAccessor.isBooleanValue( adapters[i] ) ) {
73 - return true;
74 - }
75 - }
76 - return false;
77 - }
78 -
79 - public void publishAnyPendingAttributeChanges() {
80 - FormAttributeAdapter[] adapters = getAll();
81 - for ( int i = 0; i < adapters.length; i++ ) {
82 - adapters[i].publishAnyPendingChanges();
83 - }
84 - }
85 -
86 - public boolean setInputDisabled( String pAttributeName, boolean pDisabled ) {
87 - boolean rv = false;
88 - if ( pAttributeName != null ) {
89 - FormAttributeAdapter[] all = getAll();
90 - for ( int i = 0; i < all.length; i++ ) {
91 - FormAttributeAdapter adapter = all[i];
92 - if ( pAttributeName.equals( adapter.getAttributeReference() ) ) {
93 - rv = true;
94 - adapter.setDisabled( pDisabled );
95 - }
96 - }
97 - }
98 - return rv;
99 - }
100 -
101 - public boolean setFocus() {
102 - FormAttributeAdapter[] all = getAll();
103 - for ( int i = 0; i < all.length; i++ ) {
104 - FormAttributeAdapter adapter = all[i];
105 - if ( adapter.isVisible() && adapter.isEnabled() ) {
106 - if ( adapter.setFocus() ) {
107 - return true;
108 - }
109 - }
110 - }
111 - return false;
112 - }
113 -
114 - public static final String USER_STATE_PREFIX = "FORM-";
115 - public static final String ENTRIES = "Entries";
116 -
117 - public void captureUserState( String pRootType, ParamMap pParamMap ) {
118 - if ( pParamMap != null ) {
119 - pParamMap.add( USER_STATE_PREFIX + pRootType, captureUserState() );
120 - }
121 - }
122 -
123 - public void restoreUserState( String pRootType, ParamMap pParamMap ) {
124 - if ( pParamMap != null ) {
125 - ParamMap map = pParamMap.getParamMap( USER_STATE_PREFIX + pRootType );
126 - if ( map != null ) {
127 - restoreUserState( map );
128 - }
129 - }
130 - }
131 -
132 - private String createEntrys() {
133 - StringBuilder sb = new StringBuilder();
134 - for ( int i = 0; i < mAttributeAdapters.length; i++ ) {
135 - FormAttributeAdapter adapter = mAttributeAdapters[i];
136 - sb.append( adapter.getAttributeReference() ).append( '|' );
137 - }
138 - return sb.toString();
139 - }
140 -
141 - private ParamMap captureUserState() {
142 - ParamMap map = new ParamMap();
143 - map.add( ENTRIES, createEntrys() );
144 - for ( int i = 0; i < mAttributeAdapters.length; i++ ) {
145 - FormAttributeAdapter adapter = mAttributeAdapters[i];
146 - if ( adapter.isChangedState() ) {
147 - String value = adapter.getUserValue();
148 - map.add( "" + i, value );
149 - }
150 - }
151 - return map;
152 - }
153 -
154 - private void restoreUserState( ParamMap pParamMap ) {
155 - String expectedEntrys = createEntrys();
156 - String actualEntrys = pParamMap.getString( ENTRIES );
157 - if ( !expectedEntrys.equals( actualEntrys ) ) {
158 - System.err.println( "AttributeAdapterManager.restoreUserState entries\n" + //
159 - " Expected: " + expectedEntrys + "\n" + //
160 - " Actual: " + actualEntrys );
161 - return;
162 - }
163 - for ( int i = 0; i < mAttributeAdapters.length; i++ ) {
164 - FormAttributeAdapter adapter = mAttributeAdapters[i];
165 - String value = pParamMap.getString( "" + i );
166 - if ( value != null ) {
167 - adapter.setUserValue( value );
168 - }
169 - }
170 - }
171 - }
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.eventbus.client.*;
5 + import org.litesoft.commonfoundation.base.*;
6 + import org.litesoft.core.simpletypes.*;
7 + import org.litesoft.ui.def.nonpublic.support.*;
8 +
9 + import java.util.*;
10 +
11 + public class AttributeAdapterManager {
12 + private FormAttributeAdapter[] mAttributeAdapters = FormAttributeAdapter.EMPTY_ARRAY;
13 + private Map mAttributeAdaptersByUniqueID = new HashMap();
14 +
15 + private FormAttributeAdapter[] getAll() {
16 + return mAttributeAdapters;
17 + }
18 +
19 + public void dispose() {
20 + mAttributeAdapters = FormAttributeAdapter.EMPTY_ARRAY;
21 + mAttributeAdaptersByUniqueID.clear();
22 + }
23 +
24 + public FormAttributeAdapter get( Integer pUniqueID ) {
25 + return (FormAttributeAdapter) mAttributeAdaptersByUniqueID.get( pUniqueID );
26 + }
27 +
28 + public void add( FormAttributeAdapter pAttributeAdapter ) {
29 + mAttributeAdaptersByUniqueID.put( pAttributeAdapter.getUniqueID(), pAttributeAdapter );
30 +
31 + mAttributeAdapters = FormAttributeAdapter.Helper.append( mAttributeAdapters, pAttributeAdapter );
32 + }
33 +
34 + public void apply( FormDataRowKey pFormDataRowKey, AttributeUpdateFormData[] pAttributeUpdatesNonNullOrEmpty ) {
35 + for ( int i = 0; i < pAttributeUpdatesNonNullOrEmpty.length; i++ ) {
36 + AttributeUpdateFormData update = pAttributeUpdatesNonNullOrEmpty[i];
37 + if ( Currently.areEqual( pFormDataRowKey, update.getFormDataRowKey() ) ) {
38 + apply( update );
39 + }
40 + }
41 + }
42 +
43 + private void apply( AttributeUpdateFormData pUpdate ) {
44 + // todo: need to add a FormAttributeAdapter for the Tab Label
45 + FormAttributeAdapter adapter = get( pUpdate.getUniqueID() );
46 + if ( adapter == null ) {
47 + System.out.println( "update '" + pUpdate + "', but no AttributeAdapter" );
48 + return;
49 + }
50 + if ( pUpdate.hasValue() ) {
51 + adapter.setBaseValue( pUpdate.getValue() );
52 + }
53 + if ( pUpdate.getDisable() != null ) {
54 + adapter.setDisabled( pUpdate.getDisable().booleanValue() );
55 + }
56 + adapter.setErrorText( ConstrainTo.significantOrNull( pUpdate.getErrorText() ) );
57 + if ( pUpdate instanceof ComboBoxAttributeUpdateFormData ) {
58 + SimpleKeyValuePair[] newValidOptions =
59 + ((ComboBoxAttributeUpdateFormData) pUpdate).getValidOptions();
60 + if ( Currently.isNullOrEmpty( newValidOptions ) ) {
61 + System.out.println( "update '" + pUpdate + "', but no ValidOptions" );
62 + } else {
63 + adapter.updateValidOptions( newValidOptions );
64 + }
65 + }
66 + }
67 +
68 + public boolean recalcAnyAttributes( FormAttributeAdapter.BooleanValueAccessor pValueAccessor ) {
69 + FormAttributeAdapter[] adapters = getAll();
70 + for ( int i = 0; i < adapters.length; i++ ) {
71 + if ( pValueAccessor.isBooleanValue( adapters[i] ) ) {
72 + return true;
73 + }
74 + }
75 + return false;
76 + }
77 +
78 + public void publishAnyPendingAttributeChanges() {
79 + FormAttributeAdapter[] adapters = getAll();
80 + for ( int i = 0; i < adapters.length; i++ ) {
81 + adapters[i].publishAnyPendingChanges();
82 + }
83 + }
84 +
85 + public boolean setInputDisabled( String pAttributeName, boolean pDisabled ) {
86 + boolean rv = false;
87 + if ( pAttributeName != null ) {
88 + FormAttributeAdapter[] all = getAll();
89 + for ( int i = 0; i < all.length; i++ ) {
90 + FormAttributeAdapter adapter = all[i];
91 + if ( pAttributeName.equals( adapter.getAttributeReference() ) ) {
92 + rv = true;
93 + adapter.setDisabled( pDisabled );
94 + }
95 + }
96 + }
97 + return rv;
98 + }
99 +
100 + public boolean setFocus() {
101 + FormAttributeAdapter[] all = getAll();
102 + for ( int i = 0; i < all.length; i++ ) {
103 + FormAttributeAdapter adapter = all[i];
104 + if ( adapter.isVisible() && adapter.isEnabled() ) {
105 + if ( adapter.setFocus() ) {
106 + return true;
107 + }
108 + }
109 + }
110 + return false;
111 + }
112 +
113 + public static final String USER_STATE_PREFIX = "FORM-";
114 + public static final String ENTRIES = "Entries";
115 +
116 + public void captureUserState( String pRootType, ParamMap pParamMap ) {
117 + if ( pParamMap != null ) {
118 + pParamMap.add( USER_STATE_PREFIX + pRootType, captureUserState() );
119 + }
120 + }
121 +
122 + public void restoreUserState( String pRootType, ParamMap pParamMap ) {
123 + if ( pParamMap != null ) {
124 + ParamMap map = pParamMap.getParamMap( USER_STATE_PREFIX + pRootType );
125 + if ( map != null ) {
126 + restoreUserState( map );
127 + }
128 + }
129 + }
130 +
131 + private String createEntrys() {
132 + StringBuilder sb = new StringBuilder();
133 + for ( int i = 0; i < mAttributeAdapters.length; i++ ) {
134 + FormAttributeAdapter adapter = mAttributeAdapters[i];
135 + sb.append( adapter.getAttributeReference() ).append( '|' );
136 + }
137 + return sb.toString();
138 + }
139 +
140 + private ParamMap captureUserState() {
141 + ParamMap map = new ParamMap();
142 + map.add( ENTRIES, createEntrys() );
143 + for ( int i = 0; i < mAttributeAdapters.length; i++ ) {
144 + FormAttributeAdapter adapter = mAttributeAdapters[i];
145 + if ( adapter.isChangedState() ) {
146 + String value = adapter.getUserValue();
147 + map.add( "" + i, value );
148 + }
149 + }
150 + return map;
151 + }
152 +
153 + private void restoreUserState( ParamMap pParamMap ) {
154 + String expectedEntrys = createEntrys();
155 + String actualEntrys = pParamMap.getString( ENTRIES );
156 + if ( !expectedEntrys.equals( actualEntrys ) ) {
157 + System.err.println( "AttributeAdapterManager.restoreUserState entries\n" + //
158 + " Expected: " + expectedEntrys + "\n" + //
159 + " Actual: " + actualEntrys );
160 + return;
161 + }
162 + for ( int i = 0; i < mAttributeAdapters.length; i++ ) {
163 + FormAttributeAdapter adapter = mAttributeAdapters[i];
164 + String value = pParamMap.getString( "" + i );
165 + if ( value != null ) {
166 + adapter.setUserValue( value );
167 + }
168 + }
169 + }
170 + }