Subversion Repository Public Repository

litesoft

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
package org.litesoft.GWT.forms.client.nonpublic;

import org.litesoft.GWT.client.*;
import org.litesoft.GWT.forms.client.components.impls.input.*;
import org.litesoft.core.simpletypes.*;
import org.litesoft.core.simpletypes.nonpublic.*;
import org.litesoft.core.util.*;
import org.litesoft.rpcpassable.*;
import org.litesoft.ui.def.nonpublic.*;
import org.litesoft.ui.def.nonpublic.support.*;
import org.litesoft.uispecification.*;

public abstract class AbstractNumericRequireableAttributeAdapter
        extends AbstractNonStringRequireableAttributeAdapter
{
    private Integer mDecimalPlaces;
    private NumericFormatControl mFormatControl;

    public AbstractNumericRequireableAttributeAdapter( FormInstanceComponentHandler pComponentHandler,
                                                       UiInputDef pUiDef, NumericMetaData pMD )
    {
        super( pComponentHandler, pMD, createFC( pUiDef, pMD ) );
        if ( (null != (mDecimalPlaces = pMD.getDecimalPlaces())) && //
             ((mDecimalPlaces.intValue() < 0) || (mDecimalPlaces.intValue() > 20)) )
        {
            int i = Math.abs( mDecimalPlaces.intValue() );
            mDecimalPlaces = new Integer( (i > 20) ? 20 : i );
        }
        if ( null == (mFormatControl = pMD.getFormatControl()) )
        {
            mFormatControl = NumericFormatControl.JUST_DOT;
        }
    }

    private static FormRightAlignTextField createFC( UiInputDef pUiDef, NumericMetaData pMD )
    {
        String zLabelText = !pUiDef.isLabelLess() ? pMD.getExternalText() : null;
        UiFont zLabelFont = pUiDef.getLabelFont();
        String zTooltip = pMD.getTooltip();

        Integer zPreferredWidth = !pUiDef.isFloodX() ? pMD.getPreferredWidth() : null;
        Integer zMaxChars = pMD.getMaxChars();

        return new FormRightAlignTextField( zLabelText, zLabelFont, zTooltip, zPreferredWidth, zMaxChars );
    }

    protected Object getComponentCurrentValue()
    {
        Object value = super.getComponentCurrentValue();
        if ( value != null )
        {
            value = UtilsCommon.noEmpty( value.toString() );
        }
        return value;
    }

    public void blurOccurred()
    {
        super.blurOccurred();
        if ( !isErrorState() )
        {
            try
            {
                DecimalToStringParts zSP = convert( mComponent.getCurrentText() );
                if ( zSP != null )
                {
                    mComponent.setCurrentValue(
                            mLastErrorComponentCurrentValue = zSP.toString( mFormatControl ) );
                }
            }
            catch ( IllegalArgumentException e )
            {
                // Already in Error State
            }
        }
    }

    protected String transformErrorText( String pErrorText, RPCpassable pSendableCurrentValue,
                                         Object pComponentCurrentValue )
    {
        if ( null == (pErrorText = UtilsCommon.noEmpty( pErrorText )) )
        {
            pErrorText = getCurrentValueErrorText( pComponentCurrentValue );
        }
        return super.transformErrorText( pErrorText, //
                                         pSendableCurrentValue, //
                                         pComponentCurrentValue );
    }

    protected Object convertSendableToComponentValue( RPCpassable pValue )
    {
        try
        {
            DecimalToStringParts zSP = convert( pValue );
            if ( zSP != null )
            {
                return mLastErrorComponentCurrentValue = zSP.toString( mFormatControl );
            }
        }
        catch ( IllegalArgumentException e )
        {
            AlertManager.alert( "DataConversion", null, "Unable to convert value", "Value:" + pValue, e );
        }
        return null;
    }

    protected RPCpassable convertComponentValueToSendable( Object pValue )
    {
        try
        {
            DecimalToStringParts zSP = convert( pValue );
            if ( zSP != null )
            {
                return LLconvertNonNullComponentValueToSendable( zSP.toString() );
            }
        }
        catch ( IllegalArgumentException e )
        {
            mLastErrorText = e.getMessage();
            setErrorTextAndPublish( null, null, mLastErrorComponentCurrentValue );
        }
        return null;
    }

    abstract protected RPCpassable LLconvertNonNullComponentValueToSendable( String pCleanedValue );

    private DecimalToStringParts convert( Object pValue )
            throws IllegalArgumentException
    {
        mLastErrorText = null;
        if ( null != (mLastErrorComponentCurrentValue = conversionHelper( pValue )) )
        {
            DecimalToStringParts zSP = new DecimalToStringParts( mLastErrorComponentCurrentValue, //
                                                                 mFormatControl.getDecimalSeparator() );
            return zSP.forceDecimalPlaces( mDecimalPlaces, false );
        }
        return null;
    }

    private String conversionHelper( Object pValue )
    {
        return (pValue != null) ? UtilsCommon.noEmpty( pValue.toString() ) : null;
    }

    private String getCurrentValueErrorText( Object pComponentCurrentValue )
    {
        if ( !UtilsCommon.areNonArraysEqual( pComponentCurrentValue, mLastErrorComponentCurrentValue ) )
        {
            convertComponentValueToSendable( mComponent.getCurrentText() );
        }
        return mLastErrorText;
    }

    private String mLastErrorComponentCurrentValue = null;
    private String mLastErrorText = null;
}

Commits for litesoft/trunk/Java/GWT/OldClient/src/org/litesoft/GWT/forms/client/nonpublic/AbstractNumericRequireableAttributeAdapter.java

Diff revisions: vs.
Revision Author Commited Message
2 GeorgeS picture GeorgeS Sun 07 Feb, 2010 12:50:58 +0000