Subversion Repository Public Repository

litesoft

Diff Revisions 949 vs 950 for /trunk/Java/GWT/OldServer/src/org/litesoft/GWT/forms/server/support/CreateAMDParamsPlus.java

Diff revisions: vs.
  @@ -1,220 +1,220 @@
1 - // This Source Code is in the Public Domain per: http://unlicense.org
2 - package org.litesoft.GWT.forms.server.support;
3 -
4 - import org.litesoft.GWT.forms.server.*;
5 - import org.litesoft.commonfoundation.typeutils.*;
6 - import org.litesoft.configuration.*;
7 - import org.litesoft.core.util.*;
8 - import org.litesoft.orsup.base.*;
9 - import org.litesoft.ui_1_5.def.*;
10 - import org.litesoft.util.*;
11 -
12 - public class CreateAMDParamsPlus extends CreateAMDParams {
13 - public static final Configuration.CachedConfigInt DEFAULT_SHORT_DISPLAY_CHARS_WIDTH = //
14 - new Configuration.CachedConfigInt( "DefaultShortDisplayCharsWidth", 3 );
15 -
16 - public static final Configuration.CachedConfigInt DEFAULT_INTEGER_DISPLAY_CHARS_WIDTH = //
17 - new Configuration.CachedConfigInt( "DefaultIntegerDisplayCharsWidth", 8 );
18 -
19 - public static final Configuration.CachedConfigInt DEFAULT_LONG_DISPLAY_CHARS_WIDTH = //
20 - new Configuration.CachedConfigInt( "DefaultLongDisplayCharsWidth", 15 );
21 -
22 - public static final Configuration.CachedConfigInt DEFAULT_FIXED_PLONG_DISPLAY_CHARS_WIDTH = //
23 - new Configuration.CachedConfigInt( "DefaultFixedPLongDisplayCharsWidth", 15 );
24 -
25 - public static final Configuration.CachedConfigInt DEFAULT_FLOATING_PLONG_DISPLAY_CHARS_WIDTH = //
26 - new Configuration.CachedConfigInt( "DefaultFloatingPLongDisplayCharsWidth", 15 );
27 -
28 - public static final Configuration.CachedConfigInt DEFAULT_FLOAT_DISPLAY_CHARS_WIDTH = //
29 - new Configuration.CachedConfigInt( "DefaultFloatDisplayCharsWidth", 15 );
30 -
31 - public static final Configuration.CachedConfigInt DEFAULT_DOUBLE_DISPLAY_CHARS_WIDTH = //
32 - new Configuration.CachedConfigInt( "DefaultDoubleDisplayCharsWidth", 20 );
33 -
34 - public static final Configuration.CachedConfigInt DEFAULT_MONEY_DISPLAY_CHARS_WIDTH = //
35 - new Configuration.CachedConfigInt( "DefaultMoneyDisplayCharsWidth", 15 );
36 -
37 - private static final Configuration.CachedConfigInt DEFAULT_TEXT_FIELD_DISPLAY_CHARS_WIDTH = //
38 - new Configuration.CachedConfigInt( "DefaultTextFieldDisplayCharsWidth", 20 );
39 -
40 - private static final Configuration.CachedConfigInt DEFAULT_PASSWORD_FIELD_DISPLAY_CHARS_WIDTH = //
41 - new Configuration.CachedConfigInt( "DefaultPasswordFieldDisplayCharsWidth", 10 );
42 -
43 - private static final Configuration.CachedConfigInt MAX_CHARS_FOR_TEXT_FIELD = //
44 - new Configuration.CachedConfigInt( "MaxCharsForTextField", 255 );
45 -
46 - private static final Configuration.CachedConfigInt MAX_DEFAULT_DISPLAY_CHARS_WIDTH_FOR_TEXT_FIELD_BEFORE_FLOODX = //
47 - new Configuration.CachedConfigInt( "MaxDefaultDisplayCharsWidthForTextFieldBeforeFloodX", 80 );
48 -
49 - protected HintManager mHintManager;
50 -
51 - protected boolean mRequired;
52 - protected boolean mDisabled;
53 - protected boolean mHide;
54 -
55 - protected Integer mMaxChars;
56 -
57 - protected Integer mDisplayLines, mDisplayCharsWidth;
58 -
59 - protected void apply( HintManager pAttributeHintManager, //
60 - boolean pRequired, boolean pDisabled, boolean pHide, //
61 - Integer pMaxChars, Integer pDisplayLines, Integer pDisplayCharsWidth ) {
62 - mHintManager = HintController.getGlobalHintManager().addAll( pAttributeHintManager ).addAll(
63 - getUsage().getHints() );
64 -
65 - mRequired = mergeRequired( pRequired, getUsage().getRequired() );
66 - mDisabled = pDisabled || getUsage().shouldComponentBeDisabled();
67 - mHide = pHide || getUsage().shouldDataBeHiden();
68 - switch ( getField() ) {
69 - default:
70 - case ViewHide:
71 - mHide = true;
72 - // Fall Thru
73 - case ViewOnly:
74 - mDisabled = true;
75 - break;
76 - case EditHide:
77 - mHide = true;
78 - break;
79 - case Editable:
80 - break;
81 - }
82 -
83 - mMaxChars = pMaxChars;
84 - if ( (mMaxChars != null) && (mMaxChars < 1) ) {
85 - mMaxChars = null;
86 - }
87 -
88 - mDisplayLines = pDisplayLines;
89 -
90 - if ( (mDisplayCharsWidth != null) && (mDisplayCharsWidth < 1) ) {
91 - mDisplayCharsWidth = null;
92 - }
93 - mDisplayCharsWidth = pDisplayCharsWidth;
94 - }
95 -
96 - protected boolean mergeRequired( boolean pServiceSaysRequired, Boolean pUsageSaysRequired ) {
97 - return (pUsageSaysRequired == null) ? pServiceSaysRequired : pUsageSaysRequired;
98 - }
99 -
100 - public CreateAMDParamsPlus( CreateAMDParams pParams, HintManager pAttributeHintManager, //
101 - boolean pRequired, boolean pDisabled, boolean pHide, //
102 - Integer pMaxChars, Integer pDisplayLines, Integer pDisplayCharsWidth ) {
103 - super( pParams );
104 - apply( pAttributeHintManager, //
105 - pRequired, pDisabled, pHide, //
106 - pMaxChars, pDisplayLines, pDisplayCharsWidth );
107 - }
108 -
109 - public CreateAMDParamsPlus( CreateAMDParams pParams, AttributeAccessorSCD pSCD ) {
110 - super( pParams );
111 - // todo: translate:
112 - // apply( pSCD.getHintManager(), //
113 - // pSCD.isRequired(), //
114 - // Boolean.FALSE.equals( pSCD.getBooleanProperty( AttributeAccessorSCD.EDITABLE_PROPERTY ) ), //
115 - // Boolean.TRUE.equals( pSCD.getBooleanProperty( AttributeAccessorSCD.HIDE_PROPERTY ) ), //
116 - // pSCD.getIntegerProperty( AttributeAccessorSCD.LENGTH_PROPERTY ), // MaxChars;
117 - // pSCD.getIntegerProperty( AttributeAccessorSCD.DISPLAY_LINES_PROPERTY ),
118 - // pSCD.getIntegerProperty( AttributeAccessorSCD.DISPLAY_COLUMNS_PROPERTY ) );
119 - }
120 -
121 - public boolean isRequired() {
122 - return mRequired;
123 - }
124 -
125 - public boolean isDisabled() {
126 - return mDisabled;
127 - }
128 -
129 - public boolean isHide() {
130 - return mHide;
131 - }
132 -
133 - public Hintable.Hint[] getHints() {
134 - return mHintManager.getHints();
135 - }
136 -
137 - public String getHintValue( String pName ) {
138 - return mHintManager.getHintValue( pName );
139 - }
140 -
141 - public String getHintValue( String pName, String pDefaultIfNullOrEmpty ) {
142 - return mHintManager.getHintValue( pName, pDefaultIfNullOrEmpty );
143 - }
144 -
145 - public boolean isEditRequired() {
146 - return isRequired() && getUsage().getIntendedUse().isEdit();
147 - }
148 -
149 - public String resolveAction( String pActionID ) {
150 - return mExternalization.resolveAction( pActionID );
151 - }
152 -
153 - public String getErrorTextForRequired() {
154 - return isRequired() ? error( FormServicePeer.IS_REQUIRED_ERROR_KEY, getFieldLabel() ) : null;
155 - }
156 -
157 - public String error( String pErrorKey, String... pToInject ) {
158 - return SimpleMessage.format( mExternalization.resolveError( pErrorKey ), (Object[]) pToInject );
159 - }
160 -
161 - public Integer getMaxChars() {
162 - return mMaxChars;
163 - }
164 -
165 - public Integer getDisplayLines() {
166 - return mDisplayLines;
167 - }
168 -
169 - public Integer getDisplayCharsWidth() {
170 - return mDisplayCharsWidth;
171 - }
172 -
173 - public boolean shouldBeTextArea() {
174 - return ((mMaxChars == null) || (mMaxChars > MAX_CHARS_FOR_TEXT_FIELD.getInteger()) ||
175 - UI.Hints.CF_TEXT_AREA.equals( getHintValue( UI.Hints.COMPONENT_FORM ) ));
176 - }
177 -
178 - public Integer getPasswordDisplayCharsWidth() {
179 - return oneLineHintOveride( DEFAULT_PASSWORD_FIELD_DISPLAY_CHARS_WIDTH );
180 - }
181 -
182 - public Integer getTextFieldDisplayCharsWidth() {
183 - return oneLineHintOveride( DEFAULT_TEXT_FIELD_DISPLAY_CHARS_WIDTH );
184 - }
185 -
186 - public Integer oneLineHintOveride( Configuration.CachedConfigInt pCachedConfigInt ) {
187 - Integer width = hintOveride( UI.Hints.TEXT_FIELD_WIDTH, mDisplayCharsWidth );
188 - if ( width == null ) {
189 - width = (mMaxChars == null) ? pCachedConfigInt.getInteger() : (mMaxChars + 1);
190 - }
191 - return (width <= MAX_DEFAULT_DISPLAY_CHARS_WIDTH_FOR_TEXT_FIELD_BEFORE_FLOODX.getInteger()) ? //
192 - width : null;
193 - }
194 -
195 - public Integer getTextAreaInitialDisplayCharsWidth() {
196 - return hintOveride( UI.Hints.TEXT_AREA_WIDTH, mDisplayLines );
197 - }
198 -
199 - public Integer getTextAreaInitialDisplayLines() {
200 - return hintOveride( UI.Hints.TEXT_AREA_LINES, mDisplayLines );
201 - }
202 -
203 - private Integer hintOveride( String pHintName, Integer pCurValue ) {
204 - Integer override = getIntegerHint( pHintName );
205 - return (override != null) ? override : pCurValue;
206 - }
207 -
208 - public Integer getIntegerHint( String pHintName ) {
209 - String value = Strings.noEmpty( getHintValue( pHintName ) );
210 - if ( value != null ) {
211 - try {
212 - return Integer.valueOf( value );
213 - }
214 - catch ( NumberFormatException e ) {
215 - System.err.println( "Hint '" + pHintName + "' Not an Integer: " + value );
216 - }
217 - }
218 - return null;
219 - }
220 - }
1 + // This Source Code is in the Public Domain per: http://unlicense.org
2 + package org.litesoft.GWT.forms.server.support;
3 +
4 + import org.litesoft.GWT.forms.server.*;
5 + import org.litesoft.commonfoundation.base.*;
6 + import org.litesoft.configuration.*;
7 + import org.litesoft.core.util.*;
8 + import org.litesoft.orsup.base.*;
9 + import org.litesoft.ui_1_5.def.*;
10 + import org.litesoft.util.*;
11 +
12 + public class CreateAMDParamsPlus extends CreateAMDParams {
13 + public static final Configuration.CachedConfigInt DEFAULT_SHORT_DISPLAY_CHARS_WIDTH = //
14 + new Configuration.CachedConfigInt( "DefaultShortDisplayCharsWidth", 3 );
15 +
16 + public static final Configuration.CachedConfigInt DEFAULT_INTEGER_DISPLAY_CHARS_WIDTH = //
17 + new Configuration.CachedConfigInt( "DefaultIntegerDisplayCharsWidth", 8 );
18 +
19 + public static final Configuration.CachedConfigInt DEFAULT_LONG_DISPLAY_CHARS_WIDTH = //
20 + new Configuration.CachedConfigInt( "DefaultLongDisplayCharsWidth", 15 );
21 +
22 + public static final Configuration.CachedConfigInt DEFAULT_FIXED_PLONG_DISPLAY_CHARS_WIDTH = //
23 + new Configuration.CachedConfigInt( "DefaultFixedPLongDisplayCharsWidth", 15 );
24 +
25 + public static final Configuration.CachedConfigInt DEFAULT_FLOATING_PLONG_DISPLAY_CHARS_WIDTH = //
26 + new Configuration.CachedConfigInt( "DefaultFloatingPLongDisplayCharsWidth", 15 );
27 +
28 + public static final Configuration.CachedConfigInt DEFAULT_FLOAT_DISPLAY_CHARS_WIDTH = //
29 + new Configuration.CachedConfigInt( "DefaultFloatDisplayCharsWidth", 15 );
30 +
31 + public static final Configuration.CachedConfigInt DEFAULT_DOUBLE_DISPLAY_CHARS_WIDTH = //
32 + new Configuration.CachedConfigInt( "DefaultDoubleDisplayCharsWidth", 20 );
33 +
34 + public static final Configuration.CachedConfigInt DEFAULT_MONEY_DISPLAY_CHARS_WIDTH = //
35 + new Configuration.CachedConfigInt( "DefaultMoneyDisplayCharsWidth", 15 );
36 +
37 + private static final Configuration.CachedConfigInt DEFAULT_TEXT_FIELD_DISPLAY_CHARS_WIDTH = //
38 + new Configuration.CachedConfigInt( "DefaultTextFieldDisplayCharsWidth", 20 );
39 +
40 + private static final Configuration.CachedConfigInt DEFAULT_PASSWORD_FIELD_DISPLAY_CHARS_WIDTH = //
41 + new Configuration.CachedConfigInt( "DefaultPasswordFieldDisplayCharsWidth", 10 );
42 +
43 + private static final Configuration.CachedConfigInt MAX_CHARS_FOR_TEXT_FIELD = //
44 + new Configuration.CachedConfigInt( "MaxCharsForTextField", 255 );
45 +
46 + private static final Configuration.CachedConfigInt MAX_DEFAULT_DISPLAY_CHARS_WIDTH_FOR_TEXT_FIELD_BEFORE_FLOODX = //
47 + new Configuration.CachedConfigInt( "MaxDefaultDisplayCharsWidthForTextFieldBeforeFloodX", 80 );
48 +
49 + protected HintManager mHintManager;
50 +
51 + protected boolean mRequired;
52 + protected boolean mDisabled;
53 + protected boolean mHide;
54 +
55 + protected Integer mMaxChars;
56 +
57 + protected Integer mDisplayLines, mDisplayCharsWidth;
58 +
59 + protected void apply( HintManager pAttributeHintManager, //
60 + boolean pRequired, boolean pDisabled, boolean pHide, //
61 + Integer pMaxChars, Integer pDisplayLines, Integer pDisplayCharsWidth ) {
62 + mHintManager = HintController.getGlobalHintManager().addAll( pAttributeHintManager ).addAll(
63 + getUsage().getHints() );
64 +
65 + mRequired = mergeRequired( pRequired, getUsage().getRequired() );
66 + mDisabled = pDisabled || getUsage().shouldComponentBeDisabled();
67 + mHide = pHide || getUsage().shouldDataBeHiden();
68 + switch ( getField() ) {
69 + default:
70 + case ViewHide:
71 + mHide = true;
72 + // Fall Thru
73 + case ViewOnly:
74 + mDisabled = true;
75 + break;
76 + case EditHide:
77 + mHide = true;
78 + break;
79 + case Editable:
80 + break;
81 + }
82 +
83 + mMaxChars = pMaxChars;
84 + if ( (mMaxChars != null) && (mMaxChars < 1) ) {
85 + mMaxChars = null;
86 + }
87 +
88 + mDisplayLines = pDisplayLines;
89 +
90 + if ( (mDisplayCharsWidth != null) && (mDisplayCharsWidth < 1) ) {
91 + mDisplayCharsWidth = null;
92 + }
93 + mDisplayCharsWidth = pDisplayCharsWidth;
94 + }
95 +
96 + protected boolean mergeRequired( boolean pServiceSaysRequired, Boolean pUsageSaysRequired ) {
97 + return (pUsageSaysRequired == null) ? pServiceSaysRequired : pUsageSaysRequired;
98 + }
99 +
100 + public CreateAMDParamsPlus( CreateAMDParams pParams, HintManager pAttributeHintManager, //
101 + boolean pRequired, boolean pDisabled, boolean pHide, //
102 + Integer pMaxChars, Integer pDisplayLines, Integer pDisplayCharsWidth ) {
103 + super( pParams );
104 + apply( pAttributeHintManager, //
105 + pRequired, pDisabled, pHide, //
106 + pMaxChars, pDisplayLines, pDisplayCharsWidth );
107 + }
108 +
109 + public CreateAMDParamsPlus( CreateAMDParams pParams, AttributeAccessorSCD pSCD ) {
110 + super( pParams );
111 + // todo: translate:
112 + // apply( pSCD.getHintManager(), //
113 + // pSCD.isRequired(), //
114 + // Boolean.FALSE.equals( pSCD.getBooleanProperty( AttributeAccessorSCD.EDITABLE_PROPERTY ) ), //
115 + // Boolean.TRUE.equals( pSCD.getBooleanProperty( AttributeAccessorSCD.HIDE_PROPERTY ) ), //
116 + // pSCD.getIntegerProperty( AttributeAccessorSCD.LENGTH_PROPERTY ), // MaxChars;
117 + // pSCD.getIntegerProperty( AttributeAccessorSCD.DISPLAY_LINES_PROPERTY ),
118 + // pSCD.getIntegerProperty( AttributeAccessorSCD.DISPLAY_COLUMNS_PROPERTY ) );
119 + }
120 +
121 + public boolean isRequired() {
122 + return mRequired;
123 + }
124 +
125 + public boolean isDisabled() {
126 + return mDisabled;
127 + }
128 +
129 + public boolean isHide() {
130 + return mHide;
131 + }
132 +
133 + public Hintable.Hint[] getHints() {
134 + return mHintManager.getHints();
135 + }
136 +
137 + public String getHintValue( String pName ) {
138 + return mHintManager.getHintValue( pName );
139 + }
140 +
141 + public String getHintValue( String pName, String pDefaultIfNullOrEmpty ) {
142 + return mHintManager.getHintValue( pName, pDefaultIfNullOrEmpty );
143 + }
144 +
145 + public boolean isEditRequired() {
146 + return isRequired() && getUsage().getIntendedUse().isEdit();
147 + }
148 +
149 + public String resolveAction( String pActionID ) {
150 + return mExternalization.resolveAction( pActionID );
151 + }
152 +
153 + public String getErrorTextForRequired() {
154 + return isRequired() ? error( FormServicePeer.IS_REQUIRED_ERROR_KEY, getFieldLabel() ) : null;
155 + }
156 +
157 + public String error( String pErrorKey, String... pToInject ) {
158 + return SimpleMessage.format( mExternalization.resolveError( pErrorKey ), (Object[]) pToInject );
159 + }
160 +
161 + public Integer getMaxChars() {
162 + return mMaxChars;
163 + }
164 +
165 + public Integer getDisplayLines() {
166 + return mDisplayLines;
167 + }
168 +
169 + public Integer getDisplayCharsWidth() {
170 + return mDisplayCharsWidth;
171 + }
172 +
173 + public boolean shouldBeTextArea() {
174 + return ((mMaxChars == null) || (mMaxChars > MAX_CHARS_FOR_TEXT_FIELD.getInteger()) ||
175 + UI.Hints.CF_TEXT_AREA.equals( getHintValue( UI.Hints.COMPONENT_FORM ) ));
176 + }
177 +
178 + public Integer getPasswordDisplayCharsWidth() {
179 + return oneLineHintOveride( DEFAULT_PASSWORD_FIELD_DISPLAY_CHARS_WIDTH );
180 + }
181 +
182 + public Integer getTextFieldDisplayCharsWidth() {
183 + return oneLineHintOveride( DEFAULT_TEXT_FIELD_DISPLAY_CHARS_WIDTH );
184 + }
185 +
186 + public Integer oneLineHintOveride( Configuration.CachedConfigInt pCachedConfigInt ) {
187 + Integer width = hintOveride( UI.Hints.TEXT_FIELD_WIDTH, mDisplayCharsWidth );
188 + if ( width == null ) {
189 + width = (mMaxChars == null) ? pCachedConfigInt.getInteger() : (mMaxChars + 1);
190 + }
191 + return (width <= MAX_DEFAULT_DISPLAY_CHARS_WIDTH_FOR_TEXT_FIELD_BEFORE_FLOODX.getInteger()) ? //
192 + width : null;
193 + }
194 +
195 + public Integer getTextAreaInitialDisplayCharsWidth() {
196 + return hintOveride( UI.Hints.TEXT_AREA_WIDTH, mDisplayLines );
197 + }
198 +
199 + public Integer getTextAreaInitialDisplayLines() {
200 + return hintOveride( UI.Hints.TEXT_AREA_LINES, mDisplayLines );
201 + }
202 +
203 + private Integer hintOveride( String pHintName, Integer pCurValue ) {
204 + Integer override = getIntegerHint( pHintName );
205 + return (override != null) ? override : pCurValue;
206 + }
207 +
208 + public Integer getIntegerHint( String pHintName ) {
209 + String value = ConstrainTo.significantOrNull( getHintValue( pHintName ) );
210 + if ( value != null ) {
211 + try {
212 + return Integer.valueOf( value );
213 + }
214 + catch ( NumberFormatException e ) {
215 + System.err.println( "Hint '" + pHintName + "' Not an Integer: " + value );
216 + }
217 + }
218 + return null;
219 + }
220 + }