KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > util > DisplayType


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2003 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.util;
15
16 import java.text.*;
17 import java.util.*;
18
19 /**
20  * System Display Types.
21  * <pre>
22  * SELECT AD_Reference_ID, Name FROM AD_Reference WHERE ValidationType = 'D'
23  * </pre>
24  * @author Jorg Janke
25  * @version $Id: DisplayType.java,v 1.8 2003/10/08 03:38:29 jjanke Exp $
26  */

27 public final class DisplayType
28 {
29     /** Display Type */
30     public static final int String = 10;
31     /** Display Type */
32     public static final int Integer = 11;
33     /** Display Type */
34     public static final int Amount = 12;
35     /** Display Type */
36     public static final int ID = 13;
37     /** Display Type */
38     public static final int Text = 14;
39     /** Display Type */
40     public static final int Date = 15;
41     /** Display Type */
42     public static final int DateTime = 16;
43     /** Display Type */
44     public static final int List = 17;
45     /** Display Type */
46     public static final int Table = 18;
47     /** Display Type */
48     public static final int TableDir = 19;
49     /** Display Type */
50     public static final int YesNo = 20;
51     /** Display Type */
52     public static final int Location = 21;
53     /** Display Type */
54     public static final int Number = 22;
55     /** Display Type BLOB */
56     public static final int Binary = 23;
57     /** Display Type */
58     public static final int Time = 24;
59     /** Display Type */
60     public static final int Account = 25;
61     /** Display Type */
62     public static final int RowID = 26;
63     /** Display Type */
64     public static final int Color = 27;
65     /** Display Type */
66     public static final int Button = 28;
67     /** Display Type */
68     public static final int Quantity = 29;
69     /** Display Type */
70     public static final int Search = 30;
71     /** Display Type */
72     public static final int Locator = 31;
73     /** Display Type BLOB */
74     public static final int Image = 32;
75     /** DisplayType */
76     public static final int Assignment = 33;
77     /** DisplayType */
78     public static final int Memo = 34;
79     /** DisplayType */
80     public static final int PAttribute = 35;
81     /** DisplayType CLOB */
82     public static final int TextLong = 36;
83
84     /**
85      * - New Display Type
86         INSERT INTO AD_REFERENCE
87         (AD_REFERENCE_ID, AD_CLIENT_ID,AD_ORG_ID,ISACTIVE,CREATED,CREATEDBY,UPDATED,UPDATEDBY,
88         NAME,DESCRIPTION,HELP, VALIDATIONTYPE,VFORMAT,ENTITYTYPE)
89         VALUES (35, 0,0,'Y',SysDate,0,SysDate,0,
90         'PAttribute','Product Attribute',null,'D',null,'D');
91      *
92      * - org.compiere.model.MModel
93      * - org.compiere.grid.ed.VEditor/Dialog
94      * - org.compiere.grid.ed.VEditorFactory
95      * add/check 0_cleanupAD.sql
96      */

97
98     // See DBA_DisplayType.sql ----------------------------------------------
99

100     /** Maximum number of digits */
101     private static final int MAX_DIGITS = 28; // Oracle Standard Limitation 38 digits
102
/** Digits of an Integer */
103     private static final int INTEGER_DIGITS = 10;
104     /** Maximum number of fractions */
105     private static final int MAX_FRACTION = 12;
106     /** Default Amount Precision */
107     private static final int AMOUNT_FRACTION = 2;
108
109     /**
110      * Returns true if (numeric) ID.
111      * (stored as Integer)
112      * @param displayType Display Type
113      * @return true if ID
114      */

115     public static boolean isID (int displayType)
116     {
117         if (displayType == ID || displayType == Table || displayType == TableDir
118             || displayType == Search || displayType == Location || displayType == Locator
119             || displayType == Account || displayType == Assignment || displayType == PAttribute)
120             return true;
121         return false;
122     } // isID
123

124     /**
125      * Returns true, if DisplayType is numeric (Amount, Number, Quantity, Integer).
126      * (stored as BigDecimal)
127      * @param displayType Display Type
128      * @return true if numeric
129      */

130     public static boolean isNumeric(int displayType)
131     {
132         if (displayType == Amount || displayType == Number
133             || displayType == Integer || displayType == Quantity)
134             return true;
135         return false;
136     } // isNumeric
137

138     /**
139      * Returns truem if DisplayType is a Date.
140      * (stored as Timestamp)
141      * @param displayType Display Type
142      * @return true if date
143      */

144     public static boolean isDate (int displayType)
145     {
146         if (displayType == Date || displayType == DateTime || displayType == Time)
147             return true;
148         return false;
149     } // isDate
150

151     /**
152      * Returns true if DisplayType is a VLookup.
153      * (stored as Integer)
154      * @param displayType Display Type
155      * @return true if Lookup
156      */

157     public static boolean isLookup(int displayType)
158     {
159         if (displayType == List || displayType == Table
160             || displayType == TableDir || displayType == Search)
161             return true;
162         return false;
163     } // isLookup
164

165     /*************************************************************************/
166
167     /**
168      * Return Format for numeric DisplayType
169      * @param displayType Display Type (default Number)
170      * @param language Language
171      * @return number format
172      */

173     public static DecimalFormat getNumberFormat(int displayType, Language language)
174     {
175         Language myLanguage = language;
176         if (myLanguage == null)
177             myLanguage = Language.getLanguage();
178         Locale locale = myLanguage.getLocale();
179         DecimalFormat format = null;
180         if (locale != null)
181             format = (DecimalFormat)NumberFormat.getNumberInstance(locale);
182         else
183             format = (DecimalFormat)NumberFormat.getNumberInstance(Locale.US);
184         //
185
if (displayType == Integer)
186         {
187             format.setParseIntegerOnly(true);
188             format.setMaximumIntegerDigits(INTEGER_DIGITS);
189             format.setMaximumFractionDigits(0);
190         }
191         else if (displayType == Quantity)
192         {
193             format.setMaximumIntegerDigits(MAX_DIGITS);
194             format.setMaximumFractionDigits(MAX_FRACTION);
195         }
196         else if (displayType == Amount)
197         {
198             format.setMaximumIntegerDigits(MAX_DIGITS);
199             format.setMaximumFractionDigits(AMOUNT_FRACTION);
200             format.setMinimumFractionDigits(AMOUNT_FRACTION);
201         }
202         else // if (displayType == Number)
203
{
204             format.setMaximumIntegerDigits(MAX_DIGITS);
205             format.setMaximumFractionDigits(MAX_FRACTION);
206             format.setMinimumFractionDigits(1);
207         }
208         return format;
209     } // getDecimalFormat
210

211     /**
212      * Return Format for numeric DisplayType
213      * @param displayType Display Type
214      * @return number format
215      */

216     public static DecimalFormat getNumberFormat(int displayType)
217     {
218         return getNumberFormat (displayType, null);
219     } // getNumberFormat
220

221
222     /*************************************************************************/
223
224     /**
225      * Return Date Format
226      * @return date format
227      */

228     public static SimpleDateFormat getDateFormat()
229     {
230         return getDateFormat (DisplayType.Date, null);
231     } // getDateFormat
232

233     /**
234      * Return Date Format
235      * @param language Language
236      * @return date format
237      */

238     public static SimpleDateFormat getDateFormat (Language language)
239     {
240         return getDateFormat (DisplayType.Date, language);
241     } // getDateFormat
242

243     /**
244      * Return format for date displayType
245      * @param displayType Display Type
246      * @return date format
247      */

248     public static SimpleDateFormat getDateFormat (int displayType)
249     {
250         return getDateFormat (displayType, null);
251     } // getDateFormat
252

253     /**
254      * Return format for date displayType
255      * @param displayType Display Type (default Date)
256      * @param language Language
257      * @return date format
258      */

259     public static SimpleDateFormat getDateFormat (int displayType, Language language)
260     {
261         Language myLanguage = language;
262         if (myLanguage == null)
263             myLanguage = Language.getLanguage();
264         //
265
if (displayType == DateTime)
266             return myLanguage.getDateTimeFormat();
267         else if (displayType == Time)
268             return myLanguage.getTimeFormat();
269     // else if (displayType == Date)
270
return myLanguage.getDateFormat(); // default
271
} // getDateFormat
272

273     /**
274      * JDBC Date Format YYYY-MM-DD
275      * @return date format
276      */

277     static public SimpleDateFormat getDateFormat_JDBC()
278     {
279         return new SimpleDateFormat ("yyyy-MM-dd");
280     } // getDateFormat_JDBC
281

282     /**
283      * Return Storage Class.
284      * (used for MiniTable)
285      * @param displayType Display Type
286      * @param yesNoAsBoolean - yes or no as boolean
287      * @return class Integer - BigDecimal - Timestamp - String - Boolean
288      */

289     public static Class JavaDoc getClass (int displayType, boolean yesNoAsBoolean)
290     {
291         if (displayType == String || displayType == Text || displayType == TextLong
292             || displayType == List || displayType == Memo)
293             return String JavaDoc.class;
294         else if (isID(displayType) || displayType == Integer) // note that Integer is stored as BD
295
return Integer JavaDoc.class;
296         else if (isNumeric(displayType))
297             return java.math.BigDecimal JavaDoc.class;
298         else if (isDate(displayType))
299             return java.sql.Timestamp JavaDoc.class;
300         else if (displayType == YesNo)
301             return yesNoAsBoolean ? Boolean JavaDoc.class : String JavaDoc.class;
302         else if (displayType == Button)
303             return String JavaDoc.class;
304         //
305
return Object JavaDoc.class;
306     } // getClass
307

308 } // DisplayType
309
Popular Tags