001: package com.teamkonzept.field;
002:
003: import com.teamkonzept.lib.*;
004: import com.teamkonzept.web.*;
005: import com.teamkonzept.field.db.*;
006: import com.teamkonzept.international.LanguageManager;
007:
008: /**
009: * The select field control.
010: *
011: * @author $Author: uli $
012: * @version $Revision: 1.17.4.1 $
013: */
014: public class TKSelectField extends TKOptionField {
015:
016: /**
017: * The class identifier.
018: */
019: public static final String CLASS_ID = "SELECT";
020: public static final String SIZE_KEY = "SIZE";
021:
022: /**
023: * The name field size.
024: */
025: public static final int NAME_FIELD_SIZE = 8;
026:
027: /**
028: * The size field size.
029: */
030: public static final int SIZE_FIELD_SIZE = 2;
031:
032: protected int size = 0;
033:
034: /**
035: * Creates an empty select field control.
036: */
037: public TKSelectField() {
038: // NOP
039: }
040:
041: /**
042: * Creates a select field control with the specified properties.
043: *
044: * @param name the field name.
045: * @param optionList the option list.
046: */
047: public TKSelectField(String name, TKVector optionList) {
048: this (name, null, optionList);
049: }
050:
051: /**
052: * Creates a select field control with the specified properties.
053: *
054: * @param name the field name.
055: * @param showName the field description.
056: * @param optionList the option list.
057: */
058: public TKSelectField(String name, String showName,
059: TKVector optionList) {
060: this (name, showName, optionList, 1, false);
061: }
062:
063: /**
064: * Creates a select field control with the specified properties.
065: *
066: * @param name the field name.
067: * @param optionList the option list.
068: * @param size the list size.
069: * @param multiple the field occurrence.
070: */
071: public TKSelectField(String name, TKVector optionList, int size,
072: boolean multiple) {
073: this (name, null, optionList, size, multiple);
074: }
075:
076: /**
077: * Creates a select field control with the specified properties.
078: *
079: * @param name the field name.
080: * @param showName the field description.
081: * @param optionList the option list.
082: * @param size the list size.
083: * @param multiple the field occurrence.
084: */
085: public TKSelectField(String name, String showName,
086: TKVector optionList, int size, boolean multiple) {
087: initSelectField(CLASS_ID, name, showName, optionList, size,
088: multiple);
089: }
090:
091: public final void initSelectField(String type, String name,
092: String showName, TKVector optionList, int size,
093: boolean multiple) {
094: initOptionField(type, name, showName, optionList, multiple);
095: this .size = size;
096: }
097:
098: public void init(String fieldClass, Object data)
099: throws TKUnregisteredClassException,
100: ClassNotFoundException, InstantiationException,
101: IllegalAccessException {
102: super .init(fieldClass, data);
103: TKHashtable selectData = (TKHashtable) data;
104: size = Integer.parseInt((String) selectData.get(SIZE_KEY));
105: }
106:
107: /**
108: * Methode zur Definition alternativer Eingabe-Objekte
109: */
110: public TKFieldGroup getDefGroup(TKFieldSwitch allSwitch,
111: TKFieldSwitchList allSwitchList) {
112:
113: TKVector multipleOptions = new TKVector(2);
114: multipleOptions
115: .addElement(new TKOptionFieldEntry(LanguageManager
116: .getText(LanguageManager.GENERAL, "YES"), "YES"));
117: multipleOptions.addElement(new TKOptionFieldEntry(
118: LanguageManager.getText(LanguageManager.GENERAL, "NO"),
119: "NO"));
120: TKBaseField[] optionArray = {
121: new TKInputField("NAME",
122: TKInputField.SMALL_DEFAULT_SIZE,
123: TKInputField.SMALL_DEFAULT_LENGTH,
124: LanguageManager.getText(LANGUAGE_CONTEXT,
125: "OPTIONFIELD_NAME"),
126: TKInputField.CHECK_STRING),
127: new TKInputField("SHOWNAME",
128: TKInputField.LARGE_DEFAULT_SIZE,
129: TKInputField.LARGE_DEFAULT_LENGTH,
130: LanguageManager.getText(LANGUAGE_CONTEXT,
131: "OPTIONFIELD_SHOWNAME"),
132: TKInputField.CHECK_STRING) };
133: TKFieldGroup optionGroup = new TKFieldGroup("OPTION",
134: new TKVector(optionArray), LanguageManager.getText(
135: LANGUAGE_CONTEXT, "OPTION"));
136:
137: TKBaseField[] selectArray = {
138: new TKInputField("NAME", NAME_FIELD_SIZE,
139: TKInputField.SMALL_DEFAULT_LENGTH,
140: LanguageManager.getText(LANGUAGE_CONTEXT,
141: "SELECT_NAME"),
142: TKInputField.CHECK_STRING),
143: new TKInputField("SHOWNAME",
144: TKInputField.LARGE_DEFAULT_SIZE,
145: TKInputField.LARGE_DEFAULT_LENGTH,
146: LanguageManager.getText(LANGUAGE_CONTEXT,
147: "SELECT_SHOWNAME"),
148: TKInputField.CHECK_STRING),
149: new TKInputField("SIZE", SIZE_FIELD_SIZE,
150: SIZE_FIELD_SIZE, LanguageManager.getText(
151: LANGUAGE_CONTEXT, "SELECT_COUNT"),
152: TKInputField.CHECK_INTEGER),
153: new TKCheckField("MULTIPLE", LanguageManager.getText(
154: LANGUAGE_CONTEXT, "SELECT_MULTIPLE"),
155: multipleOptions, false),
156: new TKFieldList("OPTIONS", optionGroup, LanguageManager
157: .getText(LANGUAGE_CONTEXT, "SELECT_ELEMENTS")) };
158: TKFieldGroup selectGroup = new TKFieldGroup(
159: TKSelectField.CLASS_ID, new TKVector(selectArray),
160: LanguageManager.getText(LANGUAGE_CONTEXT,
161: TKSelectField.CLASS_ID));
162:
163: return selectGroup;
164: }
165:
166: public Object toData() {
167: TKHashtable result = (TKHashtable) super .toData();
168: result.put(SIZE_KEY, String.valueOf(size));
169: return result;
170: }
171:
172: public void fillIntoTemplate(TKHTMLTemplate t, Object value,
173: String prefix) {
174: super .fillIntoTemplate(t, value, prefix);
175: t.set("SIZE", String.valueOf(size));
176: }
177:
178: public int realInsertIntoDB(TKFormDBData db, int formId) {
179: if (super .realInsertIntoDB(db, formId) == -1)
180: return -1;
181:
182: insertNewFieldAttribute(db, formId, SIZE_KEY, 0, String
183: .valueOf(size));
184: return fieldId;
185: }
186:
187: public void initFromDB(String classId, TKFormDBData db,
188: TKVector otherFields) throws TKUnregisteredClassException,
189: ClassNotFoundException, InstantiationException,
190: IllegalAccessException {
191: super .initFromDB(classId, db, otherFields);
192: size = Integer.parseInt(getFieldAttribute(db, SIZE_KEY, 0));
193: }
194:
195: /**
196: * Checks wether this object and the specified object
197: * may be treated as equal.
198: *
199: * @param object the object to checked for equality.
200: * @return <CODE>true</CODE> if this object and the
201: * specified object may be treated as equal, otherwise
202: * <CODE>false</CODE>.
203: */
204: public boolean equals(Object object) {
205: if (!super .equals(object)) {
206: return false;
207: }
208:
209: TKSelectField field = (TKSelectField) object;
210:
211: return (this .size == field.size);
212: }
213:
214: /**
215: * Returns the hash code for this object.
216: *
217: * @return the hash code for this object.
218: */
219: public int hashCode() {
220: // Implementation for JTest only ;-(
221: return super.hashCode();
222: }
223:
224: }
|