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 14 public class TKSelectField 15 extends TKOptionField 16 { 17 18 21 public static final String CLASS_ID = "SELECT"; 22 public static final String SIZE_KEY = "SIZE"; 23 24 27 public static final int NAME_FIELD_SIZE = 8; 28 29 32 public static final int SIZE_FIELD_SIZE = 2; 33 34 protected int size = 0; 35 36 39 public TKSelectField () 40 { 41 } 43 44 50 public TKSelectField (String name, 51 TKVector optionList) 52 { 53 this(name, null, optionList); 54 } 55 56 63 public TKSelectField (String name, 64 String showName, 65 TKVector optionList) 66 { 67 this(name, showName, optionList, 1, false); 68 } 69 70 78 public TKSelectField (String name, 79 TKVector optionList, 80 int size, 81 boolean multiple) 82 { 83 this(name, null, optionList, size, multiple); 84 } 85 86 95 public TKSelectField (String name, 96 String 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 type, 106 String name, 107 String 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 fieldClass, Object data) 118 throws 119 TKUnregisteredClassException, 120 ClassNotFoundException , 121 InstantiationException , 122 IllegalAccessException  123 { 124 super.init(fieldClass, data); 125 TKHashtable selectData = (TKHashtable) data; 126 size = Integer.parseInt((String ) selectData.get(SIZE_KEY)); 127 } 128 129 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 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 value, String 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 classId, TKFormDBData db, TKVector otherFields) 182 throws 183 TKUnregisteredClassException, 184 ClassNotFoundException , 185 InstantiationException , 186 IllegalAccessException  187 { 188 super.initFromDB(classId, db, otherFields); 189 size = Integer.parseInt(getFieldAttribute(db, SIZE_KEY, 0)); 190 } 191 192 201 public boolean equals (Object 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 218 public int hashCode () 219 { 220 return super.hashCode(); 222 } 223 224 } 225
| Popular Tags
|