/************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * Copyright 2008 by Sun Microsystems, Inc. * * OpenOffice.org - a multi-platform office productivity suite * * This file is part of OpenOffice.org. * * OpenOffice.org is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License version 3 * only, as published by the Free Software Foundation. * * OpenOffice.org is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License version 3 for more details * (a copy is included in the LICENSE file that accompanied this code). * * You should have received a copy of the GNU Lesser General Public License * version 3 along with OpenOffice.org. If not, see * * for a copy of the LGPLv3 License. * ************************************************************************/ package integration.forms; import com.sun.star.awt.XListBox; import com.sun.star.beans.XPropertySet; import com.sun.star.container.XChild; import com.sun.star.container.XIndexAccess; import com.sun.star.container.XNameAccess; import com.sun.star.form.ListSourceType; import com.sun.star.form.runtime.FormFeature; import com.sun.star.form.runtime.XFormController; import com.sun.star.form.runtime.XFormOperations; import com.sun.star.sdb.CommandType; import com.sun.star.sdbc.SQLException; import com.sun.star.sdbc.XParameters; import com.sun.star.sdbc.XPreparedStatement; import com.sun.star.uno.Exception; import com.sun.star.uno.UnoRuntime; import connectivity.tools.HsqlColumnDescriptor; import connectivity.tools.HsqlDatabase; import connectivity.tools.HsqlTableDescriptor; import connectivity.tools.sdb.Connection; import java.util.HashMap; import java.util.Map; import java.util.Vector; public class ListBox extends TestCase { HsqlDatabase m_database = null; private final String m_foreignKeyTableName = "foreign_keys"; public ListBox() { super( DocumentType.WRITER ); } /* ------------------------------------------------------------------ */ public String[] getTestMethodNames() { return new String[] { "checkForeignKeys" }; } /* ------------------------------------------------------------------ */ public void checkForeignKeys() throws com.sun.star.uno.Exception, java.lang.Exception { try { // create the form document prepareDocument(); final XIndexAccess formsCollection = UnoRuntime.queryInterface( XIndexAccess.class, m_document.getFormComponentTreeRoot() ); final XNameAccess form = UnoRuntime.queryInterface( XNameAccess.class, formsCollection.getByIndex(0) ); final DocumentViewHelper view = m_document.getCurrentView(); final XFormController formController = view.getFormController( form ); final XFormOperations formOperations = formController.getFormOperations(); // move through all records, and check that the display values in the list boxes are as expected final String[][] fieldTypesDefinitions = impl_getFieldTypeDefinitions(); final String[] fieldTypes = fieldTypesDefinitions[0]; final String[] displayValues = impl_getDisplayValues(); formOperations.execute( FormFeature.MoveToFirst ); for ( int row=0; row<2; ++row ) { StringBuffer failedFieldTypes = new StringBuffer(); for ( int i=0; i 0 ) failedFieldTypes.append( ", " ); failedFieldTypes.append( fieldTypes[i] ); } } /*assure( "The following field types do not work when used as bound list box fields: " + failedFieldTypes.toString() + " (row " + row + ")", failedFieldTypes.length() == 0 );*/ formOperations.execute( FormFeature.MoveToNext ); } } finally { closeDocument(); } } /* ------------------------------------------------------------------ */ public void before() throws Exception, java.lang.Exception { super.before(); impl_createDatabase(); } /* ------------------------------------------------------------------ */ protected void prepareDocument() throws com.sun.star.uno.Exception, java.lang.Exception { super.prepareDocument(); impl_createForm(); } /* ------------------------------------------------------------------ */ private String[][] impl_getFieldTypeDefinitions() { return new String[][] { new String[] { "bigint", "boolean", "date", "decimal", "double", "float", "numeric", "time", "timestamp", "tinyint", "varchar" }, new String[] { null, null, null, "(10,2)", null, null, "(10,2)", null, null, null, "(50)" } }; } /* ------------------------------------------------------------------ */ private String[] impl_getTypedValue( final String _asType, final int _rowNum ) throws SQLException { Map< String, String[] > valueMap = new HashMap< String, String[] >(); valueMap.put( "bigint", new String[] { "1111111111", "222222222" } ); valueMap.put( "boolean", new String[] { "false", "true" } ); valueMap.put( "date", new String[] { "2001-01-01", "2002-02-02" } ); valueMap.put( "decimal", new String[] { "1.11", "2.22" } ); valueMap.put( "double", new String[] { "1.11", "2.22" } ); valueMap.put( "float", new String[] { "1.11", "2.22" } ); valueMap.put( "numeric", new String[] { "1.11", "2.22" } ); valueMap.put( "time", new String[] { "01:01:01", "02:02:02" } ); valueMap.put( "timestamp", new String[] { "2001-01-01 01:01:01", "2002-02-02 02:02:02" } ); valueMap.put( "tinyint", new String[] { "1", "2" } ); valueMap.put( "varchar", new String[] { "first", "second" } ); return valueMap.get( _asType ); } /* ------------------------------------------------------------------ */ private String[] impl_getDisplayValues() { return new String[] { "one", "two" }; } /* ------------------------------------------------------------------ */ private void impl_createDatabase() throws java.lang.Exception { try { m_database = new HsqlDatabase( m_orb ); Connection connection = m_database.defaultConnection(); System.out.println( m_database.getDocumentURL() ); final String[][] fieldDefinitions = impl_getFieldTypeDefinitions(); final String[] keyTypes = fieldDefinitions[0]; final String[] keyCreationArgs = fieldDefinitions[1]; Vector< HsqlColumnDescriptor > foreignKeyColumns = new Vector< HsqlColumnDescriptor >(); foreignKeyColumns.add( new HsqlColumnDescriptor( "ID", "integer", HsqlColumnDescriptor.PRIMARY ) ); Vector< String[] > foreignKeyValues = new Vector< String[] >(); StringBuffer foreignKeyInsertSQL = new StringBuffer(); foreignKeyInsertSQL.append( "INSERT INTO \"" + m_foreignKeyTableName + "\" VALUES (?" ); final String[] displayValues = impl_getDisplayValues(); for ( int i=0; i