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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
// This Source Code is in the Public Domain per: http://unlicense.org
package org.litesoft.GWT.forms.server.support;

import org.litesoft.GWT.forms.server.*;
import org.litesoft.commonfoundation.base.*;
import org.litesoft.configuration.*;
import org.litesoft.core.util.*;
import org.litesoft.orsup.base.*;
import org.litesoft.ui_1_5.def.*;
import org.litesoft.util.*;

public class CreateAMDParamsPlus extends CreateAMDParams {
    public static final Configuration.CachedConfigInt DEFAULT_SHORT_DISPLAY_CHARS_WIDTH = //
            new Configuration.CachedConfigInt( "DefaultShortDisplayCharsWidth", 3 );

    public static final Configuration.CachedConfigInt DEFAULT_INTEGER_DISPLAY_CHARS_WIDTH = //
            new Configuration.CachedConfigInt( "DefaultIntegerDisplayCharsWidth", 8 );

    public static final Configuration.CachedConfigInt DEFAULT_LONG_DISPLAY_CHARS_WIDTH = //
            new Configuration.CachedConfigInt( "DefaultLongDisplayCharsWidth", 15 );

    public static final Configuration.CachedConfigInt DEFAULT_FIXED_PLONG_DISPLAY_CHARS_WIDTH = //
            new Configuration.CachedConfigInt( "DefaultFixedPLongDisplayCharsWidth", 15 );

    public static final Configuration.CachedConfigInt DEFAULT_FLOATING_PLONG_DISPLAY_CHARS_WIDTH = //
            new Configuration.CachedConfigInt( "DefaultFloatingPLongDisplayCharsWidth", 15 );

    public static final Configuration.CachedConfigInt DEFAULT_FLOAT_DISPLAY_CHARS_WIDTH = //
            new Configuration.CachedConfigInt( "DefaultFloatDisplayCharsWidth", 15 );

    public static final Configuration.CachedConfigInt DEFAULT_DOUBLE_DISPLAY_CHARS_WIDTH = //
            new Configuration.CachedConfigInt( "DefaultDoubleDisplayCharsWidth", 20 );

    public static final Configuration.CachedConfigInt DEFAULT_MONEY_DISPLAY_CHARS_WIDTH = //
            new Configuration.CachedConfigInt( "DefaultMoneyDisplayCharsWidth", 15 );

    private static final Configuration.CachedConfigInt DEFAULT_TEXT_FIELD_DISPLAY_CHARS_WIDTH = //
            new Configuration.CachedConfigInt( "DefaultTextFieldDisplayCharsWidth", 20 );

    private static final Configuration.CachedConfigInt DEFAULT_PASSWORD_FIELD_DISPLAY_CHARS_WIDTH = //
            new Configuration.CachedConfigInt( "DefaultPasswordFieldDisplayCharsWidth", 10 );

    private static final Configuration.CachedConfigInt MAX_CHARS_FOR_TEXT_FIELD = //
            new Configuration.CachedConfigInt( "MaxCharsForTextField", 255 );

    private static final Configuration.CachedConfigInt MAX_DEFAULT_DISPLAY_CHARS_WIDTH_FOR_TEXT_FIELD_BEFORE_FLOODX = //
            new Configuration.CachedConfigInt( "MaxDefaultDisplayCharsWidthForTextFieldBeforeFloodX", 80 );

    protected HintManager mHintManager;

    protected boolean mRequired;
    protected boolean mDisabled;
    protected boolean mHide;

    protected Integer mMaxChars;

    protected Integer mDisplayLines, mDisplayCharsWidth;

    protected void apply( HintManager pAttributeHintManager, //
                          boolean pRequired, boolean pDisabled, boolean pHide, //
                          Integer pMaxChars, Integer pDisplayLines, Integer pDisplayCharsWidth ) {
        mHintManager = HintController.getGlobalHintManager().addAll( pAttributeHintManager ).addAll(
                getUsage().getHints() );

        mRequired = mergeRequired( pRequired, getUsage().getRequired() );
        mDisabled = pDisabled || getUsage().shouldComponentBeDisabled();
        mHide = pHide || getUsage().shouldDataBeHiden();
        switch ( getField() ) {
            default:
            case ViewHide:
                mHide = true;
                // Fall Thru
            case ViewOnly:
                mDisabled = true;
                break;
            case EditHide:
                mHide = true;
                break;
            case Editable:
                break;
        }

        mMaxChars = pMaxChars;
        if ( (mMaxChars != null) && (mMaxChars < 1) ) {
            mMaxChars = null;
        }

        mDisplayLines = pDisplayLines;

        if ( (mDisplayCharsWidth != null) && (mDisplayCharsWidth < 1) ) {
            mDisplayCharsWidth = null;
        }
        mDisplayCharsWidth = pDisplayCharsWidth;
    }

    protected boolean mergeRequired( boolean pServiceSaysRequired, Boolean pUsageSaysRequired ) {
        return (pUsageSaysRequired == null) ? pServiceSaysRequired : pUsageSaysRequired;
    }

    public CreateAMDParamsPlus( CreateAMDParams pParams, HintManager pAttributeHintManager, //
                                boolean pRequired, boolean pDisabled, boolean pHide, //
                                Integer pMaxChars, Integer pDisplayLines, Integer pDisplayCharsWidth ) {
        super( pParams );
        apply( pAttributeHintManager, //
               pRequired, pDisabled, pHide, //
               pMaxChars, pDisplayLines, pDisplayCharsWidth );
    }

    public CreateAMDParamsPlus( CreateAMDParams pParams, AttributeAccessorSCD pSCD ) {
        super( pParams );
        // todo: translate:
//        apply( pSCD.getHintManager(), //
//               pSCD.isRequired(), //
//               Boolean.FALSE.equals( pSCD.getBooleanProperty( AttributeAccessorSCD.EDITABLE_PROPERTY ) ), //
//               Boolean.TRUE.equals( pSCD.getBooleanProperty( AttributeAccessorSCD.HIDE_PROPERTY ) ), //
//               pSCD.getIntegerProperty( AttributeAccessorSCD.LENGTH_PROPERTY ), // MaxChars;
//               pSCD.getIntegerProperty( AttributeAccessorSCD.DISPLAY_LINES_PROPERTY ),
//               pSCD.getIntegerProperty( AttributeAccessorSCD.DISPLAY_COLUMNS_PROPERTY ) );
    }

    public boolean isRequired() {
        return mRequired;
    }

    public boolean isDisabled() {
        return mDisabled;
    }

    public boolean isHide() {
        return mHide;
    }

    public Hintable.Hint[] getHints() {
        return mHintManager.getHints();
    }

    public String getHintValue( String pName ) {
        return mHintManager.getHintValue( pName );
    }

    public String getHintValue( String pName, String pDefaultIfNullOrEmpty ) {
        return mHintManager.getHintValue( pName, pDefaultIfNullOrEmpty );
    }

    public boolean isEditRequired() {
        return isRequired() && getUsage().getIntendedUse().isEdit();
    }

    public String resolveAction( String pActionID ) {
        return mExternalization.resolveAction( pActionID );
    }

    public String getErrorTextForRequired() {
        return isRequired() ? error( FormServicePeer.IS_REQUIRED_ERROR_KEY, getFieldLabel() ) : null;
    }

    public String error( String pErrorKey, String... pToInject ) {
        return SimpleMessage.format( mExternalization.resolveError( pErrorKey ), (Object[]) pToInject );
    }

    public Integer getMaxChars() {
        return mMaxChars;
    }

    public Integer getDisplayLines() {
        return mDisplayLines;
    }

    public Integer getDisplayCharsWidth() {
        return mDisplayCharsWidth;
    }

    public boolean shouldBeTextArea() {
        return ((mMaxChars == null) || (mMaxChars > MAX_CHARS_FOR_TEXT_FIELD.getInteger()) ||
                UI.Hints.CF_TEXT_AREA.equals( getHintValue( UI.Hints.COMPONENT_FORM ) ));
    }

    public Integer getPasswordDisplayCharsWidth() {
        return oneLineHintOveride( DEFAULT_PASSWORD_FIELD_DISPLAY_CHARS_WIDTH );
    }

    public Integer getTextFieldDisplayCharsWidth() {
        return oneLineHintOveride( DEFAULT_TEXT_FIELD_DISPLAY_CHARS_WIDTH );
    }

    public Integer oneLineHintOveride( Configuration.CachedConfigInt pCachedConfigInt ) {
        Integer width = hintOveride( UI.Hints.TEXT_FIELD_WIDTH, mDisplayCharsWidth );
        if ( width == null ) {
            width = (mMaxChars == null) ? pCachedConfigInt.getInteger() : (mMaxChars + 1);
        }
        return (width <= MAX_DEFAULT_DISPLAY_CHARS_WIDTH_FOR_TEXT_FIELD_BEFORE_FLOODX.getInteger()) ? //
               width : null;
    }

    public Integer getTextAreaInitialDisplayCharsWidth() {
        return hintOveride( UI.Hints.TEXT_AREA_WIDTH, mDisplayLines );
    }

    public Integer getTextAreaInitialDisplayLines() {
        return hintOveride( UI.Hints.TEXT_AREA_LINES, mDisplayLines );
    }

    private Integer hintOveride( String pHintName, Integer pCurValue ) {
        Integer override = getIntegerHint( pHintName );
        return (override != null) ? override : pCurValue;
    }

    public Integer getIntegerHint( String pHintName ) {
        String value = ConstrainTo.significantOrNull( getHintValue( pHintName ) );
        if ( value != null ) {
            try {
                return Integer.valueOf( value );
            }
            catch ( NumberFormatException e ) {
                System.err.println( "Hint '" + pHintName + "' Not an Integer: " + value );
            }
        }
        return null;
    }
}

Commits for litesoft/trunk/Java/GWT/OldServer/src/org/litesoft/GWT/forms/server/support/CreateAMDParamsPlus.java

Diff revisions: vs.
Revision Author Commited Message
950 Diff Diff GeorgeS picture GeorgeS Thu 19 Jun, 2014 17:57:04 +0000

New Lines

948 Diff Diff GeorgeS picture GeorgeS Sat 07 Jun, 2014 23:42:39 +0000

Jusefuls Formatter Updated to New Code Format

947 Diff Diff GeorgeS picture GeorgeS Fri 06 Jun, 2014 23:36:56 +0000

Correct Spelling of package!

939 Diff Diff GeorgeS picture GeorgeS Mon 02 Jun, 2014 21:30:31 +0000

Extracting commonfoundation

801 Diff Diff GeorgeS picture GeorgeS Wed 15 Aug, 2012 03:59:02 +0000
60 Diff Diff GeorgeS picture GeorgeS Tue 24 Aug, 2010 00:37:36 +0000
49 Diff Diff GeorgeS picture GeorgeS Mon 12 Apr, 2010 02:59:10 +0000

License Text

2 GeorgeS picture GeorgeS Sun 07 Feb, 2010 12:50:58 +0000