KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > cowsultants > itracker > ejb > client > util > CustomFieldUtilities


1 /*
2  * This software was designed and created by Jason Carroll.
3  * Copyright (c) 2002, 2003, 2004 Jason Carroll.
4  * The author can be reached at jcarroll@cowsultants.com
5  * ITracker website: http://www.cowsultants.com
6  * ITracker forums: http://www.cowsultants.com/phpBB/index.php
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it only under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  */

18
19 package cowsultants.itracker.ejb.client.util;
20
21 import java.text.*;
22 import java.util.*;
23
24 import cowsultants.itracker.ejb.client.resources.ITrackerResources;
25
26 public class CustomFieldUtilities {
27     public static final int TYPE_UNKNOWN = -1;
28     public static final int TYPE_STRING = 1;
29     public static final int TYPE_INTEGER = 2;
30     public static final int TYPE_DATE = 3;
31     public static final int TYPE_LIST = 4;
32
33     public static final String JavaDoc DATE_FORMAT_UNKNOWN = "UNKNOWN";
34     public static final String JavaDoc DATE_FORMAT_FULL = "full";
35     public static final String JavaDoc DATE_FORMAT_DATEONLY = "dateonly";
36     public static final String JavaDoc DATE_FORMAT_TIMEONLY = "timeonly";
37
38     /**
39       * Returns the string representation of a field type.
40       * @param type the type to translate
41       * @return a string representation of the field type translated to the specified locale
42       */

43     public static String JavaDoc getTypeString(int type) {
44         return getTypeString(type, ITrackerResources.getLocale());
45     }
46
47     /**
48       * Returns the string representation of a field type.
49       * @param type the type to translate
50       * @param locale the locale to translate the type into
51       * @return a string representation of the field type translated to the default locale
52       */

53     public static String JavaDoc getTypeString(int type, Locale locale) {
54         if(type == TYPE_STRING) {
55             return ITrackerResources.getString(ITrackerResources.KEY_BASE_CUSTOMFIELD_TYPE + "string", locale);
56         } else if(type == TYPE_INTEGER) {
57             return ITrackerResources.getString(ITrackerResources.KEY_BASE_CUSTOMFIELD_TYPE + "integer", locale);
58         } else if(type == TYPE_DATE) {
59             return ITrackerResources.getString(ITrackerResources.KEY_BASE_CUSTOMFIELD_TYPE + "date", locale);
60         } else if(type == TYPE_LIST) {
61             return ITrackerResources.getString(ITrackerResources.KEY_BASE_CUSTOMFIELD_TYPE + "list", locale);
62         }
63
64         return ITrackerResources.getString(ITrackerResources.KEY_BASE_CUSTOMFIELD_TYPE + "unknown", locale);
65     }
66
67     /**
68       * Returns the label key for a particular custom field. This is made up of
69       * a static part and the unique value of the custom field.
70       * @param fieldId the CustomField id to return the label key for
71       * @return the label key for the field
72       */

73     public static String JavaDoc getCustomFieldLabelKey(Integer JavaDoc fieldId) {
74         return ITrackerResources.KEY_BASE_CUSTOMFIELD + fieldId + ITrackerResources.KEY_BASE_CUSTOMFIELD_LABEL;
75     }
76
77     /**
78       * Returns the label key for a particular custom field option. This is made up of
79       * a static part and the unique value of the custom field option.
80       * @param fieldId the CustomField id to return the label key for
81       * @param optionId the CustomField option's id to return the label key for
82       * @return the label key for the field option
83       */

84     public static String JavaDoc getCustomFieldOptionLabelKey(Integer JavaDoc fieldId, Integer JavaDoc optionId) {
85         return ITrackerResources.KEY_BASE_CUSTOMFIELD + fieldId + ITrackerResources.KEY_BASE_CUSTOMFIELD_OPTION + optionId + ITrackerResources.KEY_BASE_CUSTOMFIELD_LABEL;
86     }
87
88     /**
89       * Returns the label for a custom field in the default locale.
90       * @param fieldId the id of the field to return the label for
91       * @return the label for the field translated to the default locale
92       */

93     public static String JavaDoc getCustomFieldName(Integer JavaDoc fieldId) {
94         return getCustomFieldName(fieldId, ITrackerResources.getLocale());
95     }
96
97     /**
98       * Returns the label for a custom field in the specified locale.
99       * @param fieldId the id of the field to return the label for
100       * @param locale the locale to return the label for
101       * @return the label for the field translated to the specified locale
102       */

103     public static String JavaDoc getCustomFieldName(Integer JavaDoc fieldId, Locale locale) {
104         return ITrackerResources.getString(CustomFieldUtilities.getCustomFieldLabelKey(fieldId), locale);
105     }
106
107     /**
108       * Returns the label for a custom field option in the default locale.
109       * @param fieldId the id of the field to return the label for
110       * @param optionId the id of the field option to return the label for
111       * @return the label for the field option translated to the default locale
112       */

113     public static String JavaDoc getCustomFieldOptionName(Integer JavaDoc fieldId, Integer JavaDoc optionId) {
114         return getCustomFieldOptionName(fieldId, optionId, ITrackerResources.getLocale());
115     }
116
117     /**
118       * Returns the label for a custom field option in the specified locale.
119       * @param fieldId the id of the field to return the label for
120       * @param optionId the id of the field option to return the label for
121       * @param locale the locale to return the label for
122       * @return the label for the field option translated to the default locale
123       */

124     public static String JavaDoc getCustomFieldOptionName(Integer JavaDoc fieldId, Integer JavaDoc optionId, Locale locale) {
125         if(fieldId != null && optionId != null) {
126             return ITrackerResources.getString(CustomFieldUtilities.getCustomFieldOptionLabelKey(fieldId, optionId), locale);
127         }
128         return "";
129     }
130 }
131
Popular Tags