KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.teamkonzept.field;
2
3 import java.util.Enumeration JavaDoc;
4 import java.util.StringTokenizer JavaDoc;
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 /**
12  * The oriented field table control.
13  *
14  * @author $Author: uli $
15  * @version $Revision: 1.17.4.1 $
16  */

17 public abstract class TKFieldTableOriented
18     extends TKBaseField
19 {
20     // $Id: TKFieldTableOriented.java,v 1.17.4.1 2002/05/06 11:17:06 uli Exp $
21

22     public static final String JavaDoc SUB_FIELD_KEY = "SUBFIELD";
23
24     public static final String JavaDoc ROW_ENTRY_KEY = "ROWENTRY";
25     public static final String JavaDoc COL_ENTRY_KEY = "COLENTRY";
26
27     public static final String JavaDoc IS_ROWENTRY_KEY = "IS_ROWENTRY";
28     public static final String JavaDoc IS_COLENTRY_KEY = "IS_COLENTRY";
29     public static final String JavaDoc ROW_JANEIN_KEY = "JANEINZEILE";
30     public static final String JavaDoc COL_JANEIN_KEY = "JANEINSPALTE";
31
32     public static final String JavaDoc ZUSATZ_KEY = "ZUSATZ";
33     public static final String JavaDoc CELLINFO_KEY = "CELL";
34     public static final String JavaDoc NOCELLINFO_KEY = "NOCELL";
35     public static final String JavaDoc BOOL_ZUSATZ_ROW = "BOOLZUSATZROW";
36     public static final String JavaDoc BOOL_ZUSATZ_COL = "BOOLZUSATZCOL";
37
38     public static final String JavaDoc PRE_COLS = "COL";
39     public static final String JavaDoc PRE_ROWS = "ROW";
40
41     /** true wenn Cell*/
42     public boolean isRowCell;
43     /** true wenn Cell*/
44     public boolean isColCell;
45
46     TKBaseField rowEntry;
47     TKBaseField colEntry;
48
49     TKVector fieldList;
50     TKHashtable tableFields;
51
52     /**
53      * Creates an empty oriented field table control.
54      */

55     public TKFieldTableOriented ()
56     {
57         // NOP
58
}
59
60     /**
61      * Creates an oriented field table control with the specified
62      * properties.
63      *
64      * @param fieldType the field type.
65      * @param name the name.
66      * @param fields the fields.
67      */

68     public TKFieldTableOriented (String JavaDoc fieldType,
69                                  String JavaDoc name,
70                                  TKVector fields)
71     {
72         this(fieldType, name, fields, null, null);
73     }
74
75     /**
76      * Creates an oriented field table control with the specified
77      * properties.
78      *
79      * @param fieldType the field type.
80      * @param name the name.
81      * @param fields the fields.
82      * @param rowEntry the row entry.
83      * @param colEntry the column entry.
84      */

85     public TKFieldTableOriented (String JavaDoc fieldType,
86                                  String JavaDoc name,
87                                  TKVector fields,
88                                  TKBaseField rowEntry,
89                                  TKBaseField colEntry)
90     {
91         this(fieldType, name, fields, rowEntry, colEntry, null);
92     }
93
94     /**
95      * Creates an oriented field table control with the specified
96      * properties.
97      *
98      * @param fieldType the field type.
99      * @param name the name.
100      * @param fields the fields.
101      * @param rowEntry the row entry.
102      * @param colEntry the column entry.
103      * @param showName the description.
104      */

105     public TKFieldTableOriented (String JavaDoc fieldType,
106                                  String JavaDoc name,
107                                  TKVector fields,
108                                  TKBaseField rowEntry,
109                                  TKBaseField colEntry,
110                                  String JavaDoc showName)
111     {
112         initFieldTableOriented(fieldType, name, fields, rowEntry, colEntry, showName);
113     }
114
115     public final void initFieldTableOriented(
116         String JavaDoc fieldType,
117         String JavaDoc name,
118         TKVector fields,
119         TKBaseField rowEntry,
120         TKBaseField colEntry ,
121         String JavaDoc 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 JavaDoc fieldType, Object JavaDoc data )
132         throws
133             TKUnregisteredClassException,
134             ClassNotFoundException JavaDoc,
135             InstantiationException JavaDoc,
136             IllegalAccessException JavaDoc
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         //--------------------------------------------------------//
145
//---- Objekt fuer die Row filtern und registrieren ----//
146
//--------------------------------------------------------//
147
TKFieldOptionData rowData = (TKFieldOptionData)tableData.get(ROW_JANEIN_KEY);
148         initSubFields(rowData, true);
149
150         //--------------------------------------------------------//
151
//---- Objekt fuer die Col filtern und registrieren ----//
152
//--------------------------------------------------------//
153
TKFieldOptionData colData= (TKFieldOptionData)tableData.get(COL_JANEIN_KEY);
154         initSubFields(colData, false);
155     }
156
157     /**
158      * Hilfsmethode fuer init()
159      */

160     public void initSubFields(TKFieldOptionData optionData, boolean initRow)
161         throws
162         TKUnregisteredClassException,
163         ClassNotFoundException JavaDoc,
164         InstantiationException JavaDoc,
165         IllegalAccessException JavaDoc
166
167     {
168
169         if(optionData.data != null) {
170             TKHashtable optionDataHash = (TKHashtable) optionData.data;
171
172             //--------------------------------------------------//
173
//---- Zusatzinfos in globaler Variable merken----//
174
//--------------------------------------------------//
175
String JavaDoc selectedVal = (String JavaDoc) 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 JavaDoc( "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     /**
211      * Returns the internal representation of this field.
212      *
213      * @return the internal representation of this field.
214      */

215     public Object JavaDoc toData ()
216     {
217         TKHashtable result = (TKHashtable) super.toData();
218         result.put( SUB_LIST_KEY, getDataOfAlternatives( fieldList ) );
219
220         //--------------------------------------------------//
221
//---- ROW ueber TKFieldOption wiederherstellen ----//
222
//--------------------------------------------------//
223
TKFieldOptionData rowEntryOption = null;
224         result = toDataSubFields(rowEntryOption, rowEntry, result, "row");
225
226         //--------------------------------------------------//
227
//---- COL ueber TKFieldOption wiederherstellen ----//
228
//--------------------------------------------------//
229
TKFieldOptionData colEntryOption = null;
230         result = toDataSubFields(colEntryOption, colEntry, result, "col");
231         return result;
232     }
233
234     /**
235      * Hilfsmethode fuer toData()
236      */

237     public TKHashtable toDataSubFields(
238         TKFieldOptionData entryOption,
239         TKBaseField rowOrColEntry,
240         TKHashtable result,
241         String JavaDoc rowOrCol)
242     {
243         if(rowOrColEntry != null) {
244             //----------------------------------------------//
245
//---- Das Switch wiederherstellen und in ----//
246
//---- einen Hash fuer dieGruppe packen ----//
247
//----------------------------------------------//
248
TKHashtable groupData = new TKHashtable();
249             groupData.put(
250                 SUB_TYPE_KEY,
251                 new TKFieldSwitchData( rowOrColEntry.getType(), rowOrColEntry.getType(), rowOrColEntry.toData() )
252             );
253             //----------------------------------------------------------//
254
//---- Pulldownmenue wieder herstellen und in den Hash ----//
255
//---- fuer dieGruppe packen ----//
256
//----------------------------------------------------------//
257
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             //---------------------------------------------------//
280
//---- Switch-Auswahl wenn yes ausgewaehlt wurde ----//
281
//---------------------------------------------------//
282
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 JavaDoc subPrefix( String JavaDoc prefix )
294     {
295         return prefix+fieldName+".";
296     }
297
298     public TKBaseField getTarget(String JavaDoc fieldPath, String JavaDoc prefix)
299     {
300         TKBaseField targetField = null;
301         int pLength = prefix.length()+fieldName.length();
302
303         //-------------------------------------//
304
//---- action betrifft Sub-ELement ----//
305
//-------------------------------------//
306
if ( (fieldPath.length() != pLength) && (fieldPath.length()-3 != pLength) )
307         {
308             String JavaDoc 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 JavaDoc 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             //---- modify des SubElementes in einer ZusatzCol ----//
319
else if( subZusatz.startsWith( PRE_COLS ) ) {
320                 subZusatz = subZusatz.substring( PRE_COLS.length()+1 );
321                 int idxEnd = subZusatz.indexOf('.');
322                 String JavaDoc 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             //---- modify des SubElementes in einer Zelle ----//
329
else {
330                 String JavaDoc subName = fieldPath.substring( pLength+5);
331                 TKBaseField field = (TKBaseField) tableFields.get( subName );
332
333                 String JavaDoc subPath = fieldPath.substring( pLength+1);
334                 StringTokenizer JavaDoc getToken = new StringTokenizer JavaDoc(subPath, ".");
335                 int rowIdx = Integer.parseInt( (String JavaDoc) getToken.nextElement() );
336                 int colIdx = Integer.parseInt( (String JavaDoc) 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 JavaDoc data, String JavaDoc prefix )
345     {
346         super.fillIntoTemplate( t, data, prefix );
347     }
348
349
350     public void fillIntoDOM(Document doc, Element node, Object JavaDoc data) throws DOMException
351     {
352         Element me = doc.createElement(getInternationalName());
353         node.appendChild(me);
354         fillAttributesIntoNode(me, data);
355         // NICHT FERTIG !!!!! oder doch ?
356
}
357
358     public abstract Object JavaDoc compileData( String JavaDoc prefix, TKHashtable data, TKHashtable context );
359
360     public abstract Object JavaDoc compileData( String JavaDoc prefix, TKMarkupNode data, TKHashtable context );
361
362     public Object JavaDoc 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 JavaDoc 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     //***********************************************************************
383
public int realInsertIntoDB( TKFormDBData db, int formId )
384     {
385         //---- table fieldlist ----//
386
if( super.realInsertIntoDB( db, formId ) == -1 ) return -1;
387
388         insertNewSubFieldList( db, formId, SUB_FIELD_KEY, fieldList );
389
390
391         //------------------------------------------------------------------//
392
//---- Diese Attribute zuerst setzen, da hieraus erkennbar ist, ----//
393
//---- ob ein colEntry oder rowEntry vorhanden ist ----//
394
//------------------------------------------------------------------//
395
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         //---- rowEntry ----//
407
if(rowEntry != null) {
408             //---- Was wurde im Pulldown ausgewaehlt => true oder false merken ----//
409
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         //---- colEntry ----//
418
if(colEntry != null) {
419             //---- Was wurde im Pulldown ausgewaehlt => true oder false merken ----//
420
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     //***********************************************************************
434
public void initFromDB( String JavaDoc classId, TKFormDBData db, TKVector otherFields )
435         throws
436             TKUnregisteredClassException,
437             ClassNotFoundException JavaDoc,
438             InstantiationException JavaDoc,
439             IllegalAccessException JavaDoc
440     {
441
442         super.initFromDB( classId, db, otherFields );
443         fieldList = getSubFieldList( db, SUB_FIELD_KEY, otherFields );
444         tableFields = getFieldHashFromList( fieldList );
445
446
447         //---- Attribute, welche ZusatzBaseFields aufgebaut werden muessen ----//
448
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             //---- Attribute, was aus dem Pulldown Ausgewaehlt wurde fuer Row ----//
453
String JavaDoc 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             //---- Attribute, was aus dem Pulldown Ausgewaehlt wurde fuer Col ----//
461
String JavaDoc 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     /**
469      * Checks wether this object and the specified object
470      * may be treated as equal.
471      *
472      * @param object the object to checked for equality.
473      * @return <CODE>true</CODE> if this object and the
474      * specified object may be treated as equal, otherwise
475      * <CODE>false</CODE>.
476      */

477     public boolean equals (Object JavaDoc 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     /**
494      * Returns the hash code for this object.
495      *
496      * @return the hash code for this object.
497      */

498     public int hashCode ()
499     {
500         // Implementation for JTest only ;-(
501
return super.hashCode();
502     }
503
504 }
505
Popular Tags