|
@@ -1,129 +1,129 @@ |
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.client.*; |
5 |
|
- |
import org.litesoft.GWT.forms.client.components.impls.input.*; |
6 |
|
- |
import org.litesoft.commonfoundation.typeutils.*; |
7 |
|
- |
import org.litesoft.core.simpletypes.*; |
8 |
|
- |
import org.litesoft.core.simpletypes.nonpublic.*; |
9 |
|
- |
import org.litesoft.ui.def.nonpublic.*; |
10 |
|
- |
import org.litesoft.ui.def.nonpublic.support.*; |
11 |
|
- |
import org.litesoft.uispecification.*; |
12 |
|
- |
|
13 |
|
- |
import java.io.*; |
14 |
|
- |
|
15 |
|
- |
public abstract class AbstractNumericRequireableAttributeAdapter |
16 |
|
- |
extends AbstractNonStringRequireableAttributeAdapter { |
17 |
|
- |
private Integer mDecimalPlaces; |
18 |
|
- |
private NumericFormatControl mFormatControl; |
19 |
|
- |
|
20 |
|
- |
public AbstractNumericRequireableAttributeAdapter( FormInstanceComponentHandler pComponentHandler, |
21 |
|
- |
UiInputDef pUiDef, NumericMetaData pMD ) { |
22 |
|
- |
super( pComponentHandler, pMD, createFC( pUiDef, pMD ) ); |
23 |
|
- |
if ( null != (mDecimalPlaces = pMD.getDecimalPlaces()) ) { |
24 |
|
- |
mDecimalPlaces = Math.min( Math.abs( mDecimalPlaces.intValue() ), 20 ); |
25 |
|
- |
} |
26 |
|
- |
if ( null == (mFormatControl = pMD.getFormatControl()) ) { |
27 |
|
- |
mFormatControl = NumericFormatControl.JUST_DOT; |
28 |
|
- |
} |
29 |
|
- |
} |
30 |
|
- |
|
31 |
|
- |
private static FormRightAlignTextField createFC( UiInputDef pUiDef, NumericMetaData pMD ) { |
32 |
|
- |
String zLabelText = !pUiDef.isLabelLess() ? pMD.getExternalText() : null; |
33 |
|
- |
UiFont zLabelFont = pUiDef.getLabelFont(); |
34 |
|
- |
String zTooltip = pMD.getTooltip(); |
35 |
|
- |
|
36 |
|
- |
Integer zPreferredWidth = !pUiDef.isFloodX() ? pMD.getPreferredWidth() : null; |
37 |
|
- |
Integer zMaxChars = pMD.getMaxChars(); |
38 |
|
- |
|
39 |
|
- |
return new FormRightAlignTextField( zLabelText, zLabelFont, zTooltip, zPreferredWidth, zMaxChars ); |
40 |
|
- |
} |
41 |
|
- |
|
42 |
|
- |
protected Object getComponentCurrentValue() { |
43 |
|
- |
Object value = super.getComponentCurrentValue(); |
44 |
|
- |
if ( value != null ) { |
45 |
|
- |
value = Strings.noEmpty( value.toString() ); |
46 |
|
- |
} |
47 |
|
- |
return value; |
48 |
|
- |
} |
49 |
|
- |
|
50 |
|
- |
public void blurOccurred() { |
51 |
|
- |
super.blurOccurred(); |
52 |
|
- |
if ( !isErrorState() ) { |
53 |
|
- |
try { |
54 |
|
- |
DecimalToStringParts zSP = convert( mComponent.getCurrentText() ); |
55 |
|
- |
if ( zSP != null ) { |
56 |
|
- |
mComponent.setCurrentValue( |
57 |
|
- |
mLastErrorComponentCurrentValue = zSP.toString( mFormatControl ) ); |
58 |
|
- |
} |
59 |
|
- |
} |
60 |
|
- |
catch ( IllegalArgumentException e ) { |
61 |
|
- |
// Already in Error State |
62 |
|
- |
} |
63 |
|
- |
} |
64 |
|
- |
} |
65 |
|
- |
|
66 |
|
- |
protected String transformErrorText( String pErrorText, Serializable pSendableCurrentValue, |
67 |
|
- |
Object pComponentCurrentValue ) { |
68 |
|
- |
if ( null == (pErrorText = Strings.noEmpty( pErrorText )) ) { |
69 |
|
- |
pErrorText = getCurrentValueErrorText( pComponentCurrentValue ); |
70 |
|
- |
} |
71 |
|
- |
return super.transformErrorText( pErrorText, // |
72 |
|
- |
pSendableCurrentValue, // |
73 |
|
- |
pComponentCurrentValue ); |
74 |
|
- |
} |
75 |
|
- |
|
76 |
|
- |
protected Object convertSendableToComponentValue( Serializable pValue ) { |
77 |
|
- |
try { |
78 |
|
- |
DecimalToStringParts zSP = convert( pValue ); |
79 |
|
- |
if ( zSP != null ) { |
80 |
|
- |
return mLastErrorComponentCurrentValue = zSP.toString( mFormatControl ); |
81 |
|
- |
} |
82 |
|
- |
} |
83 |
|
- |
catch ( IllegalArgumentException e ) { |
84 |
|
- |
AlertManager.alert( "DataConversion", null, "Unable to convert value", "Value:" + pValue, e ); |
85 |
|
- |
} |
86 |
|
- |
return null; |
87 |
|
- |
} |
88 |
|
- |
|
89 |
|
- |
protected Serializable convertComponentValueToSendable( Object pValue ) { |
90 |
|
- |
try { |
91 |
|
- |
DecimalToStringParts zSP = convert( pValue ); |
92 |
|
- |
if ( zSP != null ) { |
93 |
|
- |
return LLconvertNonNullComponentValueToSendable( zSP.toString() ); |
94 |
|
- |
} |
95 |
|
- |
} |
96 |
|
- |
catch ( IllegalArgumentException e ) { |
97 |
|
- |
mLastErrorText = e.getMessage(); |
98 |
|
- |
setErrorTextAndPublish( null, null, mLastErrorComponentCurrentValue ); |
99 |
|
- |
} |
100 |
|
- |
return null; |
101 |
|
- |
} |
102 |
|
- |
|
103 |
|
- |
abstract protected Serializable LLconvertNonNullComponentValueToSendable( String pCleanedValue ); |
104 |
|
- |
|
105 |
|
- |
private DecimalToStringParts convert( Object pValue ) |
106 |
|
- |
throws IllegalArgumentException { |
107 |
|
- |
mLastErrorText = null; |
108 |
|
- |
if ( null != (mLastErrorComponentCurrentValue = conversionHelper( pValue )) ) { |
109 |
|
- |
DecimalToStringParts zSP = new DecimalToStringParts( mLastErrorComponentCurrentValue, // |
110 |
|
- |
mFormatControl.getDecimalSeparator() ); |
111 |
|
- |
return zSP.forceDecimalPlaces( mDecimalPlaces, false ); |
112 |
|
- |
} |
113 |
|
- |
return null; |
114 |
|
- |
} |
115 |
|
- |
|
116 |
|
- |
private String conversionHelper( Object pValue ) { |
117 |
|
- |
return (pValue != null) ? Strings.noEmpty( pValue.toString() ) : null; |
118 |
|
- |
} |
119 |
|
- |
|
120 |
|
- |
private String getCurrentValueErrorText( Object pComponentCurrentValue ) { |
121 |
|
- |
if ( !Objects.areNonArraysEqual( pComponentCurrentValue, mLastErrorComponentCurrentValue ) ) { |
122 |
|
- |
convertComponentValueToSendable( mComponent.getCurrentText() ); |
123 |
|
- |
} |
124 |
|
- |
return mLastErrorText; |
125 |
|
- |
} |
126 |
|
- |
|
127 |
|
- |
private String mLastErrorComponentCurrentValue = null; |
128 |
|
- |
private String mLastErrorText = null; |
129 |
|
- |
} |
|
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.client.*; |
|
5 |
+ |
import org.litesoft.GWT.forms.client.components.impls.input.*; |
|
6 |
+ |
import org.litesoft.commonfoundation.base.*; |
|
7 |
+ |
import org.litesoft.core.simpletypes.*; |
|
8 |
+ |
import org.litesoft.core.simpletypes.nonpublic.*; |
|
9 |
+ |
import org.litesoft.ui.def.nonpublic.*; |
|
10 |
+ |
import org.litesoft.ui.def.nonpublic.support.*; |
|
11 |
+ |
import org.litesoft.uispecification.*; |
|
12 |
+ |
|
|
13 |
+ |
import java.io.*; |
|
14 |
+ |
|
|
15 |
+ |
public abstract class AbstractNumericRequireableAttributeAdapter |
|
16 |
+ |
extends AbstractNonStringRequireableAttributeAdapter { |
|
17 |
+ |
private Integer mDecimalPlaces; |
|
18 |
+ |
private NumericFormatControl mFormatControl; |
|
19 |
+ |
|
|
20 |
+ |
public AbstractNumericRequireableAttributeAdapter( FormInstanceComponentHandler pComponentHandler, |
|
21 |
+ |
UiInputDef pUiDef, NumericMetaData pMD ) { |
|
22 |
+ |
super( pComponentHandler, pMD, createFC( pUiDef, pMD ) ); |
|
23 |
+ |
if ( null != (mDecimalPlaces = pMD.getDecimalPlaces()) ) { |
|
24 |
+ |
mDecimalPlaces = Math.min( Math.abs( mDecimalPlaces.intValue() ), 20 ); |
|
25 |
+ |
} |
|
26 |
+ |
if ( null == (mFormatControl = pMD.getFormatControl()) ) { |
|
27 |
+ |
mFormatControl = NumericFormatControl.JUST_DOT; |
|
28 |
+ |
} |
|
29 |
+ |
} |
|
30 |
+ |
|
|
31 |
+ |
private static FormRightAlignTextField createFC( UiInputDef pUiDef, NumericMetaData pMD ) { |
|
32 |
+ |
String zLabelText = !pUiDef.isLabelLess() ? pMD.getExternalText() : null; |
|
33 |
+ |
UiFont zLabelFont = pUiDef.getLabelFont(); |
|
34 |
+ |
String zTooltip = pMD.getTooltip(); |
|
35 |
+ |
|
|
36 |
+ |
Integer zPreferredWidth = !pUiDef.isFloodX() ? pMD.getPreferredWidth() : null; |
|
37 |
+ |
Integer zMaxChars = pMD.getMaxChars(); |
|
38 |
+ |
|
|
39 |
+ |
return new FormRightAlignTextField( zLabelText, zLabelFont, zTooltip, zPreferredWidth, zMaxChars ); |
|
40 |
+ |
} |
|
41 |
+ |
|
|
42 |
+ |
protected Object getComponentCurrentValue() { |
|
43 |
+ |
Object value = super.getComponentCurrentValue(); |
|
44 |
+ |
if ( value != null ) { |
|
45 |
+ |
value = ConstrainTo.significantOrNull( value.toString() ); |
|
46 |
+ |
} |
|
47 |
+ |
return value; |
|
48 |
+ |
} |
|
49 |
+ |
|
|
50 |
+ |
public void blurOccurred() { |
|
51 |
+ |
super.blurOccurred(); |
|
52 |
+ |
if ( !isErrorState() ) { |
|
53 |
+ |
try { |
|
54 |
+ |
DecimalToStringParts zSP = convert( mComponent.getCurrentText() ); |
|
55 |
+ |
if ( zSP != null ) { |
|
56 |
+ |
mComponent.setCurrentValue( |
|
57 |
+ |
mLastErrorComponentCurrentValue = zSP.toString( mFormatControl ) ); |
|
58 |
+ |
} |
|
59 |
+ |
} |
|
60 |
+ |
catch ( IllegalArgumentException e ) { |
|
61 |
+ |
// Already in Error State |
|
62 |
+ |
} |
|
63 |
+ |
} |
|
64 |
+ |
} |
|
65 |
+ |
|
|
66 |
+ |
protected String transformErrorText( String pErrorText, Serializable pSendableCurrentValue, |
|
67 |
+ |
Object pComponentCurrentValue ) { |
|
68 |
+ |
if ( null == (pErrorText = ConstrainTo.significantOrNull( pErrorText )) ) { |
|
69 |
+ |
pErrorText = getCurrentValueErrorText( pComponentCurrentValue ); |
|
70 |
+ |
} |
|
71 |
+ |
return super.transformErrorText( pErrorText, // |
|
72 |
+ |
pSendableCurrentValue, // |
|
73 |
+ |
pComponentCurrentValue ); |
|
74 |
+ |
} |
|
75 |
+ |
|
|
76 |
+ |
protected Object convertSendableToComponentValue( Serializable pValue ) { |
|
77 |
+ |
try { |
|
78 |
+ |
DecimalToStringParts zSP = convert( pValue ); |
|
79 |
+ |
if ( zSP != null ) { |
|
80 |
+ |
return mLastErrorComponentCurrentValue = zSP.toString( mFormatControl ); |
|
81 |
+ |
} |
|
82 |
+ |
} |
|
83 |
+ |
catch ( IllegalArgumentException e ) { |
|
84 |
+ |
AlertManager.alert( "DataConversion", null, "Unable to convert value", "Value:" + pValue, e ); |
|
85 |
+ |
} |
|
86 |
+ |
return null; |
|
87 |
+ |
} |
|
88 |
+ |
|
|
89 |
+ |
protected Serializable convertComponentValueToSendable( Object pValue ) { |
|
90 |
+ |
try { |
|
91 |
+ |
DecimalToStringParts zSP = convert( pValue ); |
|
92 |
+ |
if ( zSP != null ) { |
|
93 |
+ |
return LLconvertNonNullComponentValueToSendable( zSP.toString() ); |
|
94 |
+ |
} |
|
95 |
+ |
} |
|
96 |
+ |
catch ( IllegalArgumentException e ) { |
|
97 |
+ |
mLastErrorText = e.getMessage(); |
|
98 |
+ |
setErrorTextAndPublish( null, null, mLastErrorComponentCurrentValue ); |
|
99 |
+ |
} |
|
100 |
+ |
return null; |
|
101 |
+ |
} |
|
102 |
+ |
|
|
103 |
+ |
abstract protected Serializable LLconvertNonNullComponentValueToSendable( String pCleanedValue ); |
|
104 |
+ |
|
|
105 |
+ |
private DecimalToStringParts convert( Object pValue ) |
|
106 |
+ |
throws IllegalArgumentException { |
|
107 |
+ |
mLastErrorText = null; |
|
108 |
+ |
if ( null != (mLastErrorComponentCurrentValue = conversionHelper( pValue )) ) { |
|
109 |
+ |
DecimalToStringParts zSP = new DecimalToStringParts( mLastErrorComponentCurrentValue, // |
|
110 |
+ |
mFormatControl.getDecimalSeparator() ); |
|
111 |
+ |
return zSP.forceDecimalPlaces( mDecimalPlaces, false ); |
|
112 |
+ |
} |
|
113 |
+ |
return null; |
|
114 |
+ |
} |
|
115 |
+ |
|
|
116 |
+ |
private String conversionHelper( Object pValue ) { |
|
117 |
+ |
return (pValue != null) ? ConstrainTo.significantOrNull( pValue.toString() ) : null; |
|
118 |
+ |
} |
|
119 |
+ |
|
|
120 |
+ |
private String getCurrentValueErrorText( Object pComponentCurrentValue ) { |
|
121 |
+ |
if ( !Currently.areEqual( pComponentCurrentValue, mLastErrorComponentCurrentValue ) ) { |
|
122 |
+ |
convertComponentValueToSendable( mComponent.getCurrentText() ); |
|
123 |
+ |
} |
|
124 |
+ |
return mLastErrorText; |
|
125 |
+ |
} |
|
126 |
+ |
|
|
127 |
+ |
private String mLastErrorComponentCurrentValue = null; |
|
128 |
+ |
private String mLastErrorText = null; |
|
129 |
+ |
} |