|
@@ -1,81 +1,81 @@ |
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.commonfoundation.typeutils.Objects; |
5 |
|
- |
import org.litesoft.ui.def.nonpublic.support.*; |
6 |
|
- |
|
7 |
|
- |
import java.util.*; |
8 |
|
- |
|
9 |
|
- |
public class ActionAdapterManager { |
10 |
|
- |
private FormActionAdapter[] mAdapters = FormActionAdapter.EMPTY_ARRAY; |
11 |
|
- |
private Map mAdaptersByActionID = new HashMap(); |
12 |
|
- |
|
13 |
|
- |
private FormActionAdapter[] getFor( String pActionID ) { |
14 |
|
- |
Object o = mAdaptersByActionID.get( pActionID ); |
15 |
|
- |
return (o == null) ? FormActionAdapter.EMPTY_ARRAY : (FormActionAdapter[]) o; |
16 |
|
- |
} |
17 |
|
- |
|
18 |
|
- |
public void dispose() { |
19 |
|
- |
mAdapters = FormActionAdapter.EMPTY_ARRAY; |
20 |
|
- |
mAdaptersByActionID.clear(); |
21 |
|
- |
} |
22 |
|
- |
|
23 |
|
- |
public void add( FormActionAdapter pActionAdapter ) { |
24 |
|
- |
if ( pActionAdapter != null ) { |
25 |
|
- |
mAdapters = FormActionAdapter.Helper.append( mAdapters, pActionAdapter ); |
26 |
|
- |
String actionID = pActionAdapter.getActionID(); |
27 |
|
- |
FormActionAdapter[] adapters = FormActionAdapter.Helper.append( getFor( actionID ), pActionAdapter ); |
28 |
|
- |
mAdaptersByActionID.put( actionID, adapters ); |
29 |
|
- |
} |
30 |
|
- |
} |
31 |
|
- |
|
32 |
|
- |
public void apply( FormDataRowKey pFormDataRowKey, ActionUpdateFormData[] pActionUpdatesNonNullOrEmpty ) { |
33 |
|
- |
for ( int i = 0; i < pActionUpdatesNonNullOrEmpty.length; i++ ) { |
34 |
|
- |
ActionUpdateFormData update = pActionUpdatesNonNullOrEmpty[i]; |
35 |
|
- |
if ( Objects.areNonArraysEqual( pFormDataRowKey, update.getFormDataRowKey() ) ) { |
36 |
|
- |
setActionDisabled( update.getActionID(), update.getDisabled() ); |
37 |
|
- |
} |
38 |
|
- |
} |
39 |
|
- |
} |
40 |
|
- |
|
41 |
|
- |
public void updateInputState( boolean pAnyChanged, boolean pAnyErrors ) { |
42 |
|
- |
for ( int i = 0; i < mAdapters.length; i++ ) { |
43 |
|
- |
FormActionAdapter adapter = mAdapters[i]; |
44 |
|
- |
Boolean changeStateEnablement = adapter.getInputChangeStateEnablement(); |
45 |
|
- |
Boolean errorStateEnablement = adapter.getInputErrorStateEnablement(); |
46 |
|
- |
Boolean change = merge( null, changeStateEnablement, pAnyChanged ); |
47 |
|
- |
change = merge( change, errorStateEnablement, pAnyErrors ); |
48 |
|
- |
if ( change != null ) { |
49 |
|
- |
adapter.setEnabled( change.booleanValue() ); |
50 |
|
- |
} |
51 |
|
- |
} |
52 |
|
- |
} |
53 |
|
- |
|
54 |
|
- |
public boolean setActionDisabled( String pActionID, boolean pDisabled ) { |
55 |
|
- |
FormActionAdapter[] adapters = getFor( pActionID ); |
56 |
|
- |
for ( int i = 0; i < adapters.length; i++ ) { |
57 |
|
- |
FormActionAdapter adapter = adapters[i]; |
58 |
|
- |
adapter.setDisabled( pDisabled ); |
59 |
|
- |
} |
60 |
|
- |
return (adapters.length != 0); |
61 |
|
- |
} |
62 |
|
- |
|
63 |
|
- |
public boolean setFocus() { |
64 |
|
- |
for ( int i = 0; i < mAdapters.length; i++ ) { |
65 |
|
- |
FormActionAdapter adapter = mAdapters[i]; |
66 |
|
- |
if ( adapter.isVisible() && adapter.isEnabled() ) { |
67 |
|
- |
if ( adapter.setFocus() ) { |
68 |
|
- |
return true; |
69 |
|
- |
} |
70 |
|
- |
} |
71 |
|
- |
} |
72 |
|
- |
return false; |
73 |
|
- |
} |
74 |
|
- |
|
75 |
|
- |
private Boolean merge( Boolean pExisting, Boolean pStateEnablement, boolean pState ) { |
76 |
|
- |
if ( Boolean.FALSE.equals( pExisting ) || (pStateEnablement == null) ) { |
77 |
|
- |
return pExisting; |
78 |
|
- |
} |
79 |
|
- |
return Boolean.valueOf( pState == pStateEnablement.booleanValue() ); |
80 |
|
- |
} |
81 |
|
- |
} |
|
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.commonfoundation.base.*; |
|
5 |
+ |
import org.litesoft.ui.def.nonpublic.support.*; |
|
6 |
+ |
|
|
7 |
+ |
import java.util.*; |
|
8 |
+ |
|
|
9 |
+ |
public class ActionAdapterManager { |
|
10 |
+ |
private FormActionAdapter[] mAdapters = FormActionAdapter.EMPTY_ARRAY; |
|
11 |
+ |
private Map mAdaptersByActionID = new HashMap(); |
|
12 |
+ |
|
|
13 |
+ |
private FormActionAdapter[] getFor( String pActionID ) { |
|
14 |
+ |
Object o = mAdaptersByActionID.get( pActionID ); |
|
15 |
+ |
return (o == null) ? FormActionAdapter.EMPTY_ARRAY : (FormActionAdapter[]) o; |
|
16 |
+ |
} |
|
17 |
+ |
|
|
18 |
+ |
public void dispose() { |
|
19 |
+ |
mAdapters = FormActionAdapter.EMPTY_ARRAY; |
|
20 |
+ |
mAdaptersByActionID.clear(); |
|
21 |
+ |
} |
|
22 |
+ |
|
|
23 |
+ |
public void add( FormActionAdapter pActionAdapter ) { |
|
24 |
+ |
if ( pActionAdapter != null ) { |
|
25 |
+ |
mAdapters = FormActionAdapter.Helper.append( mAdapters, pActionAdapter ); |
|
26 |
+ |
String actionID = pActionAdapter.getActionID(); |
|
27 |
+ |
FormActionAdapter[] adapters = FormActionAdapter.Helper.append( getFor( actionID ), pActionAdapter ); |
|
28 |
+ |
mAdaptersByActionID.put( actionID, adapters ); |
|
29 |
+ |
} |
|
30 |
+ |
} |
|
31 |
+ |
|
|
32 |
+ |
public void apply( FormDataRowKey pFormDataRowKey, ActionUpdateFormData[] pActionUpdatesNonNullOrEmpty ) { |
|
33 |
+ |
for ( int i = 0; i < pActionUpdatesNonNullOrEmpty.length; i++ ) { |
|
34 |
+ |
ActionUpdateFormData update = pActionUpdatesNonNullOrEmpty[i]; |
|
35 |
+ |
if ( Currently.areEqual( pFormDataRowKey, update.getFormDataRowKey() ) ) { |
|
36 |
+ |
setActionDisabled( update.getActionID(), update.getDisabled() ); |
|
37 |
+ |
} |
|
38 |
+ |
} |
|
39 |
+ |
} |
|
40 |
+ |
|
|
41 |
+ |
public void updateInputState( boolean pAnyChanged, boolean pAnyErrors ) { |
|
42 |
+ |
for ( int i = 0; i < mAdapters.length; i++ ) { |
|
43 |
+ |
FormActionAdapter adapter = mAdapters[i]; |
|
44 |
+ |
Boolean changeStateEnablement = adapter.getInputChangeStateEnablement(); |
|
45 |
+ |
Boolean errorStateEnablement = adapter.getInputErrorStateEnablement(); |
|
46 |
+ |
Boolean change = merge( null, changeStateEnablement, pAnyChanged ); |
|
47 |
+ |
change = merge( change, errorStateEnablement, pAnyErrors ); |
|
48 |
+ |
if ( change != null ) { |
|
49 |
+ |
adapter.setEnabled( change.booleanValue() ); |
|
50 |
+ |
} |
|
51 |
+ |
} |
|
52 |
+ |
} |
|
53 |
+ |
|
|
54 |
+ |
public boolean setActionDisabled( String pActionID, boolean pDisabled ) { |
|
55 |
+ |
FormActionAdapter[] adapters = getFor( pActionID ); |
|
56 |
+ |
for ( int i = 0; i < adapters.length; i++ ) { |
|
57 |
+ |
FormActionAdapter adapter = adapters[i]; |
|
58 |
+ |
adapter.setDisabled( pDisabled ); |
|
59 |
+ |
} |
|
60 |
+ |
return (adapters.length != 0); |
|
61 |
+ |
} |
|
62 |
+ |
|
|
63 |
+ |
public boolean setFocus() { |
|
64 |
+ |
for ( int i = 0; i < mAdapters.length; i++ ) { |
|
65 |
+ |
FormActionAdapter adapter = mAdapters[i]; |
|
66 |
+ |
if ( adapter.isVisible() && adapter.isEnabled() ) { |
|
67 |
+ |
if ( adapter.setFocus() ) { |
|
68 |
+ |
return true; |
|
69 |
+ |
} |
|
70 |
+ |
} |
|
71 |
+ |
} |
|
72 |
+ |
return false; |
|
73 |
+ |
} |
|
74 |
+ |
|
|
75 |
+ |
private Boolean merge( Boolean pExisting, Boolean pStateEnablement, boolean pState ) { |
|
76 |
+ |
if ( Boolean.FALSE.equals( pExisting ) || (pStateEnablement == null) ) { |
|
77 |
+ |
return pExisting; |
|
78 |
+ |
} |
|
79 |
+ |
return Boolean.valueOf( pState == pStateEnablement.booleanValue() ); |
|
80 |
+ |
} |
|
81 |
+ |
} |