package com.teamkonzept.field;
import java.util.*;
import com.teamkonzept.lib.*;
import com.teamkonzept.publishing.markups.*;
import com.teamkonzept.web.*;
import com.teamkonzept.field.db.*;
import com.teamkonzept.international.LanguageManager;
public class TKFieldTableRowOriented
extends TKFieldTableOriented
{
// $Id: TKFieldTableRowOriented.java,v 1.17 2001/09/21 14:22:06 uli Exp $
public static final String CLASS_ID = "FIELDTABLEROWORIENTED";
public TKFieldTableRowOriented() {}
public TKFieldTableRowOriented( String name, TKVector fields )
{
this( name, fields, null, null );
}
public TKFieldTableRowOriented(
String name,
TKVector fields,
TKBaseField rowEntry,
TKBaseField colEntry )
{
this( name, fields, rowEntry, colEntry, null );
}
public TKFieldTableRowOriented(
String name,
TKVector fields,
TKBaseField rowEntry,
TKBaseField colEntry ,
String showName )
{
initFieldTableRowOriented( "FIELDTABLEROWORIENTED", name, fields, rowEntry, colEntry, showName );
}
public final void initFieldTableRowOriented(
String fieldType,
String name,
TKVector fields,
TKBaseField rowEntry,
TKBaseField colEntry ,
String showName )
{
initFieldTableOriented( "FIELDTABLEROWORIENTED", name, fields, rowEntry, colEntry, showName );
}
/**
* Methode zur Definition Row-Orientierter Tabellen
*/
public TKFieldGroup getDefGroup(TKFieldSwitch allSwitch, TKFieldSwitchList allSwitchList) {
TKBaseField [] groupTableArray = {
allSwitchList
};
//======================= Switch und Check =================//
//---- Eine Checkbox, falls "Yes" selectiert wurde ----//
TKVector singleCheckVector = new TKVector(2);
singleCheckVector.addElement(
new TKOptionFieldEntry( LanguageManager.getText(LANGUAGE_CONTEXT, "FIELDTABLE_CELL"), "CELL" ) );
singleCheckVector.addElement(
new TKOptionFieldEntry( LanguageManager.getText(LANGUAGE_CONTEXT, "FIELDTABLE_ROW_COLUMN"), "NOCELL" ) );
TKBaseField [] switchAndCheckArray = {
new TKSelectField( "ZUSATZ", LanguageManager.getText(LANGUAGE_CONTEXT, "FIELDTABLE_ADDINFO"),singleCheckVector ),
allSwitch
};
//======================= SPALTENINFOS =================//
//---- Gruppe wird erzeugt mit einer Switchauswahl und einer Checkbox ----//
TKFieldGroup switchAndCheckGroup =
new TKFieldGroup( TKFieldOption.CLASS_ID, new TKVector( switchAndCheckArray ), LanguageManager.getText(LANGUAGE_CONTEXT, "FIELDTABLE_INFOCOLUMN"));
//================== ZEILENINFOS =====================/
//---- Gruppe wird erzeugt mit einer Switchauswahl und einer Checkbox ----//
TKFieldGroup switchAndCheckGroup2 =
new TKFieldGroup( TKFieldOption.CLASS_ID, new TKVector( switchAndCheckArray ), LanguageManager.getText(LANGUAGE_CONTEXT, "FIELDTABLE_INFOROW") );
//========================= TABELLE ==================================//
TKFieldGroup groupGroupTable =
new TKFieldGroup( TKFieldGroup.CLASS_ID, new TKVector( groupTableArray ), LanguageManager.getText(LANGUAGE_CONTEXT, "FIELDTABLE_GROUPING"));
TKBaseField [] tableRowOrientedArray = {
new TKInputField( TKFieldTableRowOriented.NAME_KEY, 16, 80, LanguageManager.getText(LANGUAGE_CONTEXT, "FIELDTABLE_NAME"), TKInputField.CHECK_STRING),
new TKInputField( TKFieldTableRowOriented.SHOW_NAME_KEY, 50, 254, LanguageManager.getText(LANGUAGE_CONTEXT, "FIELDTABLE_SHOWNAME"), TKInputField.CHECK_STRING),
allSwitchList,
new TKFieldOption( "JANEINSPALTE", switchAndCheckGroup, LanguageManager.getText(LANGUAGE_CONTEXT, "FIELDTABLE_JANEINSPALTE")),
new TKFieldOption( "JANEINZEILE", switchAndCheckGroup2, LanguageManager.getText(LANGUAGE_CONTEXT, "FIELDTABLE_JANEINZEILE"))
};
TKFieldGroup tableRowOrientedGroup =
new TKFieldGroup( TKFieldTableRowOriented.CLASS_ID, new TKVector( tableRowOrientedArray ), LanguageManager.getText(LANGUAGE_CONTEXT, TKFieldTableRowOriented.CLASS_ID) );
return tableRowOrientedGroup;
}
//***********************************************************************
public Object compileData( String prefix, TKHashtable data, TKHashtable context )
{
int entryCount = fieldList.size();
if( entryCount == 0 ) return new TKFieldTableOrientedData(null, null, null);
TKVector result = new TKVector(1);
TKVector colVector = null;
prefix = subPrefix( prefix );
int tableSize = Integer.parseInt( (String)data.get(prefix+"SIZE") );
int cols = entryCount;
int rows = tableSize;
//-----------------------------------//
//---- Data fuer eine zusatz ROW ----//
//-----------------------------------//
TKVector rowInfoVector = null;
if(rowEntry != null) {
rowInfoVector = new TKVector();
for( int x=0; x< rows; x++ ) {
rowInfoVector.addElement(rowEntry.compileData( prefix+PRE_ROWS+"."+x+".", data, context ));
}
}
//---------------------------------------//
//---- Data fuer eine zusatz COLUMN ----//
//---------------------------------------//
TKVector colInfoVector = null;
if((colEntry != null) && (cols > 0) ){
colInfoVector = new TKVector(cols);
if(rows > 0) {
for( int x=0; x< cols; x++ ) {
colInfoVector.addElement(colEntry.compileData( prefix+PRE_COLS+"."+x+".", data, context ));
}
}
else {
for( int x=0; x< cols; x++ ) {
colInfoVector.addElement(colEntry.getDefault());
}
}
}
//-----------------//
//---- tabelle ----//
//-----------------//
for(int x=0; x < tableSize; x++) {
colVector = new TKVector( entryCount );
for( int y=0; y<entryCount; y++ ) {
TKBaseField field = (TKBaseField) fieldList.get( y );
colVector.addElement(field.compileData(prefix+x+"."+y+".", data, context) );
}
result.addElement(colVector);
}
return new TKFieldTableOrientedData(result, rowInfoVector, colInfoVector);
}
public Object compileData( String prefix, TKMarkupNode data, TKHashtable context )
{
int entryCount = fieldList.size();
if( entryCount == 0 ) return new TKFieldTableOrientedData(null, null, null);
TKXmlMarkup markup = data == null ? null : (TKXmlMarkup) data.markup;
if (markup == null) { return null;}
if (!markup.name.equals (getName())) {
return null;
}
TKXmlTree tree = (TKXmlTree) data.tree;
if (tree == null) { return null;}
TKVector rowInfoVector = null;
TKVector colInfoVector = null;
TKVector result = null;
int x = 0;
for (int i = 0; i < tree.size(); i++) {
Object obj = tree.getSub(i);
if (obj == null) continue;
TKMarkupNode subNode = null;
TKXmlMarkup subMarkup = null;
if (obj instanceof TKXmlMarkup) { // Atomares Markup
subMarkup = (TKXmlMarkup) obj;
continue;
} else {
subNode = (TKMarkupNode) obj;
subMarkup = (TKXmlMarkup) subNode.markup;
}
if (subMarkup.name.equals ("CI")) {
TKXmlTree subTree = (TKXmlTree) subNode.tree;
if (subTree == null) { continue; }
for (int j = 0; j < subTree.size(); j++) {
Object subObj = subTree.getSub(j);
if (subObj == null) continue;
TKMarkupNode subSubNode = null;
TKXmlMarkup subSubMarkup = null;
if (subObj instanceof TKXmlMarkup) { // Atomares Markup
subSubMarkup = (TKXmlMarkup) subObj;
subSubNode = new TKMarkupNode (subSubMarkup,null);
} else {
subSubNode = (TKMarkupNode) subObj;
subSubMarkup = (TKXmlMarkup) subSubNode.markup;
}
if (colInfoVector == null) colInfoVector = new TKVector();
colInfoVector.addElement(colEntry.compileData( prefix+j+".", subSubNode, context ));
}
}
else if (subMarkup.name.equals ("TR")) {
TKVector colsResultVector = null;
TKXmlTree subTree = (TKXmlTree) subNode.tree;
if (subTree == null) { continue; }
int y = 0;
for (int j = 0; j < subTree.size(); j++) {
Object subObj = subTree.getSub(j);
if (subObj == null) continue;
if (y >= entryCount) {
break;
}
TKMarkupNode subSubNode = null;
TKXmlMarkup subSubMarkup = null;
if (subObj instanceof TKXmlMarkup) { // Atomares Markup
subSubMarkup = (TKXmlMarkup) subObj;
subSubNode = new TKMarkupNode (subSubMarkup,null);
} else {
subSubNode = (TKMarkupNode) subObj;
subSubMarkup = (TKXmlMarkup) subSubNode.markup;
}
TKXmlTree subSubTree = (TKXmlTree) subSubNode.tree;
Object subSubObj = subSubTree.getSingleSub();
if (subSubObj == null) continue;
TKMarkupNode subSubSubNode = null;
TKXmlMarkup subSubSubMarkup = null;
if (subSubObj instanceof TKXmlMarkup) { // Atomares Markup
subSubSubMarkup = (TKXmlMarkup) subSubObj;
subSubSubNode = new TKMarkupNode (subSubSubMarkup,null);
} else {
subSubSubNode = (TKMarkupNode) subSubObj;
subSubSubMarkup = (TKXmlMarkup) subSubSubNode.markup;
}
if (subSubMarkup.name.equals ("RI")) {
if (rowInfoVector == null) rowInfoVector = new TKVector();
rowInfoVector.addElement(rowEntry.compileData( prefix+j+".", subSubSubNode, context ));
} else {
if (result == null) result = new TKVector();
if (colsResultVector == null) {
colsResultVector = new TKVector();
result.addElement(colsResultVector);
}
TKBaseField field = (TKBaseField) fieldList.get( y );
if (field == null)
;
else colsResultVector.addElement
(field.compileData( prefix+x+"."+y+".", subSubSubNode, context ));
y++;
}
}
x++;
}
else {
;
}
}
return new TKFieldTableOrientedData(result, rowInfoVector, colInfoVector);
}
public void fillIntoTemplate( TKHTMLTemplate t, Object data, String prefix )
{
TKFieldTableOrientedData dataClass = (TKFieldTableOrientedData) data;
TKVector dataVector = (TKVector) dataClass.contentData;
super.fillIntoTemplate( t, data, prefix );
if(dataVector == null) {
t.set("SIZE", "0");
}
else {
t.set("SIZE", String.valueOf(dataVector.size()) );
t.set("IS_OUTERLIST", Boolean.TRUE);
}
int rows = ( dataVector == null ? 0 : dataVector.size() );
int cols = fieldList.size();
if( (TKVector)dataClass.rowData != null )
t.set("IS_COLFORINFOS", Boolean.TRUE);
if( (TKVector)dataClass.colData != null )
t.set("IS_ROWFORINFOS", Boolean.TRUE);
t.setListIterator( new TKFieldTableRowOrientedIterator(
dataClass,
fieldList,
rowEntry,
colEntry,
subPrefix( prefix ),
t.getListIterator(),
"OUTERLIST",
"INNERLIST",
"ROWFORINFOLIST",
fieldType
) );
//t.set( "FIELDTABLELIST", Boolean.TRUE );
}
public void fillIntoPresentation( TKHTMLTemplate t, Object data, String scope )
{
TKFieldTableOrientedData dataClass = (TKFieldTableOrientedData) data;
TKVector dataVector = (TKVector) dataClass.contentData;
t.set(scope+"."+getName()+".COLSIZE", String.valueOf( dataVector.size() ) );
t.set(scope+"."+getName()+".ROWSIZE", String.valueOf( fieldList.size() ) );
//---- tabellenlayout ----//
if( (TKVector)dataClass.rowData != null )
t.set("IS_ROWENTRY", Boolean.TRUE);
if( (TKVector)dataClass.colData != null )
t.set("IS_COLENTRY", Boolean.TRUE);
if(dataVector != null)
t.set("IS_OUTERLIST", Boolean.TRUE);
//--- Ueberschrift ----//
if(isRowCell == false)
t.set("HEADERROW", Boolean.TRUE);
if(isColCell == false)
t.set("HEADERCOL", Boolean.TRUE);
t.setListIterator( new TKTableRowShowIterator(
dataClass,
fieldList,
rowEntry,
colEntry,
scope,
getName(),
t.getListIterator(),
"OUTERLIST",
"INNERLIST",
"ROWFORINFOLIST"
) );
}
//***********************************************************************
public Object modify( String action, String fieldPath, Object data, String prefix, StringBuffer destination )
{
TKFieldTableOrientedData dataClass = (TKFieldTableOrientedData) data;
TKVector dataVector = (TKVector) dataClass.contentData;
int pLength = prefix.length()+fieldName.length();
//--------------------------------------//
//----action betrifft Tabelle selbst----//
//--------------------------------------//
if(fieldPath.length() == pLength ) {
int entryCount = fieldList.size();
int dataVectorSize = dataVector.size();
if(action.equals("ADD")) {
TKVector colVector = new TKVector( entryCount );
//---- Zusatztrow ----//
if( rowEntry != null ) {
dataClass.rowData.addElement(rowEntry.getDefault());
}
//---- Zusatzcol HAT FESTE Groesse fest!!! ----//
for( int i=0; i<entryCount; i++ ) {
TKBaseField field = (TKBaseField) fieldList.get( i );
colVector.addElement(field.getDefault() );
}
dataVector.addElement(colVector);
destination.append( prefix+fieldName+"."+(dataClass.contentData.size()-1)+".");
}
}
//----------------------------------------------------------//
//---- Action betrifft eine Zeile/Spalte der Tabelle -------//
//----------------------------------------------------------//
else if(fieldPath.length()-3 == pLength) {
int index = 0;
String subPath = fieldPath.substring( pLength+1 );
StringTokenizer getToken = new StringTokenizer( subPath, ".");
index = Integer.parseInt( (String)getToken.nextElement() );
if(action.equals("DELETE")) {
if(index == 0)
destination.append( prefix+fieldName+"."+index+".");
else
destination.append( prefix+fieldName+"."+(index-1)+".");
data = actionIsDelete(dataClass, index);
}
if(action.equals("INSERT")) {
destination.append( prefix+fieldName+"."+index+".");
dataClass = actionIsInsert(dataClass, index);
}
if(action.equals("FIRST")) {
destination.append( prefix+fieldName+"."+0+".");
dataClass = actionIsFirst(dataClass, index);
if(index != 0)
data = actionIsDelete(dataClass, index+1);
}
if(action.equals("LAST")) {
destination.append( prefix+fieldName+"."+(dataClass.contentData.size()-1)+".");
dataClass = actionIsLast(dataClass, index);
data = actionIsDelete(dataClass, index);
}
if(action.equals("FORWARD")) {
if(index == dataClass.contentData.size()-1)
destination.append( prefix+fieldName+"."+index+".");
else
destination.append( prefix+fieldName+"."+(index+1)+".");
dataClass = actionIsForward(dataClass, index);
if(index != dataClass.contentData.size()-1)
data = actionIsDelete(dataClass, index);
}
if(action.equals("BACK")) {
if(index == 0)
destination.append( prefix+fieldName+"."+0+".");
else
destination.append( prefix+fieldName+"."+(index-1)+".");
dataClass = actionIsBack(dataClass, index);
if(index != 0)
data = actionIsDelete(dataClass, index+1);
}
}
//-------------------------------------//
//---- action betrifft Sub-ELement ----//
//-------------------------------------//
else {
String subZusatz = fieldPath.substring( pLength+1);
//---- modify des SubElementes in einer ZusatzRow ----//
if( subZusatz.startsWith( PRE_ROWS ) ) {
subZusatz = subZusatz.substring( PRE_ROWS.length()+1 );
int idxEnd = subZusatz.indexOf('.');
String idxStr = subZusatz.substring( 0, idxEnd );
int idx = Integer.parseInt( idxStr );
dataClass.rowData.put( idx, rowEntry.modify(
action, fieldPath, dataClass.rowData.get( idx ),
prefix+fieldName+'.'+PRE_ROWS+"."+idx+'.', destination
) );
}
//---- modify des SubElementes in einer ZusatzCol ----//
else if( subZusatz.startsWith( PRE_COLS ) ) {
subZusatz = subZusatz.substring( PRE_COLS.length()+1 );
int idxEnd = subZusatz.indexOf('.');
String idxStr = subZusatz.substring( 0, idxEnd );
int idx = Integer.parseInt( idxStr );
dataClass.colData.put( idx, colEntry.modify(
action, fieldPath, dataClass.colData.get( idx ),
prefix+fieldName+'.'+PRE_COLS+"."+idx+'.',
destination
) );
}
//---- modify des SubElementes in einer Zelle ----//
else {
String subName = fieldPath.substring( pLength+5);
int idx = subName.indexOf('.');
if(idx >= 0)
subName = subName.substring(0,idx);
TKBaseField field = (TKBaseField) tableFields.get( subName );
String subPath = fieldPath.substring( pLength+1);
StringTokenizer getToken = new StringTokenizer(subPath, ".");
int rowIdx = Integer.parseInt( (String) getToken.nextElement() );
int colIdx = Integer.parseInt( (String) getToken.nextElement() );
TKVector rowVector = (TKVector) dataVector.elementAt(rowIdx);
rowVector.put( colIdx, field.modify(
action, fieldPath, rowVector.get(colIdx),
prefix+fieldName+"."+rowIdx+"."+colIdx+".", destination
) );
}
}
return data;
}
public TKFieldTableOrientedData actionIsDelete( TKFieldTableOrientedData dataClass, int index )
{
dataClass.contentData.removeElementAt(index);
if( (colEntry != null) && (dataClass.contentData.isEmpty()) )
dataClass.colData = null;
if(rowEntry != null)
if (dataClass.contentData.isEmpty() )
dataClass.rowData = null;
else
dataClass.rowData.removeElementAt(index);
return dataClass;
}
//*************************************************************************************
public TKFieldTableOrientedData actionIsInsert( TKFieldTableOrientedData dataClass, int index )
{
TKVector newVector = new TKVector ();
for(int x = 0; x < fieldList.size(); x++) {
newVector.addElement( ( (TKBaseField)fieldList.elementAt(x)).getDefault());
}
dataClass.contentData.insertElementAt(newVector,index);
if(rowEntry != null)
dataClass.rowData.insertElementAt(rowEntry.getDefault(), index);
return dataClass;
}
//*************************************************************************************
public TKFieldTableOrientedData actionIsFirst( TKFieldTableOrientedData dataClass, int index )
{
if(index > 0) {
TKVector insertVector = (TKVector) dataClass.contentData.elementAt(index);
dataClass.contentData.insertElementAt(insertVector,0);
if(rowEntry != null)
dataClass.rowData.insertElementAt(dataClass.rowData.elementAt(index), 0);
}
return dataClass;
}
//*************************************************************************************
public TKFieldTableOrientedData actionIsLast( TKFieldTableOrientedData dataClass, int index )
{
int size = dataClass.contentData.size();
TKVector insertVector = (TKVector) dataClass.contentData.elementAt(index);
dataClass.contentData.insertElementAt(insertVector,size);
if(rowEntry != null)
dataClass.rowData.insertElementAt(dataClass.rowData.elementAt(index), size);
return dataClass;
}
public TKFieldTableOrientedData actionIsBack( TKFieldTableOrientedData dataClass, int index )
{
if(index == 0) return dataClass;
if(index > 1) {
TKVector insertVector = (TKVector) dataClass.contentData.elementAt(index);
dataClass.contentData.insertElementAt(insertVector,index-1);
if(rowEntry != null)
dataClass.rowData.insertElementAt(dataClass.rowData.elementAt(index), index-1);
}
else if(index == 1) {
dataClass = actionIsFirst(dataClass, index);
}
return dataClass;
}
public TKFieldTableOrientedData actionIsForward( TKFieldTableOrientedData dataClass, int index )
{
int size = dataClass.contentData.size();
if(index == size-1) return dataClass;
else {
TKVector insertVector = (TKVector) dataClass.contentData.elementAt(index);
dataClass.contentData.insertElementAt(insertVector,index+2);
if(rowEntry != null)
dataClass.rowData.insertElementAt(dataClass.rowData.elementAt(index), index+2);
}
return dataClass;
}
//***********************************************************************
public int insertDataIntoDB( TKContentDBData db, Object data, int contentId, int leftNr )
{
int entryCount = fieldList.size();
if( entryCount == 0 ) return leftNr;
TKContentNodeTableData node = insertNewContentNode( db, contentId, leftNr );
int newNodeId = node.content_node_id;
TKFieldTableOrientedData dataClass = (TKFieldTableOrientedData) data;
TKVector dataVector = (TKVector) dataClass.contentData;
insertNewContentValue(db, contentId, newNodeId, 0, String.valueOf(dataVector != null ? dataVector.size() : 0));
leftNr++;
//---- InfoRow ----//
if(rowEntry != null) {
for (int x=0; x < dataVector.size(); x++) {
node.right_nr = rowEntry.insertDataIntoDB( db, dataClass.rowData.elementAt(x), contentId, leftNr+1 )+1;
}
}
//------ InfoCol ----//
if(colEntry != null) {
for (int x=0; x < fieldList.size(); x++) {
node.right_nr = colEntry.insertDataIntoDB( db, dataClass.colData.elementAt(x), contentId, leftNr+1 )+1;
}
}
//---- Table ----//
if(dataVector != null) {
for(int x= 0; x < dataVector.size(); x++) {
for( int y=0; y< entryCount; y++ ) {
TKBaseField field = (TKBaseField) fieldList.get( y );
leftNr = field.insertDataIntoDB( db, ((TKVector) dataVector.elementAt(x)).elementAt(y), contentId, leftNr+1 );
leftNr++;
}
}
}
node.right_nr = leftNr;
return leftNr;
}
//***********************************************************************
public Object getDataFromDB( TKContentDBData db )
{
int entryCount = fieldList.size();
if( entryCount == 0 ) return new TKVector();
TKVector dataVector = new TKVector( );
TKContentNodeTableData node = getContentNodeFromDB( db );
TKContentValueTableData value0 = getContentNodeValueFromDB(db, node);
int dataVectorSize = Integer.parseInt( value0.value);
TKVector rowInfoVector = new TKVector(dataVectorSize );
TKVector colInfoVector = new TKVector(entryCount);
//---- Info Row ----//
if(rowEntry != null) {
for( int x=0; x< dataVectorSize; x++ ) {
rowInfoVector.addElement(rowEntry.getDataFromDB( db ));
}
}
else rowInfoVector = null;
//---- Info Col ----//
if(colEntry != null) {
for( int x=0; x< entryCount; x++ ) {
colInfoVector.addElement(colEntry.getDataFromDB( db ));
}
}
else colInfoVector = null;
//---- table ----//
for(int x=0; x < dataVectorSize; x++) {
TKVector colVector = new TKVector(entryCount);
for( int i=0; i < entryCount; i++ ) {
TKBaseField field = (TKBaseField) fieldList.get( i );
colVector.addElement(field.getDataFromDB( db ));
}
dataVector.addElement(colVector);
}
return new TKFieldTableOrientedData(dataVector, rowInfoVector, colInfoVector);
}
}
|