001: package com.teamkonzept.field;
002:
003: import java.util.*;
004: import com.teamkonzept.lib.*;
005: import com.teamkonzept.publishing.markups.*;
006: import com.teamkonzept.web.*;
007: import com.teamkonzept.field.db.*;
008: import com.teamkonzept.international.LanguageManager;
009: import org.apache.log4j.Category;
010:
011: public class TKFieldTableColOriented extends TKFieldTableOriented {
012: // $Id: TKFieldTableColOriented.java,v 1.17 2001/09/21 14:22:06 uli Exp $
013:
014: private static final Category cat = Category
015: .getInstance(TKFieldTableColOriented.class);
016:
017: public static final String CLASS_ID = "FIELDTABLECOLORIENTED";
018:
019: public TKFieldTableColOriented() {
020: }
021:
022: public TKFieldTableColOriented(String name, TKVector fields) {
023: this (name, fields, null, null);
024: }
025:
026: public TKFieldTableColOriented(String name, TKVector fields,
027: TKBaseField rowEntry, TKBaseField colEntry) {
028: this (name, fields, rowEntry, colEntry, null);
029: }
030:
031: public TKFieldTableColOriented(String name, TKVector fields,
032: TKBaseField rowEntry, TKBaseField colEntry, String showName) {
033: initFieldTableColOriented("FIELDTABLECOLORIENTED", name,
034: fields, rowEntry, colEntry, showName);
035: }
036:
037: public final void initFieldTableColOriented(String fieldType,
038: String name, TKVector fields, TKBaseField rowEntry,
039: TKBaseField colEntry, String showName) {
040: initFieldTableOriented("FIELDTABLECOLORIENTED", name, fields,
041: rowEntry, colEntry, showName);
042:
043: }
044:
045: //***************************************************************************
046: /**
047: * Methode zur Definition Row-Orientierter Tabellen
048: */
049: public TKFieldGroup getDefGroup(TKFieldSwitch allSwitch,
050: TKFieldSwitchList allSwitchList) {
051:
052: TKBaseField[] groupTableArray = { allSwitchList };
053:
054: //======================= Switch und Check =================//
055: //---- Eine Checkbox, falls "Yes" selectiert wurde ----//
056: TKVector singleCheckVector = new TKVector(2);
057: singleCheckVector.addElement(new TKOptionFieldEntry(
058: LanguageManager.getText(LANGUAGE_CONTEXT,
059: "FIELDTABLE_CELL"), "CELL"));
060: singleCheckVector.addElement(new TKOptionFieldEntry(
061: LanguageManager.getText(LANGUAGE_CONTEXT,
062: "FIELDTABLE_ROW_COLUMN"), "NOCELL"));
063:
064: TKBaseField[] switchAndCheckArray = {
065: new TKSelectField("ZUSATZ", LanguageManager.getText(
066: LANGUAGE_CONTEXT, "FIELDTABLE_ADDINFO"),
067: singleCheckVector), allSwitch };
068:
069: //======================= SPALTENINFOS =================//
070: //---- Gruppe wird erzeugt mit einer Switchauswahl und einer Checkbox ----//
071: TKFieldGroup switchAndCheckGroup = new TKFieldGroup(
072: TKFieldOption.CLASS_ID, new TKVector(
073: switchAndCheckArray), LanguageManager.getText(
074: LANGUAGE_CONTEXT, "FIELDTABLE_INFOCOLUMN"));
075:
076: //================== ZEILENINFOS =====================/
077: //---- Gruppe wird erzeugt mit einer Switchauswahl und einer Checkbox ----//
078: TKFieldGroup switchAndCheckGroup2 = new TKFieldGroup(
079: TKFieldOption.CLASS_ID, new TKVector(
080: switchAndCheckArray), LanguageManager.getText(
081: LANGUAGE_CONTEXT, "FIELDTABLE_INFOROW"));
082:
083: //========================= TABELLE ==================================//
084: TKFieldGroup groupGroupTable = new TKFieldGroup(
085: TKFieldGroup.CLASS_ID, new TKVector(groupTableArray),
086: LanguageManager.getText(LANGUAGE_CONTEXT,
087: "FIELDTABLE_GROUPING"));
088:
089: TKBaseField[] tableColOrientedArray = {
090: new TKInputField(TKFieldTableColOriented.NAME_KEY, 16,
091: 80, LanguageManager.getText(LANGUAGE_CONTEXT,
092: "FIELDTABLE_NAME"),
093: TKInputField.CHECK_STRING),
094: new TKInputField(TKFieldTableColOriented.SHOW_NAME_KEY,
095: 50, 254, LanguageManager
096: .getText(LANGUAGE_CONTEXT,
097: "FIELDTABLE_SHOWNAME"),
098: TKInputField.CHECK_STRING),
099: allSwitchList,
100: new TKFieldOption("JANEINSPALTE", switchAndCheckGroup,
101: LanguageManager.getText(LANGUAGE_CONTEXT,
102: "FIELDTABLE_JANEINSPALTE")),
103: new TKFieldOption("JANEINZEILE", switchAndCheckGroup2,
104: LanguageManager.getText(LANGUAGE_CONTEXT,
105: "FIELDTABLE_JANEINZEILE")) };
106:
107: TKFieldGroup tableColOrientedGroup = new TKFieldGroup(
108: TKFieldTableColOriented.CLASS_ID, new TKVector(
109: tableColOrientedArray), LanguageManager
110: .getText(LANGUAGE_CONTEXT,
111: TKFieldTableColOriented.CLASS_ID));
112:
113: return tableColOrientedGroup;
114: }
115:
116: //***********************************************************************
117: public Object compileData(String prefix, TKHashtable data,
118: TKHashtable context) {
119: int entryCount = fieldList.size();
120: if (entryCount == 0)
121: 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) data.get(prefix
128: + "SIZE"));
129: int rows = entryCount;
130: int cols = tableSize;
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(
141: prefix + PRE_ROWS + "." + x + ".", data,
142: context));
143: }
144: } else {
145: for (int x = 0; x < rows; x++) {
146: rowInfoVector.addElement(rowEntry.getDefault());
147: }
148: }
149: }
150: //---------------------------------------//
151: //---- Data fuer eine zusatz COLUMN ----//
152: //---------------------------------------//
153: TKVector colInfoVector = null;
154: if (colEntry != null) {
155: colInfoVector = new TKVector(cols);
156: for (int x = 0; x < cols; x++) {
157: colInfoVector.addElement(colEntry.compileData(prefix
158: + PRE_COLS + "." + x + ".", data, context));
159: }
160: }
161:
162: //-----------------//
163: //---- tabelle ----//
164: //-----------------//
165: for (int x = 0; x < tableSize; x++) {
166: colVector = new TKVector(entryCount);
167: for (int y = 0; y < entryCount; y++) {
168: TKBaseField field = (TKBaseField) fieldList.get(y);
169: colVector.addElement(field.compileData(prefix + y + "."
170: + x + ".", data, context));
171: }
172: result.addElement(colVector);
173: }
174: return new TKFieldTableOrientedData(result, rowInfoVector,
175: colInfoVector);
176:
177: }
178:
179: public Object compileData(String prefix, TKMarkupNode data,
180: TKHashtable context) {
181: int entryCount = fieldList.size();
182:
183: if (entryCount == 0)
184: return new TKFieldTableOrientedData(null, null, null);
185:
186: TKXmlMarkup markup = data == null ? null
187: : (TKXmlMarkup) data.markup;
188: if (markup == null) {
189: return null;
190: }
191:
192: if (!markup.name.equals(getName())) {
193: return null;
194: }
195:
196: TKXmlTree tree = (TKXmlTree) data.tree;
197:
198: TKVector rowInfoVector = null;
199: TKVector colInfoVector = null;
200: TKVector result = null;
201:
202: int x = 0;
203: for (int i = 0; i < tree.size(); i++) {
204:
205: Object obj = tree.getSub(i);
206: if (obj == null)
207: continue;
208:
209: if (x >= entryCount) {
210: break;
211: }
212: TKMarkupNode subNode = null;
213: TKXmlMarkup subMarkup = null;
214:
215: if (obj instanceof TKXmlMarkup) { // Atomares Markup
216:
217: subMarkup = (TKXmlMarkup) obj;
218:
219: continue;
220:
221: } else {
222: subNode = (TKMarkupNode) obj;
223: subMarkup = (TKXmlMarkup) subNode.markup;
224: }
225:
226: if (subMarkup.name.equals("CI")) {
227:
228: TKXmlTree subTree = (TKXmlTree) subNode.tree;
229: if (subTree == null) {
230: continue;
231: }
232:
233: for (int j = 0; j < subTree.size(); j++) {
234:
235: Object subObj = subTree.getSub(j);
236: if (subObj == null)
237: continue;
238:
239: TKMarkupNode subSubNode = null;
240: TKXmlMarkup subSubMarkup = null;
241:
242: if (subObj instanceof TKXmlMarkup) { // Atomares Markup
243:
244: subSubMarkup = (TKXmlMarkup) subObj;
245: subSubNode = new TKMarkupNode(subSubMarkup,
246: null);
247:
248: } else {
249: subSubNode = (TKMarkupNode) subObj;
250: subSubMarkup = (TKXmlMarkup) subSubNode.markup;
251: }
252:
253: if (colInfoVector == null)
254: colInfoVector = new TKVector();
255: colInfoVector.addElement(colEntry.compileData(
256: prefix + j + ".", subSubNode, context));
257: }
258: }
259:
260: else if (subMarkup.name.equals("TR")) {
261:
262: TKVector colsResultVector = null;
263:
264: TKXmlTree subTree = (TKXmlTree) subNode.tree;
265: if (subTree == null) {
266: continue;
267: }
268:
269: int y = 0;
270: for (int j = 0; j < subTree.size(); j++) {
271:
272: Object subObj = subTree.getSub(j);
273: if (subObj == null)
274: continue;
275:
276: TKMarkupNode subSubNode = null;
277: TKXmlMarkup subSubMarkup = null;
278:
279: if (subObj instanceof TKXmlMarkup) { // Atomares Markup
280:
281: subSubMarkup = (TKXmlMarkup) subObj;
282: subSubNode = new TKMarkupNode(subSubMarkup,
283: null);
284:
285: } else {
286: subSubNode = (TKMarkupNode) subObj;
287: subSubMarkup = (TKXmlMarkup) subSubNode.markup;
288: }
289:
290: TKXmlTree subSubTree = (TKXmlTree) subSubNode.tree;
291: Object subSubObj = subSubTree.getSingleSub();
292: if (subSubObj == null)
293: continue;
294:
295: TKMarkupNode subSubSubNode = null;
296: TKXmlMarkup subSubSubMarkup = null;
297:
298: if (subSubObj instanceof TKXmlMarkup) { // Atomares Markup
299:
300: subSubSubMarkup = (TKXmlMarkup) subSubObj;
301: subSubSubNode = new TKMarkupNode(
302: subSubSubMarkup, null);
303:
304: } else {
305: subSubSubNode = (TKMarkupNode) subSubObj;
306: subSubSubMarkup = (TKXmlMarkup) subSubSubNode.markup;
307: }
308:
309: if (subSubMarkup.name.equals("RI")) {
310:
311: if (rowInfoVector == null)
312: rowInfoVector = new TKVector();
313: // TKLog.println ("TKFieldTableColOriented added ri: "+subSubSubMarkup.name);
314: rowInfoVector.addElement(rowEntry.compileData(
315: prefix + j + ".", subSubSubNode,
316: context));
317: } else {
318:
319: if (result == null)
320: result = new TKVector();
321: int currentSize = result.size();
322: while (currentSize++ <= y)
323: result.addElement(new TKVector());
324: colsResultVector = (TKVector) result.get(y);
325:
326: currentSize = colsResultVector.size();
327: while (currentSize++ < x)
328: colsResultVector.addElement(null);
329:
330: TKBaseField field = (TKBaseField) fieldList
331: .get(x);
332: if (field == null)
333: ;
334: else
335: colsResultVector.addElement(field
336: .compileData(prefix + x + "." + y
337: + ".", subSubSubNode,
338: context));
339:
340: y++;
341: }
342: }
343:
344: x++;
345: }
346:
347: else {
348:
349: }
350: }
351:
352: return new TKFieldTableOrientedData(result, rowInfoVector,
353: colInfoVector);
354: }
355:
356: public void fillIntoTemplate(TKHTMLTemplate t, Object data,
357: String prefix) {
358: TKFieldTableOrientedData dataClass = (TKFieldTableOrientedData) data;
359: TKVector dataVector = (TKVector) dataClass.contentData;
360:
361: super .fillIntoTemplate(t, data, prefix);
362:
363: int cols = (dataVector == null ? 0 : dataVector.size());
364: int rows = fieldList.size();
365:
366: if (dataVector == null) {
367: t.set("SIZE", "0");
368: } else {
369: t.set("SIZE", String.valueOf(dataVector.size()));
370: t.set("IS_OUTERLIST", Boolean.TRUE);
371: }
372:
373: if ((TKVector) dataClass.rowData != null)
374: t.set("IS_COLFORINFOS", Boolean.TRUE);
375:
376: if ((TKVector) dataClass.colData != null)
377: t.set("IS_ROWFORINFOS", Boolean.TRUE);
378:
379: t.setListIterator(new TKFieldTableColOrientedIterator(
380: dataClass, fieldList, rowEntry, colEntry,
381: subPrefix(prefix), t.getListIterator(), "OUTERLIST",
382: "INNERLIST", "ROWFORINFOLIST", fieldType));
383:
384: //t.set( "FIELDTABLELIST", Boolean.TRUE );
385: }
386:
387: //***********************************************************************
388: public void fillIntoPresentation(TKHTMLTemplate t, Object data,
389: String scope) {
390:
391: TKFieldTableOrientedData dataClass = (TKFieldTableOrientedData) data;
392: TKVector dataVector = (TKVector) dataClass.contentData;
393:
394: t.set(scope + "." + getName() + ".ROWSIZE", String
395: .valueOf(dataVector.size()));
396: t.set(scope + "." + getName() + ".COLSIZE", String
397: .valueOf(fieldList.size()));
398:
399: //---- tabellenlayout ----//
400: if ((TKVector) dataClass.rowData != null)
401: t.set("IS_ROWENTRY", Boolean.TRUE);
402:
403: if ((TKVector) dataClass.colData != null)
404: t.set("IS_COLENTRY", Boolean.TRUE);
405:
406: if (dataVector != null)
407: t.set("IS_OUTERLIST", Boolean.TRUE);
408:
409: //--- Ueberschrift ----//
410: if (isRowCell == false)
411: t.set("HEADERROW", Boolean.TRUE);
412: if (isColCell == false)
413: t.set("HEADERCOL", Boolean.TRUE);
414:
415: t.setListIterator(new TKTableColShowIterator(dataClass,
416: fieldList, rowEntry, colEntry, scope, getName(), t
417: .getListIterator(), "OUTERLIST", "INNERLIST",
418: "ROWFORINFOLIST"));
419:
420: }
421:
422: public Object modify(String action, String fieldPath, Object data,
423: String prefix, StringBuffer destination) {
424: TKFieldTableOrientedData dataClass = (TKFieldTableOrientedData) data;
425: TKVector dataVector = (TKVector) dataClass.contentData;
426:
427: int pLength = prefix.length() + fieldName.length();
428:
429: //--------------------------------------//
430: //----action betrifft Tabelle selbst----//
431: //--------------------------------------//
432: if (fieldPath.length() == pLength) {
433: int entryCount = fieldList.size();
434: int dataVectorSize = dataVector.size();
435:
436: if (action.equals("ADD")) {
437: TKVector colVector = new TKVector(entryCount);
438:
439: //---- Zusatzcol ----//
440: if (colEntry != null) {
441: dataClass.colData.addElement(colEntry.getDefault());
442: }
443:
444: //---- Zusatzrow HAT FESTE Groesse fest!!! ----//
445: for (int i = 0; i < entryCount; i++) {
446: TKBaseField field = (TKBaseField) fieldList.get(i);
447: colVector.addElement(field.getDefault());
448: }
449: dataVector.addElement(colVector);
450: destination.append(prefix + fieldName + "."
451: + (dataClass.contentData.size() - 1) + ".");
452: }
453: }
454: //----------------------------------------------------------//
455: //---- Action betrifft eine Zeile/Spalte der Tabelle -------//
456: //----------------------------------------------------------//
457: else if (fieldPath.length() - 3 == pLength) {
458:
459: int index = 0;
460: String subPath = fieldPath.substring(pLength + 1);
461: StringTokenizer getToken = new StringTokenizer(subPath, ".");
462: index = Integer.parseInt((String) getToken.nextElement());
463:
464: if (action.equals("DELETE")) {
465: if (index == 0)
466: destination.append(prefix + fieldName + "." + index
467: + ".");
468: else
469: destination.append(prefix + fieldName + "."
470: + (index - 1) + ".");
471: data = actionIsDelete(dataClass, index);
472: }
473:
474: if (action.equals("INSERT")) {
475: destination.append(prefix + fieldName + "." + index
476: + ".");
477: data = actionIsInsert(dataClass, index);
478:
479: }
480: if (action.equals("FIRST")) {
481: destination.append(prefix + fieldName + "." + 0 + ".");
482: dataClass = actionIsFirst(dataClass, index);
483: if (index != 0)
484: data = actionIsDelete(dataClass, index + 1);
485: }
486: if (action.equals("LAST")) {
487: destination.append(prefix + fieldName + "."
488: + (dataClass.contentData.size() - 1) + ".");
489: dataClass = actionIsLast(dataClass, index);
490: data = actionIsDelete(dataClass, index);
491:
492: }
493: if (action.equals("FORWARD")) {
494: if (index == dataClass.contentData.size() - 1)
495: destination.append(prefix + fieldName + "." + index
496: + ".");
497: else
498: destination.append(prefix + fieldName + "."
499: + (index + 1) + ".");
500: dataClass = actionIsForward(dataClass, index);
501: if (index != dataClass.contentData.size() - 1)
502: data = actionIsDelete(dataClass, index);
503:
504: }
505: if (action.equals("BACK")) {
506: if (index == 0)
507: destination.append(prefix + fieldName + "." + 0
508: + ".");
509: else
510: destination.append(prefix + fieldName + "."
511: + (index - 1) + ".");
512: dataClass = actionIsBack(dataClass, index);
513: if (index != 0)
514: data = actionIsDelete(dataClass, index + 1);
515: }
516: }
517: //-------------------------------------//
518: //---- action betrifft Sub-ELement ----//
519: //-------------------------------------//
520: else {
521:
522: String subZusatz = fieldPath.substring(pLength + 1);
523:
524: //---- modify des SubElementes in einer ZusatzRow ----//
525: if (subZusatz.startsWith(PRE_ROWS)) {
526: subZusatz = subZusatz.substring(PRE_ROWS.length() + 1);
527: int idxEnd = subZusatz.indexOf('.');
528: String idxStr = subZusatz.substring(0, idxEnd);
529: int idx = Integer.parseInt(idxStr);
530:
531: dataClass.rowData.put(idx, rowEntry.modify(action,
532: fieldPath, dataClass.rowData.get(idx), prefix
533: + fieldName + '.' + PRE_ROWS + "."
534: + idx + '.', destination));
535:
536: }
537: //---- modify des SubElementes in einer ZusatzCol ----//
538: else if (subZusatz.startsWith(PRE_COLS)) {
539: subZusatz = subZusatz.substring(PRE_COLS.length() + 1);
540: int idxEnd = subZusatz.indexOf('.');
541: String idxStr = subZusatz.substring(0, idxEnd);
542: int idx = Integer.parseInt(idxStr);
543: dataClass.colData.put(idx, colEntry.modify(action,
544: fieldPath, dataClass.colData.get(idx), prefix
545: + fieldName + '.' + PRE_COLS + "."
546: + idx + '.', destination));
547: }
548: //---- modify des SubElementes in einer Zelle ----//
549: else {
550: String subName = fieldPath.substring(pLength + 5);
551: int idx = subName.indexOf('.');
552: if (idx >= 0)
553: subName = subName.substring(0, idx);
554: TKBaseField field = (TKBaseField) tableFields
555: .get(subName);
556:
557: String subPath = fieldPath.substring(pLength + 1);
558: StringTokenizer getToken = new StringTokenizer(subPath,
559: ".");
560: int rowIdx = Integer.parseInt((String) getToken
561: .nextElement());
562: int colIdx = Integer.parseInt((String) getToken
563: .nextElement());
564:
565: TKVector colVector = (TKVector) dataVector
566: .elementAt(colIdx);
567:
568: colVector.put(rowIdx, field.modify(action, fieldPath,
569: colVector.get(rowIdx), prefix + fieldName + "."
570: + rowIdx + "." + colIdx + ".",
571: destination));
572:
573: }
574: }
575:
576: return data;
577: }
578:
579: public TKFieldTableOrientedData actionIsDelete(
580: TKFieldTableOrientedData dataClass, int index) {
581:
582: dataClass.contentData.removeElementAt(index);
583:
584: if ((rowEntry != null) && (dataClass.contentData.isEmpty()))
585: dataClass.rowData = null;
586:
587: if (colEntry != null)
588: if (dataClass.contentData.isEmpty())
589: dataClass.colData = null;
590: else
591: dataClass.colData.removeElementAt(index);
592:
593: return dataClass;
594: }
595:
596: public TKFieldTableOrientedData actionIsInsert(
597: TKFieldTableOrientedData dataClass, int index) {
598:
599: TKVector newVector = new TKVector();
600: for (int x = 0; x < fieldList.size(); x++) {
601: newVector.addElement(((TKBaseField) fieldList.elementAt(x))
602: .getDefault());
603: }
604: dataClass.contentData.insertElementAt(newVector, index);
605:
606: if (colEntry != null)
607: dataClass.colData.insertElementAt(colEntry.getDefault(),
608: index);
609:
610: return dataClass;
611: }
612:
613: public TKFieldTableOrientedData actionIsFirst(
614: TKFieldTableOrientedData dataClass, int index) {
615:
616: if (index > 0) {
617: TKVector insertVector = (TKVector) dataClass.contentData
618: .elementAt(index);
619: dataClass.contentData.insertElementAt(insertVector, 0);
620:
621: if (colEntry != null)
622: dataClass.colData.insertElementAt(dataClass.colData
623: .elementAt(index), 0);
624: }
625: return dataClass;
626: }
627:
628: public TKFieldTableOrientedData actionIsLast(
629: TKFieldTableOrientedData dataClass, int index) {
630: int size = dataClass.contentData.size();
631:
632: TKVector insertVector = (TKVector) dataClass.contentData
633: .elementAt(index);
634: dataClass.contentData.insertElementAt(insertVector, size);
635:
636: if (colEntry != null)
637: dataClass.colData.insertElementAt(dataClass.colData
638: .elementAt(index), size);
639: return dataClass;
640: }
641:
642: public TKFieldTableOrientedData actionIsBack(
643: TKFieldTableOrientedData dataClass, int index) {
644:
645: if (index == 0)
646: return dataClass;
647: if (index > 1) {
648: TKVector insertVector = (TKVector) dataClass.contentData
649: .elementAt(index);
650: dataClass.contentData.insertElementAt(insertVector,
651: index - 1);
652:
653: if (colEntry != null)
654: dataClass.colData.insertElementAt(dataClass.colData
655: .elementAt(index), index - 1);
656: } else if (index == 1) {
657: dataClass = actionIsFirst(dataClass, index);
658: }
659: return dataClass;
660: }
661:
662: public TKFieldTableOrientedData actionIsForward(
663: TKFieldTableOrientedData dataClass, int index) {
664: int size = dataClass.contentData.size();
665:
666: if (index == size - 1)
667: return dataClass;
668:
669: else {
670: TKVector insertVector = (TKVector) dataClass.contentData
671: .elementAt(index);
672: dataClass.contentData.insertElementAt(insertVector,
673: index + 2);
674:
675: if (colEntry != null)
676: dataClass.colData.insertElementAt(dataClass.colData
677: .elementAt(index), index + 2);
678: }
679: return dataClass;
680: }
681:
682: public int insertDataIntoDB(TKContentDBData db, Object data,
683: int contentId, int leftNr) {
684: int entryCount = fieldList.size();
685: if (entryCount == 0)
686: return leftNr;
687:
688: TKContentNodeTableData node = insertNewContentNode(db,
689: contentId, leftNr);
690: int newNodeId = node.content_node_id;
691:
692: TKFieldTableOrientedData dataClass = (TKFieldTableOrientedData) data;
693: TKVector dataVector = (TKVector) dataClass.contentData;
694:
695: insertNewContentValue(db, contentId, newNodeId, 0, String
696: .valueOf(dataVector != null ? dataVector.size() : 0));
697: leftNr++;
698:
699: //---- InfoRow ----//
700: if (rowEntry != null) {
701: for (int x = 0; x < fieldList.size(); x++) {
702: node.right_nr = rowEntry.insertDataIntoDB(db,
703: dataClass.rowData.elementAt(x), contentId,
704: leftNr + 1) + 1;
705: }
706: }
707:
708: //------ InfoCol ----//
709: if (colEntry != null) {
710: for (int x = 0; x < dataVector.size(); x++) {
711: node.right_nr = colEntry.insertDataIntoDB(db,
712: dataClass.colData.elementAt(x), contentId,
713: leftNr + 1) + 1;
714: }
715: }
716:
717: //---- Table ----//
718: if (dataVector != null) {
719: for (int x = 0; x < dataVector.size(); x++) {
720: for (int y = 0; y < entryCount; y++) {
721: TKBaseField field = (TKBaseField) fieldList.get(y);
722: leftNr = field.insertDataIntoDB(db,
723: ((TKVector) dataVector.elementAt(x))
724: .elementAt(y), contentId,
725: leftNr + 1);
726: leftNr++;
727: }
728: }
729: }
730:
731: node.right_nr = leftNr;
732: return leftNr;
733:
734: }
735:
736: public Object getDataFromDB(TKContentDBData db) {
737:
738: int entryCount = fieldList.size();
739: if (entryCount == 0)
740: return new TKVector();
741:
742: TKVector dataVector = new TKVector();
743: TKContentNodeTableData node = getContentNodeFromDB(db);
744:
745: TKContentValueTableData value0 = getContentNodeValueFromDB(db,
746: node);
747: int dataVectorSize = Integer.parseInt(value0.value);
748:
749: TKVector rowInfoVector = new TKVector(entryCount);
750: TKVector colInfoVector = new TKVector(dataVectorSize);
751:
752: //---- Info Row ----//
753: if (rowEntry != null) {
754: for (int x = 0; x < entryCount; x++) {
755: rowInfoVector.addElement(rowEntry.getDataFromDB(db));
756: }
757: } else
758: rowInfoVector = null;
759:
760: //---- Info Col ----//
761: if (colEntry != null) {
762: for (int x = 0; x < dataVectorSize; x++) {
763: colInfoVector.addElement(colEntry.getDataFromDB(db));
764: }
765: } else
766: colInfoVector = null;
767:
768: //---- table ----//
769: for (int x = 0; x < dataVectorSize; x++) {
770: TKVector colVector = new TKVector(entryCount);
771: for (int i = 0; i < entryCount; i++) {
772: TKBaseField field = (TKBaseField) fieldList.get(i);
773: colVector.addElement(field.getDataFromDB(db));
774: }
775: dataVector.addElement(colVector);
776: }
777:
778: return new TKFieldTableOrientedData(dataVector, rowInfoVector,
779: colInfoVector);
780: }
781:
782: }
|