1 package com.teamkonzept.field; 2 3 import java.util.Enumeration ; 4 import java.util.StringTokenizer ; 5 import com.teamkonzept.lib.*; 6 import com.teamkonzept.publishing.markups.*; 7 import com.teamkonzept.web.*; 8 import com.teamkonzept.field.db.*; 9 import org.w3c.dom.*; 10 11 17 public abstract class TKFieldTableOriented 18 extends TKBaseField 19 { 20 22 public static final String SUB_FIELD_KEY = "SUBFIELD"; 23 24 public static final String ROW_ENTRY_KEY = "ROWENTRY"; 25 public static final String COL_ENTRY_KEY = "COLENTRY"; 26 27 public static final String IS_ROWENTRY_KEY = "IS_ROWENTRY"; 28 public static final String IS_COLENTRY_KEY = "IS_COLENTRY"; 29 public static final String ROW_JANEIN_KEY = "JANEINZEILE"; 30 public static final String COL_JANEIN_KEY = "JANEINSPALTE"; 31 32 public static final String ZUSATZ_KEY = "ZUSATZ"; 33 public static final String CELLINFO_KEY = "CELL"; 34 public static final String NOCELLINFO_KEY = "NOCELL"; 35 public static final String BOOL_ZUSATZ_ROW = "BOOLZUSATZROW"; 36 public static final String BOOL_ZUSATZ_COL = "BOOLZUSATZCOL"; 37 38 public static final String PRE_COLS = "COL"; 39 public static final String PRE_ROWS = "ROW"; 40 41 42 public boolean isRowCell; 43 44 public boolean isColCell; 45 46 TKBaseField rowEntry; 47 TKBaseField colEntry; 48 49 TKVector fieldList; 50 TKHashtable tableFields; 51 52 55 public TKFieldTableOriented () 56 { 57 } 59 60 68 public TKFieldTableOriented (String fieldType, 69 String name, 70 TKVector fields) 71 { 72 this(fieldType, name, fields, null, null); 73 } 74 75 85 public TKFieldTableOriented (String fieldType, 86 String name, 87 TKVector fields, 88 TKBaseField rowEntry, 89 TKBaseField colEntry) 90 { 91 this(fieldType, name, fields, rowEntry, colEntry, null); 92 } 93 94 105 public TKFieldTableOriented (String fieldType, 106 String name, 107 TKVector fields, 108 TKBaseField rowEntry, 109 TKBaseField colEntry, 110 String showName) 111 { 112 initFieldTableOriented(fieldType, name, fields, rowEntry, colEntry, showName); 113 } 114 115 public final void initFieldTableOriented( 116 String fieldType, 117 String name, 118 TKVector fields, 119 TKBaseField rowEntry, 120 TKBaseField colEntry , 121 String showName ) 122 { 123 initBaseField( fieldType, name, showName ); 124 this.fieldList = fields; 125 this.tableFields = getFieldHashFromList( fields ); 126 this.rowEntry = rowEntry; 127 this.colEntry = colEntry; 128 } 129 130 131 public void init( String fieldType, Object data ) 132 throws 133 TKUnregisteredClassException, 134 ClassNotFoundException , 135 InstantiationException , 136 IllegalAccessException  137 { 138 super.init( fieldType, data ); 139 TKHashtable tableData = (TKHashtable) data; 140 this.fieldList = getListOfFields( 141 (TKFieldSwitchListData) tableData.get( SUB_LIST_KEY ) 142 ); 143 this.tableFields = getFieldHashFromList( fieldList ); 144 TKFieldOptionData rowData = (TKFieldOptionData)tableData.get(ROW_JANEIN_KEY); 148 initSubFields(rowData, true); 149 150 TKFieldOptionData colData= (TKFieldOptionData)tableData.get(COL_JANEIN_KEY); 154 initSubFields(colData, false); 155 } 156 157 160 public void initSubFields(TKFieldOptionData optionData, boolean initRow) 161 throws 162 TKUnregisteredClassException, 163 ClassNotFoundException , 164 InstantiationException , 165 IllegalAccessException  166 167 { 168 169 if(optionData.data != null) { 170 TKHashtable optionDataHash = (TKHashtable) optionData.data; 171 172 String selectedVal = (String ) optionDataHash.get(ZUSATZ_KEY); 176 177 if(initRow) { 178 if(selectedVal.equals(CELLINFO_KEY)) this.isRowCell = true; 179 else this.isRowCell = false; 180 } 181 else { 182 if(selectedVal.equals(CELLINFO_KEY)) this.isColCell = true; 183 else this.isColCell = false; 184 } 185 186 TKFieldSwitchData subType = (TKFieldSwitchData) optionDataHash.get(SUB_TYPE_KEY); 187 188 if( subType.alternative.length() == 0 ) 189 throw new InstantiationException ( "no tabletype for "+fieldType+" "+fieldName ); 190 if(initRow) { 191 this.rowEntry = (TKBaseField) 192 TKFieldRegistry.registry.get( subType.alternative, subType.data ); 193 } 194 else { 195 this.colEntry = (TKBaseField) 196 TKFieldRegistry.registry.get( subType.alternative, subType.data ); 197 } 198 199 } 200 else { 201 if(initRow) { 202 rowEntry = null; 203 } 204 else { 205 colEntry = null; 206 } 207 } 208 } 209 210 215 public Object toData () 216 { 217 TKHashtable result = (TKHashtable) super.toData(); 218 result.put( SUB_LIST_KEY, getDataOfAlternatives( fieldList ) ); 219 220 TKFieldOptionData rowEntryOption = null; 224 result = toDataSubFields(rowEntryOption, rowEntry, result, "row"); 225 226 TKFieldOptionData colEntryOption = null; 230 result = toDataSubFields(colEntryOption, colEntry, result, "col"); 231 return result; 232 } 233 234 237 public TKHashtable toDataSubFields( 238 TKFieldOptionData entryOption, 239 TKBaseField rowOrColEntry, 240 TKHashtable result, 241 String rowOrCol) 242 { 243 if(rowOrColEntry != null) { 244 TKHashtable groupData = new TKHashtable(); 249 groupData.put( 250 SUB_TYPE_KEY, 251 new TKFieldSwitchData( rowOrColEntry.getType(), rowOrColEntry.getType(), rowOrColEntry.toData() ) 252 ); 253 if( rowOrCol.equals("row")) { 258 if(isRowCell ) 259 { 260 groupData.put(ZUSATZ_KEY, "CELL"); 261 } 262 else 263 { 264 groupData.put(ZUSATZ_KEY, "NOCELL"); 265 } 266 } 267 268 if( rowOrCol.equals("col")) { 269 if(isColCell) 270 { 271 groupData.put(ZUSATZ_KEY, "CELL"); 272 } 273 else 274 { 275 groupData.put(ZUSATZ_KEY, "NOCELL"); 276 } 277 } 278 279 entryOption = new TKFieldOptionData( "YES", "YES", groupData ); 283 } 284 else { 285 entryOption = new TKFieldOptionData( "NO", "NO", null) ; 286 } 287 if( rowOrCol.equals("row")) result.put( ROW_JANEIN_KEY, entryOption); 288 if( rowOrCol.equals("col")) result.put( COL_JANEIN_KEY, entryOption); 289 290 return result; 291 } 292 293 public final String subPrefix( String prefix ) 294 { 295 return prefix+fieldName+"."; 296 } 297 298 public TKBaseField getTarget(String fieldPath, String prefix) 299 { 300 TKBaseField targetField = null; 301 int pLength = prefix.length()+fieldName.length(); 302 303 if ( (fieldPath.length() != pLength) && (fieldPath.length()-3 != pLength) ) 307 { 308 String subZusatz = fieldPath.substring( pLength+1); 309 if( subZusatz.startsWith( PRE_ROWS ) ) { 310 subZusatz = subZusatz.substring( PRE_ROWS.length()+1 ); 311 int idxEnd = subZusatz.indexOf('.'); 312 String idxStr = subZusatz.substring( 0, idxEnd ); 313 int idx = Integer.parseInt( idxStr ); 314 315 targetField = rowEntry.getTarget(fieldPath, prefix+fieldName+'.'+PRE_ROWS+"."+idx+'.'); 316 317 } 318 else if( subZusatz.startsWith( PRE_COLS ) ) { 320 subZusatz = subZusatz.substring( PRE_COLS.length()+1 ); 321 int idxEnd = subZusatz.indexOf('.'); 322 String idxStr = subZusatz.substring( 0, idxEnd ); 323 int idx = Integer.parseInt( idxStr ); 324 325 targetField = colEntry.getTarget(fieldPath, prefix+fieldName+'.'+PRE_COLS+"."+idx+'.'); 326 327 } 328 else { 330 String subName = fieldPath.substring( pLength+5); 331 TKBaseField field = (TKBaseField) tableFields.get( subName ); 332 333 String subPath = fieldPath.substring( pLength+1); 334 StringTokenizer getToken = new StringTokenizer (subPath, "."); 335 int rowIdx = Integer.parseInt( (String ) getToken.nextElement() ); 336 int colIdx = Integer.parseInt( (String ) getToken.nextElement() ); 337 field = (TKBaseField) fieldList.get( colIdx ); 338 targetField = field.getTarget(fieldPath, prefix+fieldName+"."+rowIdx+"."+colIdx+"."); 339 } 340 } 341 return targetField; 342 } 343 344 public void fillIntoTemplate( TKHTMLTemplate t, Object data, String prefix ) 345 { 346 super.fillIntoTemplate( t, data, prefix ); 347 } 348 349 350 public void fillIntoDOM(Document doc, Element node, Object data) throws DOMException 351 { 352 Element me = doc.createElement(getInternationalName()); 353 node.appendChild(me); 354 fillAttributesIntoNode(me, data); 355 } 357 358 public abstract Object compileData( String prefix, TKHashtable data, TKHashtable context ); 359 360 public abstract Object compileData( String prefix, TKMarkupNode data, TKHashtable context ); 361 362 public Object getDefault() 363 { 364 return new TKFieldTableOrientedData(null, null, null); 365 } 366 367 public void clearId() 368 { 369 if( fieldId == -1 ) return; 370 371 fieldId = -1; 372 Enumeration e = fieldList.elements(); 373 while( e.hasMoreElements() ) { 374 ((TKBaseField) e.nextElement()).clearId(); 375 } 376 if(rowEntry != null) rowEntry.clearId(); 377 if(colEntry != null) colEntry.clearId(); 378 379 } 380 381 382 public int realInsertIntoDB( TKFormDBData db, int formId ) 384 { 385 if( super.realInsertIntoDB( db, formId ) == -1 ) return -1; 387 388 insertNewSubFieldList( db, formId, SUB_FIELD_KEY, fieldList ); 389 390 391 if(rowEntry != null) 396 insertNewFieldAttribute( db, formId, IS_ROWENTRY_KEY, 0, String.valueOf(1) ); 397 else 398 insertNewFieldAttribute( db, formId, IS_ROWENTRY_KEY, 0, String.valueOf(0) ); 399 400 if(colEntry != null) 401 insertNewFieldAttribute( db, formId, IS_COLENTRY_KEY, 0, String.valueOf(1) ); 402 else 403 insertNewFieldAttribute( db, formId, IS_COLENTRY_KEY, 0, String.valueOf(0) ); 404 405 406 if(rowEntry != null) { 408 insertNewFieldAttribute( db, formId, BOOL_ZUSATZ_ROW, 0, String.valueOf(isRowCell) ); 410 411 TKSubFieldTableData subFieldDBRow = insertNewSubField( db, formId, ROW_ENTRY_KEY, 0 ); 412 rowEntry.realInsertIntoDB( db, formId ); 413 subFieldDBRow.sub_field_id = rowEntry.fieldId; 414 415 } 416 417 if(colEntry != null) { 419 insertNewFieldAttribute( db, formId, BOOL_ZUSATZ_COL, 0, String.valueOf(isColCell) ); 421 422 TKSubFieldTableData subFieldDBCol = insertNewSubField( db, formId, COL_ENTRY_KEY, 0 ); 423 colEntry.realInsertIntoDB( db, formId ); 424 subFieldDBCol.sub_field_id = colEntry.fieldId; 425 } 426 427 428 429 return fieldId; 430 } 431 432 433 public void initFromDB( String classId, TKFormDBData db, TKVector otherFields ) 435 throws 436 TKUnregisteredClassException, 437 ClassNotFoundException , 438 InstantiationException , 439 IllegalAccessException  440 { 441 442 super.initFromDB( classId, db, otherFields ); 443 fieldList = getSubFieldList( db, SUB_FIELD_KEY, otherFields ); 444 tableFields = getFieldHashFromList( fieldList ); 445 446 447 int isRowEntry = Integer.parseInt( getFieldAttribute( db, IS_ROWENTRY_KEY, 0 ) ); 449 int isColEntry = Integer.parseInt( getFieldAttribute( db, IS_COLENTRY_KEY, 0 ) ); 450 451 if(isRowEntry == 1) { 452 String zusatzInfoRow = getFieldAttribute( db, BOOL_ZUSATZ_ROW , 0); 454 isRowCell = (zusatzInfoRow.equalsIgnoreCase("true") ) ? true : false; 455 456 rowEntry = getSubField( db, ROW_ENTRY_KEY, 0, otherFields ); 457 } 458 459 if(isColEntry == 1) { 460 String zusatzInfoCol = getFieldAttribute( db, BOOL_ZUSATZ_COL , 0); 462 isColCell = (zusatzInfoCol.equalsIgnoreCase("true") ) ? true : false; 463 464 colEntry = getSubField( db, COL_ENTRY_KEY, 0, otherFields ); 465 } 466 } 467 468 477 public boolean equals (Object object) 478 { 479 if (! super.equals(object)) 480 { 481 return false; 482 } 483 484 TKFieldTableOriented field = (TKFieldTableOriented) object; 485 486 return (this.isRowCell == field.isRowCell) && 487 (this.isColCell == field.isColCell) && 488 (this.fieldList == null ? field.fieldList == null : this.fieldList.equals(field.fieldList)) && 489 (this.rowEntry == null ? field.rowEntry == null : this.rowEntry.equals(field.rowEntry)) && 490 (this.colEntry == null ? field.colEntry == null : this.colEntry.equals(field.colEntry)); 491 } 492 493 498 public int hashCode () 499 { 500 return super.hashCode(); 502 } 503 504 } 505
| Popular Tags
|