KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.teamkonzept.field;
2
3 import java.util.*;
4 import com.teamkonzept.lib.*;
5 import com.teamkonzept.publishing.markups.*;
6 import com.teamkonzept.web.*;
7 import com.teamkonzept.field.db.*;
8 import com.teamkonzept.international.LanguageManager;
9 import org.apache.log4j.Category;
10
11 public class TKFieldTableColOriented
12     extends TKFieldTableOriented
13 {
14     // $Id: TKFieldTableColOriented.java,v 1.17 2001/09/21 14:22:06 uli Exp $
15

16     private static final Category cat = Category.getInstance(TKFieldTableColOriented.class);
17
18     public static final String JavaDoc CLASS_ID = "FIELDTABLECOLORIENTED";
19
20
21     public TKFieldTableColOriented() {}
22
23     public TKFieldTableColOriented( String JavaDoc name, TKVector fields )
24     {
25         this( name, fields, null, null );
26     }
27
28
29     public TKFieldTableColOriented(
30         String JavaDoc name,
31         TKVector fields,
32         TKBaseField rowEntry,
33         TKBaseField colEntry )
34     {
35         this( name, fields, rowEntry, colEntry, null );
36     }
37
38
39
40     public TKFieldTableColOriented(
41         String JavaDoc name,
42         TKVector fields,
43         TKBaseField rowEntry,
44         TKBaseField colEntry ,
45         String JavaDoc showName )
46     {
47         initFieldTableColOriented( "FIELDTABLECOLORIENTED", name, fields, rowEntry, colEntry, showName );
48     }
49
50
51     public final void initFieldTableColOriented(
52         String JavaDoc fieldType,
53         String JavaDoc name,
54         TKVector fields,
55         TKBaseField rowEntry,
56         TKBaseField colEntry ,
57         String JavaDoc showName )
58     {
59         initFieldTableOriented( "FIELDTABLECOLORIENTED", name, fields, rowEntry, colEntry, showName );
60
61     }
62
63     //***************************************************************************
64
/**
65      * Methode zur Definition Row-Orientierter Tabellen
66      */

67     public TKFieldGroup getDefGroup(TKFieldSwitch allSwitch, TKFieldSwitchList allSwitchList) {
68
69         TKBaseField [] groupTableArray = {
70             allSwitchList
71         };
72
73         //======================= Switch und Check =================//
74
//---- Eine Checkbox, falls "Yes" selectiert wurde ----//
75
TKVector singleCheckVector = new TKVector(2);
76         singleCheckVector.addElement(
77             new TKOptionFieldEntry( LanguageManager.getText(LANGUAGE_CONTEXT, "FIELDTABLE_CELL"), "CELL" ) );
78         singleCheckVector.addElement(
79             new TKOptionFieldEntry( LanguageManager.getText(LANGUAGE_CONTEXT, "FIELDTABLE_ROW_COLUMN"), "NOCELL" ) );
80
81
82         TKBaseField [] switchAndCheckArray = {
83             new TKSelectField( "ZUSATZ", LanguageManager.getText(LANGUAGE_CONTEXT, "FIELDTABLE_ADDINFO"),singleCheckVector ),
84             allSwitch
85         };
86
87         //======================= SPALTENINFOS =================//
88
//---- Gruppe wird erzeugt mit einer Switchauswahl und einer Checkbox ----//
89
TKFieldGroup switchAndCheckGroup =
90             new TKFieldGroup( TKFieldOption.CLASS_ID, new TKVector( switchAndCheckArray ), LanguageManager.getText(LANGUAGE_CONTEXT, "FIELDTABLE_INFOCOLUMN") );
91
92         //================== ZEILENINFOS =====================/
93
//---- Gruppe wird erzeugt mit einer Switchauswahl und einer Checkbox ----//
94
TKFieldGroup switchAndCheckGroup2 =
95             new TKFieldGroup( TKFieldOption.CLASS_ID, new TKVector( switchAndCheckArray ), LanguageManager.getText(LANGUAGE_CONTEXT, "FIELDTABLE_INFOROW"));
96
97         //========================= TABELLE ==================================//
98
TKFieldGroup groupGroupTable =
99             new TKFieldGroup( TKFieldGroup.CLASS_ID, new TKVector( groupTableArray ),LanguageManager.getText(LANGUAGE_CONTEXT, "FIELDTABLE_GROUPING") );
100
101         TKBaseField [] tableColOrientedArray = {
102             new TKInputField( TKFieldTableColOriented.NAME_KEY, 16, 80, LanguageManager.getText(LANGUAGE_CONTEXT, "FIELDTABLE_NAME"), TKInputField.CHECK_STRING),
103             new TKInputField( TKFieldTableColOriented.SHOW_NAME_KEY, 50, 254, LanguageManager.getText(LANGUAGE_CONTEXT, "FIELDTABLE_SHOWNAME"), TKInputField.CHECK_STRING),
104             allSwitchList,
105             new TKFieldOption( "JANEINSPALTE", switchAndCheckGroup, LanguageManager.getText(LANGUAGE_CONTEXT, "FIELDTABLE_JANEINSPALTE")),
106             new TKFieldOption( "JANEINZEILE", switchAndCheckGroup2, LanguageManager.getText(LANGUAGE_CONTEXT, "FIELDTABLE_JANEINZEILE"))
107         };
108
109         TKFieldGroup tableColOrientedGroup =
110             new TKFieldGroup( TKFieldTableColOriented.CLASS_ID, new TKVector( tableColOrientedArray ), LanguageManager.getText(LANGUAGE_CONTEXT, TKFieldTableColOriented.CLASS_ID) );
111
112
113         return tableColOrientedGroup;
114     }
115
116
117     //***********************************************************************
118
public Object JavaDoc compileData( String JavaDoc prefix, TKHashtable data, TKHashtable context )
119     {
120         int entryCount = fieldList.size();
121         if( entryCount == 0 ) return new TKFieldTableOrientedData(null, null, null);
122
123         TKVector result = new TKVector(1);
124         TKVector colVector = null;
125         prefix = subPrefix( prefix );
126
127         int tableSize = Integer.parseInt( (String JavaDoc)data.get(prefix+"SIZE") );
128         int rows = entryCount;
129         int cols = tableSize;
130
131
132         //-----------------------------------//
133
//---- Data fuer eine zusatz ROW ----//
134
//-----------------------------------//
135
TKVector rowInfoVector = null;
136         if((rowEntry != null) && (rows >= 0)) {
137             rowInfoVector = new TKVector();
138             if(cols > 0) {
139                 for( int x=0; x< rows; x++ ) {
140                     rowInfoVector.addElement(rowEntry.compileData( prefix+PRE_ROWS+"."+x+".", data, context ));
141                 }
142             }
143             else {
144                 for( int x=0; x< rows; x++ ) {
145                     rowInfoVector.addElement(rowEntry.getDefault());
146                 }
147             }
148         }
149         //---------------------------------------//
150
//---- Data fuer eine zusatz COLUMN ----//
151
//---------------------------------------//
152
TKVector colInfoVector = null;
153         if(colEntry != null) {
154             colInfoVector = new TKVector(cols);
155             for( int x=0; x< cols; x++ ) {
156                 colInfoVector.addElement(colEntry.compileData( prefix+PRE_COLS+"."+x+".", data, context ));
157             }
158         }
159
160
161         //-----------------//
162
//---- tabelle ----//
163
//-----------------//
164
for(int x=0; x < tableSize; x++) {
165             colVector = new TKVector( entryCount);
166             for( int y=0; y<entryCount; y++ ) {
167                 TKBaseField field = (TKBaseField) fieldList.get( y);
168                 colVector.addElement(field.compileData(prefix+y+"."+x+".", data, context) );
169             }
170             result.addElement(colVector);
171         }
172         return new TKFieldTableOrientedData(result, rowInfoVector, colInfoVector);
173
174     }
175
176     public Object JavaDoc compileData( String JavaDoc prefix, TKMarkupNode data, TKHashtable context )
177     {
178         int entryCount = fieldList.size();
179
180         if( entryCount == 0 ) return new TKFieldTableOrientedData(null, null, null);
181
182         TKXmlMarkup markup = data == null ? null : (TKXmlMarkup) data.markup;
183         if (markup == null) { return null;}
184
185         if (!markup.name.equals (getName())) {
186             return null;
187         }
188
189         TKXmlTree tree = (TKXmlTree) data.tree;
190
191         TKVector rowInfoVector = null;
192         TKVector colInfoVector = null;
193         TKVector result = null;
194
195         int x = 0;
196         for (int i = 0; i < tree.size(); i++) {
197
198             Object JavaDoc obj = tree.getSub(i);
199             if (obj == null) continue;
200
201             if (x >= entryCount) {
202                 break;
203             }
204             TKMarkupNode subNode = null;
205             TKXmlMarkup subMarkup = null;
206
207             if (obj instanceof TKXmlMarkup) { // Atomares Markup
208

209                 subMarkup = (TKXmlMarkup) obj;
210
211                 continue;
212
213             } else {
214                 subNode = (TKMarkupNode) obj;
215                 subMarkup = (TKXmlMarkup) subNode.markup;
216             }
217
218             if (subMarkup.name.equals ("CI")) {
219
220                 TKXmlTree subTree = (TKXmlTree) subNode.tree;
221                 if (subTree == null) { continue; }
222
223                 for (int j = 0; j < subTree.size(); j++) {
224
225                     Object JavaDoc subObj = subTree.getSub(j);
226                     if (subObj == null) continue;
227
228                     TKMarkupNode subSubNode = null;
229                     TKXmlMarkup subSubMarkup = null;
230
231                     if (subObj instanceof TKXmlMarkup) { // Atomares Markup
232

233                         subSubMarkup = (TKXmlMarkup) subObj;
234                         subSubNode = new TKMarkupNode (subSubMarkup,null);
235
236                     } else {
237                         subSubNode = (TKMarkupNode) subObj;
238                         subSubMarkup = (TKXmlMarkup) subSubNode.markup;
239                     }
240
241                     if (colInfoVector == null) colInfoVector = new TKVector();
242                     colInfoVector.addElement(colEntry.compileData( prefix+j+".", subSubNode, context ));
243                 }
244             }
245
246             else if (subMarkup.name.equals ("TR")) {
247
248                     TKVector colsResultVector = null;
249
250                 TKXmlTree subTree = (TKXmlTree) subNode.tree;
251                 if (subTree == null) { continue; }
252
253                 int y = 0;
254                 for (int j = 0; j < subTree.size(); j++) {
255
256                     Object JavaDoc subObj = subTree.getSub(j);
257                     if (subObj == null) continue;
258
259                     TKMarkupNode subSubNode = null;
260                     TKXmlMarkup subSubMarkup = null;
261
262                     if (subObj instanceof TKXmlMarkup) { // Atomares Markup
263

264                         subSubMarkup = (TKXmlMarkup) subObj;
265                         subSubNode = new TKMarkupNode (subSubMarkup,null);
266
267                     } else {
268                         subSubNode = (TKMarkupNode) subObj;
269                         subSubMarkup = (TKXmlMarkup) subSubNode.markup;
270                     }
271
272                     TKXmlTree subSubTree = (TKXmlTree) subSubNode.tree;
273                     Object JavaDoc subSubObj = subSubTree.getSingleSub();
274                     if (subSubObj == null) continue;
275
276                     TKMarkupNode subSubSubNode = null;
277                     TKXmlMarkup subSubSubMarkup = null;
278
279                     if (subSubObj instanceof TKXmlMarkup) { // Atomares Markup
280

281                         subSubSubMarkup = (TKXmlMarkup) subSubObj;
282                         subSubSubNode = new TKMarkupNode (subSubSubMarkup,null);
283
284                     } else {
285                         subSubSubNode = (TKMarkupNode) subSubObj;
286                         subSubSubMarkup = (TKXmlMarkup) subSubSubNode.markup;
287                     }
288
289                     if (subSubMarkup.name.equals ("RI")) {
290
291                         if (rowInfoVector == null) rowInfoVector = new TKVector();
292                         // TKLog.println ("TKFieldTableColOriented added ri: "+subSubSubMarkup.name);
293
rowInfoVector.addElement(rowEntry.compileData( prefix+j+".", subSubSubNode, context ));
294                     } else {
295
296                         if (result == null) result = new TKVector();
297                         int currentSize = result.size();
298                         while (currentSize++ <= y) result.addElement (new TKVector());
299                         colsResultVector = (TKVector) result.get(y);
300
301                         currentSize = colsResultVector.size();
302                         while (currentSize++ < x) colsResultVector.addElement (null);
303
304                         TKBaseField field = (TKBaseField) fieldList.get( x);
305                         if (field == null)
306                             ;
307                         else colsResultVector.addElement
308                             (field.compileData( prefix+x+"."+y+".", subSubSubNode, context ));
309
310                         y++;
311                     }
312                 }
313
314                 x++;
315             }
316
317             else {
318
319             }
320         }
321
322         return new TKFieldTableOrientedData(result, rowInfoVector, colInfoVector);
323     }
324
325     public void fillIntoTemplate( TKHTMLTemplate t, Object JavaDoc data, String JavaDoc prefix )
326     {
327         TKFieldTableOrientedData dataClass = (TKFieldTableOrientedData) data;
328         TKVector dataVector = (TKVector) dataClass.contentData;
329
330         super.fillIntoTemplate( t, data, prefix );
331
332         int cols = ( dataVector == null ? 0 : dataVector.size() );
333         int rows = fieldList.size();
334
335         if(dataVector == null) {
336             t.set("SIZE", "0");
337         }
338         else {
339             t.set("SIZE", String.valueOf(dataVector.size()) );
340             t.set("IS_OUTERLIST", Boolean.TRUE);
341         }
342
343         if( (TKVector)dataClass.rowData != null )
344             t.set("IS_COLFORINFOS", Boolean.TRUE);
345
346         if( (TKVector)dataClass.colData != null )
347             t.set("IS_ROWFORINFOS", Boolean.TRUE);
348
349             t.setListIterator( new TKFieldTableColOrientedIterator(
350             dataClass,
351             fieldList,
352             rowEntry,
353             colEntry,
354             subPrefix( prefix ),
355             t.getListIterator(),
356             "OUTERLIST",
357             "INNERLIST",
358             "ROWFORINFOLIST",
359             fieldType
360         ) );
361
362
363         //t.set( "FIELDTABLELIST", Boolean.TRUE );
364
}
365
366     //***********************************************************************
367
public void fillIntoPresentation( TKHTMLTemplate t, Object JavaDoc data, String JavaDoc scope )
368     {
369
370         TKFieldTableOrientedData dataClass = (TKFieldTableOrientedData) data;
371         TKVector dataVector = (TKVector) dataClass.contentData;
372
373         t.set(scope+"."+getName()+".ROWSIZE", String.valueOf( dataVector.size() ) );
374         t.set(scope+"."+getName()+".COLSIZE", String.valueOf( fieldList.size() ) );
375
376         //---- tabellenlayout ----//
377
if( (TKVector)dataClass.rowData != null )
378                 t.set("IS_ROWENTRY", Boolean.TRUE);
379
380         if( (TKVector)dataClass.colData != null )
381                 t.set("IS_COLENTRY", Boolean.TRUE);
382
383         if(dataVector != null)
384         t.set("IS_OUTERLIST", Boolean.TRUE);
385
386         //--- Ueberschrift ----//
387
if(isRowCell == false)
388           t.set("HEADERROW", Boolean.TRUE);
389         if(isColCell == false)
390           t.set("HEADERCOL", Boolean.TRUE);
391
392         t.setListIterator( new TKTableColShowIterator(
393             dataClass,
394             fieldList,
395             rowEntry,
396             colEntry,
397             scope,
398             getName(),
399             t.getListIterator(),
400             "OUTERLIST",
401             "INNERLIST",
402             "ROWFORINFOLIST"
403         ) );
404
405
406     }
407
408     public Object JavaDoc modify( String JavaDoc action, String JavaDoc fieldPath, Object JavaDoc data, String JavaDoc prefix, StringBuffer JavaDoc destination )
409     {
410         TKFieldTableOrientedData dataClass = (TKFieldTableOrientedData) data;
411         TKVector dataVector = (TKVector) dataClass.contentData;
412
413
414         int pLength = prefix.length()+fieldName.length();
415
416         //--------------------------------------//
417
//----action betrifft Tabelle selbst----//
418
//--------------------------------------//
419
if(fieldPath.length() == pLength ) {
420             int entryCount = fieldList.size();
421             int dataVectorSize = dataVector.size();
422
423             if(action.equals("ADD")) {
424                 TKVector colVector = new TKVector( entryCount );
425
426                 //---- Zusatzcol ----//
427
if( colEntry != null ) {
428                     dataClass.colData.addElement(colEntry.getDefault());
429                 }
430
431                 //---- Zusatzrow HAT FESTE Groesse fest!!! ----//
432
for( int i=0; i<entryCount; i++ ) {
433                     TKBaseField field = (TKBaseField) fieldList.get( i );
434                     colVector.addElement(field.getDefault() );
435                 }
436                 dataVector.addElement(colVector);
437                 destination.append( prefix+fieldName+"."+(dataClass.contentData.size()-1)+".");
438             }
439         }
440         //----------------------------------------------------------//
441
//---- Action betrifft eine Zeile/Spalte der Tabelle -------//
442
//----------------------------------------------------------//
443
else if(fieldPath.length()-3 == pLength) {
444
445             int index = 0;
446             String JavaDoc subPath = fieldPath.substring( pLength+1 );
447             StringTokenizer getToken = new StringTokenizer( subPath, ".");
448             index = Integer.parseInt( (String JavaDoc)getToken.nextElement() );
449
450
451             if(action.equals("DELETE")) {
452                 if(index == 0)
453                     destination.append( prefix+fieldName+"."+index+".");
454                 else
455                     destination.append( prefix+fieldName+"."+(index-1)+".");
456                 data = actionIsDelete(dataClass, index);
457             }
458
459             if(action.equals("INSERT")) {
460                 destination.append( prefix+fieldName+"."+index+".");
461                 data = actionIsInsert(dataClass, index);
462
463             }
464             if(action.equals("FIRST")) {
465                 destination.append( prefix+fieldName+"."+0+".");
466                 dataClass = actionIsFirst(dataClass, index);
467                 if(index != 0)
468                     data = actionIsDelete(dataClass, index+1);
469             }
470             if(action.equals("LAST")) {
471                 destination.append( prefix+fieldName+"."+(dataClass.contentData.size()-1)+".");
472                 dataClass = actionIsLast(dataClass, index);
473                 data = actionIsDelete(dataClass, index);
474
475             }
476             if(action.equals("FORWARD")) {
477                 if(index == dataClass.contentData.size()-1)
478                     destination.append( prefix+fieldName+"."+index+".");
479                 else
480                     destination.append( prefix+fieldName+"."+(index+1)+".");
481                 dataClass = actionIsForward(dataClass, index);
482                 if(index != dataClass.contentData.size()-1)
483                     data = actionIsDelete(dataClass, index);
484
485             }
486             if(action.equals("BACK")) {
487                 if(index == 0)
488                     destination.append( prefix+fieldName+"."+0+".");
489                 else
490                     destination.append( prefix+fieldName+"."+(index-1)+".");
491                 dataClass = actionIsBack(dataClass, index);
492                 if(index != 0)
493                     data = actionIsDelete(dataClass, index+1);
494             }
495         }
496         //-------------------------------------//
497
//---- action betrifft Sub-ELement ----//
498
//-------------------------------------//
499
else {
500
501             String JavaDoc subZusatz = fieldPath.substring( pLength+1);
502
503                     //---- modify des SubElementes in einer ZusatzRow ----//
504
if( subZusatz.startsWith( PRE_ROWS ) ) {
505                 subZusatz = subZusatz.substring( PRE_ROWS.length()+1 );
506                 int idxEnd = subZusatz.indexOf('.');
507                 String JavaDoc idxStr = subZusatz.substring( 0, idxEnd );
508                 int idx = Integer.parseInt( idxStr );
509
510                 dataClass.rowData.put( idx, rowEntry.modify(
511                     action, fieldPath, dataClass.rowData.get( idx ),
512                     prefix+fieldName+'.'+PRE_ROWS+"."+idx+'.', destination
513                 ) );
514
515             }
516             //---- modify des SubElementes in einer ZusatzCol ----//
517
else if( subZusatz.startsWith( PRE_COLS ) ) {
518                 subZusatz = subZusatz.substring( PRE_COLS.length()+1 );
519                 int idxEnd = subZusatz.indexOf('.');
520                 String JavaDoc idxStr = subZusatz.substring( 0, idxEnd );
521                 int idx = Integer.parseInt( idxStr );
522                 dataClass.colData.put( idx, colEntry.modify(
523                     action, fieldPath, dataClass.colData.get( idx ),
524                     prefix+fieldName+'.'+PRE_COLS+"."+idx+'.',
525                     destination
526                 ) );
527             }
528             //---- modify des SubElementes in einer Zelle ----//
529
else {
530                 String JavaDoc subName = fieldPath.substring( pLength+5);
531                 int idx = subName.indexOf('.');
532                 if(idx >= 0)
533                     subName = subName.substring(0,idx);
534                 TKBaseField field = (TKBaseField) tableFields.get( subName );
535
536                 String JavaDoc subPath = fieldPath.substring( pLength+1);
537                 StringTokenizer getToken = new StringTokenizer(subPath, ".");
538                 int rowIdx = Integer.parseInt( (String JavaDoc) getToken.nextElement() );
539                 int colIdx = Integer.parseInt( (String JavaDoc) getToken.nextElement() );
540
541                 TKVector colVector = (TKVector) dataVector.elementAt(colIdx);
542
543                 colVector.put( rowIdx, field.modify( action, fieldPath, colVector.get(rowIdx),
544                     prefix+fieldName+"."+rowIdx+"."+colIdx+".",
545                     destination
546                 ) );
547
548             }
549         }
550
551         return data;
552     }
553
554     public TKFieldTableOrientedData actionIsDelete( TKFieldTableOrientedData dataClass, int index )
555     {
556
557         dataClass.contentData.removeElementAt(index);
558
559         if( (rowEntry != null) && (dataClass.contentData.isEmpty()) )
560             dataClass.rowData = null;
561
562
563         if(colEntry != null)
564             if (dataClass.contentData.isEmpty() )
565                 dataClass.colData = null;
566             else
567                 dataClass.colData.removeElementAt(index);
568
569         return dataClass;
570     }
571
572     public TKFieldTableOrientedData actionIsInsert( TKFieldTableOrientedData dataClass, int index )
573     {
574
575         TKVector newVector = new TKVector ();
576         for(int x = 0; x < fieldList.size(); x++) {
577             newVector.addElement( ( (TKBaseField)fieldList.elementAt(x)).getDefault());
578         }
579         dataClass.contentData.insertElementAt(newVector,index);
580
581         if(colEntry != null)
582             dataClass.colData.insertElementAt(colEntry.getDefault(), index);
583
584         return dataClass;
585     }
586
587
588     public TKFieldTableOrientedData actionIsFirst( TKFieldTableOrientedData dataClass, int index )
589     {
590
591         if(index > 0) {
592             TKVector insertVector = (TKVector) dataClass.contentData.elementAt(index);
593             dataClass.contentData.insertElementAt(insertVector,0);
594
595             if(colEntry != null)
596                 dataClass.colData.insertElementAt(dataClass.colData.elementAt(index), 0);
597         }
598             return dataClass;
599     }
600
601     public TKFieldTableOrientedData actionIsLast( TKFieldTableOrientedData dataClass, int index )
602     {
603         int size = dataClass.contentData.size();
604
605         TKVector insertVector = (TKVector) dataClass.contentData.elementAt(index);
606         dataClass.contentData.insertElementAt(insertVector,size);
607
608
609         if(colEntry != null)
610             dataClass.colData.insertElementAt(dataClass.colData.elementAt(index), size);
611         return dataClass;
612     }
613
614     public TKFieldTableOrientedData actionIsBack( TKFieldTableOrientedData dataClass, int index )
615     {
616
617         if(index == 0) return dataClass;
618         if(index > 1) {
619             TKVector insertVector = (TKVector) dataClass.contentData.elementAt(index);
620             dataClass.contentData.insertElementAt(insertVector,index-1);
621
622             if(colEntry != null)
623                 dataClass.colData.insertElementAt(dataClass.colData.elementAt(index), index-1);
624         }
625         else if(index == 1) {
626             dataClass = actionIsFirst(dataClass, index);
627         }
628         return dataClass;
629     }
630
631     public TKFieldTableOrientedData actionIsForward( TKFieldTableOrientedData dataClass, int index )
632     {
633         int size = dataClass.contentData.size();
634
635         if(index == size-1) return dataClass;
636
637         else {
638             TKVector insertVector = (TKVector) dataClass.contentData.elementAt(index);
639             dataClass.contentData.insertElementAt(insertVector,index+2);
640
641             if(colEntry != null)
642                 dataClass.colData.insertElementAt(dataClass.colData.elementAt(index), index+2);
643         }
644         return dataClass;
645     }
646
647
648
649     public int insertDataIntoDB( TKContentDBData db, Object JavaDoc data, int contentId, int leftNr )
650     {
651         int entryCount = fieldList.size();
652         if( entryCount == 0 ) return leftNr;
653
654         TKContentNodeTableData node = insertNewContentNode( db, contentId, leftNr );
655         int newNodeId = node.content_node_id;
656
657         TKFieldTableOrientedData dataClass = (TKFieldTableOrientedData) data;
658         TKVector dataVector = (TKVector) dataClass.contentData;
659
660         insertNewContentValue(db, contentId, newNodeId, 0, String.valueOf(dataVector != null ? dataVector.size() : 0));
661         leftNr++;
662
663         //---- InfoRow ----//
664
if(rowEntry != null) {
665             for (int x=0; x < fieldList.size(); x++) {
666                 node.right_nr = rowEntry.insertDataIntoDB( db, dataClass.rowData.elementAt(x), contentId, leftNr+1 )+1;
667             }
668         }
669
670         //------ InfoCol ----//
671
if(colEntry != null) {
672             for (int x=0; x < dataVector.size(); x++) {
673                 node.right_nr = colEntry.insertDataIntoDB( db, dataClass.colData.elementAt(x), contentId, leftNr+1 )+1;
674             }
675         }
676
677
678         //---- Table ----//
679
if(dataVector != null) {
680             for(int x= 0; x < dataVector.size(); x++) {
681                 for( int y=0; y< entryCount; y++ ) {
682                     TKBaseField field = (TKBaseField) fieldList.get( y );
683                     leftNr = field.insertDataIntoDB( db, ((TKVector) dataVector.elementAt(x)).elementAt(y), contentId, leftNr+1 );
684                     leftNr++;
685                 }
686             }
687         }
688
689         node.right_nr = leftNr;
690         return leftNr;
691
692     }
693
694     public Object JavaDoc getDataFromDB( TKContentDBData db )
695     {
696
697         int entryCount = fieldList.size();
698         if( entryCount == 0 ) return new TKVector();
699
700         TKVector dataVector = new TKVector( );
701         TKContentNodeTableData node = getContentNodeFromDB( db );
702
703         TKContentValueTableData value0 = getContentNodeValueFromDB(db, node);
704         int dataVectorSize = Integer.parseInt( value0.value);
705
706         TKVector rowInfoVector = new TKVector(entryCount);
707         TKVector colInfoVector = new TKVector(dataVectorSize);
708
709
710         //---- Info Row ----//
711
if(rowEntry != null) {
712             for( int x=0; x< entryCount; x++ ) {
713                 rowInfoVector.addElement(rowEntry.getDataFromDB( db ));
714             }
715         }
716         else rowInfoVector = null;
717
718
719         //---- Info Col ----//
720
if(colEntry != null) {
721             for( int x=0; x< dataVectorSize; x++ ) {
722                 colInfoVector.addElement(colEntry.getDataFromDB( db ));
723             }
724         }
725         else colInfoVector = null;
726
727
728         //---- table ----//
729
for(int x=0; x < dataVectorSize; x++) {
730             TKVector colVector = new TKVector(entryCount);
731             for( int i=0; i < entryCount; i++ ) {
732                 TKBaseField field = (TKBaseField) fieldList.get( i );
733                 colVector.addElement(field.getDataFromDB( db ));
734             }
735             dataVector.addElement(colVector);
736         }
737
738         return new TKFieldTableOrientedData(dataVector, rowInfoVector, colInfoVector);
739     }
740
741 }
742
Popular Tags