KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > teamkonzept > field > TKSelectField


1 package com.teamkonzept.field;
2
3 import com.teamkonzept.lib.*;
4 import com.teamkonzept.web.*;
5 import com.teamkonzept.field.db.*;
6 import com.teamkonzept.international.LanguageManager;
7
8 /**
9  * The select field control.
10  *
11  * @author $Author: uli $
12  * @version $Revision: 1.17.4.1 $
13  */

14 public class TKSelectField
15     extends TKOptionField
16 {
17
18     /**
19      * The class identifier.
20      */

21     public static final String JavaDoc CLASS_ID = "SELECT";
22     public static final String JavaDoc SIZE_KEY = "SIZE";
23
24     /**
25      * The name field size.
26      */

27     public static final int NAME_FIELD_SIZE = 8;
28
29     /**
30      * The size field size.
31      */

32     public static final int SIZE_FIELD_SIZE = 2;
33
34     protected int size = 0;
35
36     /**
37      * Creates an empty select field control.
38      */

39     public TKSelectField ()
40     {
41         // NOP
42
}
43
44     /**
45      * Creates a select field control with the specified properties.
46      *
47      * @param name the field name.
48      * @param optionList the option list.
49      */

50     public TKSelectField (String JavaDoc name,
51                           TKVector optionList)
52     {
53         this(name, null, optionList);
54     }
55
56     /**
57      * Creates a select field control with the specified properties.
58      *
59      * @param name the field name.
60      * @param showName the field description.
61      * @param optionList the option list.
62      */

63     public TKSelectField (String JavaDoc name,
64                           String JavaDoc showName,
65                           TKVector optionList)
66     {
67         this(name, showName, optionList, 1, false);
68     }
69
70     /**
71      * Creates a select field control with the specified properties.
72      *
73      * @param name the field name.
74      * @param optionList the option list.
75      * @param size the list size.
76      * @param multiple the field occurrence.
77      */

78     public TKSelectField (String JavaDoc name,
79                           TKVector optionList,
80                           int size,
81                           boolean multiple)
82     {
83         this(name, null, optionList, size, multiple);
84     }
85
86     /**
87      * Creates a select field control with the specified properties.
88      *
89      * @param name the field name.
90      * @param showName the field description.
91      * @param optionList the option list.
92      * @param size the list size.
93      * @param multiple the field occurrence.
94      */

95     public TKSelectField (String JavaDoc name,
96                           String JavaDoc showName,
97                           TKVector optionList,
98                           int size,
99                           boolean multiple)
100     {
101         initSelectField(CLASS_ID, name, showName, optionList, size, multiple);
102     }
103
104     public final void initSelectField(
105         String JavaDoc type,
106         String JavaDoc name,
107         String JavaDoc showName,
108         TKVector optionList,
109         int size,
110         boolean multiple
111     )
112     {
113         initOptionField(type, name, showName, optionList, multiple);
114         this.size = size;
115     }
116
117     public void init(String JavaDoc fieldClass, Object JavaDoc data)
118         throws
119             TKUnregisteredClassException,
120             ClassNotFoundException JavaDoc,
121             InstantiationException JavaDoc,
122             IllegalAccessException JavaDoc
123     {
124         super.init(fieldClass, data);
125         TKHashtable selectData = (TKHashtable) data;
126         size = Integer.parseInt((String JavaDoc) selectData.get(SIZE_KEY));
127     }
128
129     /**
130      * Methode zur Definition alternativer Eingabe-Objekte
131      */

132     public TKFieldGroup getDefGroup (TKFieldSwitch allSwitch,
133                                      TKFieldSwitchList allSwitchList)
134     {
135
136         TKVector multipleOptions = new TKVector(2);
137         multipleOptions.addElement(new TKOptionFieldEntry(LanguageManager.getText(LanguageManager.GENERAL, "YES"), "YES"));
138         multipleOptions.addElement(new TKOptionFieldEntry(LanguageManager.getText(LanguageManager.GENERAL, "NO"), "NO"));
139         TKBaseField [] optionArray = {
140             new TKInputField("NAME", TKInputField.SMALL_DEFAULT_SIZE, TKInputField.SMALL_DEFAULT_LENGTH, LanguageManager.getText(LANGUAGE_CONTEXT, "OPTIONFIELD_NAME"), TKInputField.CHECK_STRING),
141             new TKInputField("SHOWNAME", TKInputField.LARGE_DEFAULT_SIZE, TKInputField.LARGE_DEFAULT_LENGTH, LanguageManager.getText(LANGUAGE_CONTEXT, "OPTIONFIELD_SHOWNAME"), TKInputField.CHECK_STRING)
142         };
143         TKFieldGroup optionGroup =
144             new TKFieldGroup("OPTION", new TKVector(optionArray), LanguageManager.getText(LANGUAGE_CONTEXT, "OPTION"));
145
146
147         TKBaseField [] selectArray = {
148             new TKInputField("NAME", NAME_FIELD_SIZE, TKInputField.SMALL_DEFAULT_LENGTH, LanguageManager.getText(LANGUAGE_CONTEXT, "SELECT_NAME"), TKInputField.CHECK_STRING),
149             new TKInputField("SHOWNAME", TKInputField.LARGE_DEFAULT_SIZE, TKInputField.LARGE_DEFAULT_LENGTH, LanguageManager.getText(LANGUAGE_CONTEXT, "SELECT_SHOWNAME"), TKInputField.CHECK_STRING),
150             new TKInputField("SIZE", SIZE_FIELD_SIZE, SIZE_FIELD_SIZE, LanguageManager.getText(LANGUAGE_CONTEXT, "SELECT_COUNT"), TKInputField.CHECK_INTEGER),
151             new TKCheckField("MULTIPLE", LanguageManager.getText(LANGUAGE_CONTEXT, "SELECT_MULTIPLE"), multipleOptions, false),
152             new TKFieldList("OPTIONS", optionGroup, LanguageManager.getText(LANGUAGE_CONTEXT, "SELECT_ELEMENTS"))
153         };
154         TKFieldGroup selectGroup =
155             new TKFieldGroup(TKSelectField.CLASS_ID, new TKVector(selectArray), LanguageManager.getText(LANGUAGE_CONTEXT, TKSelectField.CLASS_ID));
156
157         return selectGroup;
158     }
159
160     public Object JavaDoc toData()
161     {
162         TKHashtable result = (TKHashtable) super.toData();
163         result.put(SIZE_KEY, String.valueOf(size));
164         return result;
165     }
166
167     public void fillIntoTemplate(TKHTMLTemplate t, Object JavaDoc value, String JavaDoc prefix)
168     {
169         super.fillIntoTemplate(t, value, prefix);
170         t.set("SIZE", String.valueOf(size));
171     }
172
173     public int realInsertIntoDB(TKFormDBData db, int formId)
174     {
175         if(super.realInsertIntoDB(db, formId) == -1) return -1;
176
177         insertNewFieldAttribute(db, formId, SIZE_KEY, 0, String.valueOf(size));
178         return fieldId;
179     }
180
181     public void initFromDB(String JavaDoc classId, TKFormDBData db, TKVector otherFields)
182         throws
183             TKUnregisteredClassException,
184             ClassNotFoundException JavaDoc,
185             InstantiationException JavaDoc,
186             IllegalAccessException JavaDoc
187     {
188         super.initFromDB(classId, db, otherFields);
189         size = Integer.parseInt(getFieldAttribute(db, SIZE_KEY, 0));
190     }
191
192     /**
193      * Checks wether this object and the specified object
194      * may be treated as equal.
195      *
196      * @param object the object to checked for equality.
197      * @return <CODE>true</CODE> if this object and the
198      * specified object may be treated as equal, otherwise
199      * <CODE>false</CODE>.
200      */

201     public boolean equals (Object JavaDoc object)
202     {
203         if (! super.equals(object))
204         {
205             return false;
206         }
207
208         TKSelectField field = (TKSelectField) object;
209
210         return (this.size == field.size);
211     }
212
213     /**
214      * Returns the hash code for this object.
215      *
216      * @return the hash code for this object.
217      */

218     public int hashCode ()
219     {
220         // Implementation for JTest only ;-(
221
return super.hashCode();
222     }
223
224 }
225
Popular Tags