KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Header: /cvsroot/webman-cms/source/webman/com/teamkonzept/field/TKTableShowIterator.java,v 1.8 2001/02/11 14:48:15 alex Exp $
3  *
4  */

5 /**
6  * Die Zellen einer Tabelle beinhalten jeweils das gleiche BaseField.
7  * Dies gilt auch fuer die Zusatz-Zeile/Spalte.
8  *
9  * Folgende Moeglichkeiten bestehen:
10  * 1. Anlegen von Tabellen variabler Groesse
11  * 2. Anlegen von einer Zeile/Spalte, die Zusatzinformationen enthalten
12  * 3. Auswahl der Inhalte (Fields) der Zellen
13  * 4. Auswahl der Inhalte (Fields) der Zusatzz-Zeilen/Spalten
14  * 5. Anzeigen der Tabelle
15  * 6. Das modifizieren der Tabelle selbst
16  * - Loeschen von Zeilen/Spalten
17  * - Einfuegen von Zeilen/Spalten
18  * - Vertauschen von Zeilen/Spalten
19  * 7. Speichern aller Daten in die Datenbank
20  * 8. Speichern aller Strukturinformationen in die Datenbank
21  *
22  * Um Verwechselungen zu vermeiden:
23  *
24  * --------------------------------
25  * | Col-Zusatz-Vektor |
26  * --------------------------------
27  * ------
28  * | Row- |
29  * | zu- |
30  * | satz | TABELLE
31  * | vek- |
32  * | tor |
33  * | |
34  * ------
35  */

36 package com.teamkonzept.field;
37
38 import com.teamkonzept.lib.*;
39 import com.teamkonzept.web.*;
40
41 public class TKTableShowIterator implements TKListIterator {
42     
43     TKListIterator oldIterator;
44     String JavaDoc outerList;
45     String JavaDoc innerList;
46     TKFieldTableRealData dataClass;
47     String JavaDoc tableScope;
48     String JavaDoc scope;
49     String JavaDoc fieldTableName;
50     //int outerIndex;
51
String JavaDoc fieldType;
52     TKBaseField rowField;
53     TKBaseField colField;
54     TKBaseField contentField;
55     String JavaDoc listRowForInfo;
56
57         
58     public TKTableShowIterator (
59         TKFieldTableRealData dataClass,
60         TKBaseField contentField,
61         TKBaseField rowField,
62         TKBaseField colField,
63         String JavaDoc scope,
64         String JavaDoc fieldTableName,
65         TKListIterator oldIterator,
66         String JavaDoc outerList,
67         String JavaDoc innerList,
68         String JavaDoc listRowForInfo
69     )
70     {
71         this.oldIterator = oldIterator;
72         this.outerList = outerList;
73         this.innerList = innerList;
74         this.dataClass = dataClass;
75         this.fieldType = fieldType;
76         this.rowField = rowField;
77         this.colField = colField;
78         this.contentField = contentField;
79         this.listRowForInfo = listRowForInfo;
80         //this.outerIndex = 0;
81
this.fieldTableName = fieldTableName;
82         this.scope = scope;
83         this.tableScope = scope+"."+fieldTableName;
84         
85     }
86
87
88     /**
89      * ODD: gibt an, ob der aktuelle Index gerade oder ungerade ist.
90      * Hiermit besteht die Moeglichkeit (z.B.) Jede 2. Zeile/Spalte
91      * anders zu colorieren
92      */

93     public static final void enterCounter(
94         TKHTMLTemplate t,
95         int idx,
96         String JavaDoc scope,
97         String JavaDoc kind
98     )
99     {
100         t.set( scope+"."+kind+"IDX", String.valueOf(idx+1) );
101         if( idx % 2 == 1 ) t.set( scope+".ODD"+kind, Boolean.TRUE );
102     }
103     
104     public static final void enterEntry(
105         TKHTMLTemplate t,
106         int idx,
107         Object JavaDoc data,
108         TKBaseField showField,
109         String JavaDoc scope,
110         String JavaDoc kind
111     )
112     {
113         enterCounter( t, idx, scope, kind );
114         showField.fillIntoPresentation( t, data, scope );
115     }
116
117     public boolean apply( TKTemplate t, int i, String JavaDoc currListName )
118     {
119         TKHTMLTemplate template = (TKHTMLTemplate) t;
120         TKVector dataVector = (TKVector) dataClass.contentData;
121         //---- Row mit den Infos ----//
122
if( currListName.equalsIgnoreCase(tableScope+"."+listRowForInfo))
123         {
124             TKVector colDataVector = dataClass.colData;
125             if( (colDataVector == null) || (i >= colDataVector.size())) return false;
126             
127             template.set( "SCOPE", tableScope );
128             enterEntry( template, i, colDataVector.elementAt(i), colField, tableScope+".COLS", "COL" );
129             return true;
130         }
131         //---- aeussere liste ----//
132
if( currListName.equalsIgnoreCase(tableScope+"."+outerList) ) {
133             if( (dataVector == null) || (i >= dataVector.size()) ) return false;
134             //outerIndex = i;
135
template.setEnumerationContext( currListName, new Integer JavaDoc(i) );
136             template.set( "SCOPE", tableScope );
137             enterCounter( template, i, tableScope, "ROW" );
138
139             //---- Zusatz Row ----//
140
TKVector rowDataVector = dataClass.rowData;
141             if( (rowDataVector != null) && (rowDataVector.size() > 0) ) {
142                 enterEntry( template, i, rowDataVector.elementAt(i), rowField, tableScope+".ROWS", "ROW" );
143             }
144             return true;
145         }
146         //---- innere liste ----//
147
else if( currListName.equalsIgnoreCase(tableScope+"."+innerList) ) {
148             if(dataVector == null) return false;
149
150             int outerIndex = ((Integer JavaDoc)template.getEnumerationContext(tableScope+"."+outerList)).intValue();
151             TKVector dataRow = (TKVector)dataVector.get(outerIndex);
152             if( i >= dataRow.size() ) return false;
153             
154             enterEntry( template, i, dataRow.get(i), contentField, tableScope, "COL" );
155
156             //---- Zusatz Row ----//
157
TKVector colDataVector = dataClass.colData;
158             if( (colDataVector != null) ) {
159                 enterEntry( template, i, colDataVector.elementAt(i), colField, tableScope+".COLS", "COL" );
160             }
161
162             return true;
163         }
164         else if( oldIterator != null ) {
165             return oldIterator.apply( template, i, currListName );
166         }
167         else {
168             return false;
169         }
170     }
171 }//end class
172

173
Popular Tags