1ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5ef39d40dSAndrew Rist * distributed with this work for additional information 6ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10ef39d40dSAndrew Rist * 11ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12ef39d40dSAndrew Rist * 13ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17ef39d40dSAndrew Rist * specific language governing permissions and limitations 18ef39d40dSAndrew Rist * under the License. 19ef39d40dSAndrew Rist * 20ef39d40dSAndrew Rist *************************************************************/ 21ef39d40dSAndrew Rist 22ef39d40dSAndrew Rist 23cdf0e10cSrcweir package mod._forms; 24cdf0e10cSrcweir import com.sun.star.beans.NamedValue; 25cdf0e10cSrcweir import com.sun.star.beans.PropertyValue; 26cdf0e10cSrcweir import com.sun.star.container.XIndexAccess; 27cdf0e10cSrcweir import java.io.PrintWriter; 28cdf0e10cSrcweir 29cdf0e10cSrcweir import lib.StatusException; 30cdf0e10cSrcweir import lib.TestCase; 31cdf0e10cSrcweir import lib.TestEnvironment; 32cdf0e10cSrcweir import lib.TestParameters; 33cdf0e10cSrcweir import util.DBTools; 34cdf0e10cSrcweir import util.FormTools; 35cdf0e10cSrcweir import util.WriterTools; 36cdf0e10cSrcweir 37cdf0e10cSrcweir import com.sun.star.beans.XPropertySet; 38cdf0e10cSrcweir import com.sun.star.drawing.XControlShape; 39cdf0e10cSrcweir import com.sun.star.drawing.XShape; 40cdf0e10cSrcweir import com.sun.star.form.XBoundComponent; 41cdf0e10cSrcweir import com.sun.star.form.XForm; 42cdf0e10cSrcweir import com.sun.star.form.XLoadable; 43cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 44cdf0e10cSrcweir import com.sun.star.lang.XComponent; 45cdf0e10cSrcweir import com.sun.star.sdbc.XConnection; 46cdf0e10cSrcweir import com.sun.star.sdbc.XResultSetUpdate; 47cdf0e10cSrcweir import com.sun.star.sdb.XDocumentDataSource; 48cdf0e10cSrcweir import com.sun.star.text.XTextDocument; 49cdf0e10cSrcweir import com.sun.star.uno.AnyConverter; 50cdf0e10cSrcweir import com.sun.star.uno.Type; 51cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 52cdf0e10cSrcweir import com.sun.star.uno.XInterface; 53cdf0e10cSrcweir import com.sun.star.util.XCloseable; 54cdf0e10cSrcweir import java.util.ArrayList; 55cdf0e10cSrcweir import lib.Status; 56cdf0e10cSrcweir import util.utils; 57cdf0e10cSrcweir 58cdf0e10cSrcweir 59cdf0e10cSrcweir /** 60cdf0e10cSrcweir * Test for object which is represented by service 61cdf0e10cSrcweir * <code>com.sun.star.form.component.DateField</code>. <p> 62cdf0e10cSrcweir * Object implements the following interfaces : 63cdf0e10cSrcweir * <ul> 64cdf0e10cSrcweir * <li> <code>com::sun::star::io::XPersistObject</code></li> 65cdf0e10cSrcweir * <li> <code>com::sun::star::awt::UnoControlDateFieldModel</code></li> 66cdf0e10cSrcweir * <li> <code>com::sun::star::form::XReset</code></li> 67cdf0e10cSrcweir * <li> <code>com::sun::star::form::XBoundComponent</code></li> 68cdf0e10cSrcweir * <li> <code>com::sun::star::form::FormComponent</code></li> 69cdf0e10cSrcweir * <li> <code>com::sun::star::form::component::DateField</code></li> 70cdf0e10cSrcweir * <li> <code>com::sun::star::beans::XFastPropertySet</code></li> 71cdf0e10cSrcweir * <li> <code>com::sun::star::beans::XMultiPropertySet</code></li> 72cdf0e10cSrcweir * <li> <code>com::sun::star::form::XUpdateBroadcaster</code></li> 73cdf0e10cSrcweir * <li> <code>com::sun::star::form::DataAwareControlModel</code></li> 74cdf0e10cSrcweir * <li> <code>com::sun::star::beans::XPropertyState</code></li> 75cdf0e10cSrcweir * <li> <code>com::sun::star::form::FormControlModel</code></li> 76cdf0e10cSrcweir * <li> <code>com::sun::star::container::XNamed</code></li> 77cdf0e10cSrcweir * <li> <code>com::sun::star::lang::XComponent</code></li> 78cdf0e10cSrcweir * <li> <code>com::sun::star::lang::XEventListener</code></li> 79cdf0e10cSrcweir * <li> <code>com::sun::star::beans::XPropertyAccess</code></li> 80cdf0e10cSrcweir * <li> <code>com::sun::star::beans::XPropertyContainer</code></li> 81cdf0e10cSrcweir * <li> <code>com::sun::star::beans::XPropertySet</code></li> 82cdf0e10cSrcweir * <li> <code>com::sun::star::form::XLoadListener</code></li> 83cdf0e10cSrcweir * <li> <code>com::sun::star::container::XChild</code></li> 84cdf0e10cSrcweir * </ul> 85cdf0e10cSrcweir * The following files used by this test : 86cdf0e10cSrcweir * <ul> 87cdf0e10cSrcweir * <li><b> TestDB </b> (directory) : directory with test database </li> 88cdf0e10cSrcweir * <li><b> TestDB/TestDB.dbf </b> : table file. See 89cdf0e10cSrcweir * {@link util.DBTools DBTools} class for more information.</li> 90cdf0e10cSrcweir * </ul> <p> 91cdf0e10cSrcweir * This object test <b> is NOT </b> designed to be run in several 92cdf0e10cSrcweir * threads concurently. 93cdf0e10cSrcweir * @see com.sun.star.io.XPersistObject 94cdf0e10cSrcweir * @see com.sun.star.awt.UnoControlDateFieldModel 95cdf0e10cSrcweir * @see com.sun.star.form.XReset 96cdf0e10cSrcweir * @see com.sun.star.form.XBoundComponent 97cdf0e10cSrcweir * @see com.sun.star.form.FormComponent 98cdf0e10cSrcweir * @see com.sun.star.form.component.DateField 99cdf0e10cSrcweir * @see com.sun.star.beans.XFastPropertySet 100cdf0e10cSrcweir * @see com.sun.star.beans.XMultiPropertySet 101cdf0e10cSrcweir * @see com.sun.star.form.XUpdateBroadcaster 102cdf0e10cSrcweir * @see com.sun.star.form.DataAwareControlModel 103cdf0e10cSrcweir * @see com.sun.star.beans.XPropertyState 104*5496b966SPedro Giffuni * @see com.sun.star.form 105cdf0e10cSrcweir * @see com.sun.star.container.XNamed 106cdf0e10cSrcweir * @see com.sun.star.lang.XComponent 107cdf0e10cSrcweir * @see com.sun.star.lang.XEventListener 108cdf0e10cSrcweir * @see com.sun.star.beans.XPropertyAccess 109cdf0e10cSrcweir * @see com.sun.star.beans.XPropertyContainer 110cdf0e10cSrcweir * @see com.sun.star.beans.XPropertySet 111cdf0e10cSrcweir * @see com.sun.star.form.XLoadListener 112cdf0e10cSrcweir * @see com.sun.star.container.XChild 113cdf0e10cSrcweir * @see ifc.io._XPersistObject 114cdf0e10cSrcweir * @see ifc.awt._UnoControlDateFieldModel 115cdf0e10cSrcweir * @see ifc.form._XReset 116cdf0e10cSrcweir * @see ifc.form._XBoundComponent 117cdf0e10cSrcweir * @see ifc.form._FormComponent 118cdf0e10cSrcweir * @see ifc.form.component._DateField 119cdf0e10cSrcweir * @see ifc.beans._XFastPropertySet 120cdf0e10cSrcweir * @see ifc.beans._XMultiPropertySet 121cdf0e10cSrcweir * @see ifc.form._XUpdateBroadcaster 122cdf0e10cSrcweir * @see ifc.form._DataAwareControlModel 123cdf0e10cSrcweir * @see ifc.beans._XPropertyState 124cdf0e10cSrcweir * @see ifc.form._FormControlModel 125cdf0e10cSrcweir * @see ifc.container._XNamed 126cdf0e10cSrcweir * @see ifc.lang._XComponent 127cdf0e10cSrcweir * @see ifc.lang._XEventListener 128cdf0e10cSrcweir * @see ifc.beans._XPropertySet 129cdf0e10cSrcweir * @see ifc.form._XLoadListener 130cdf0e10cSrcweir * @see ifc.container._XChild 131cdf0e10cSrcweir */ 132cdf0e10cSrcweir public class GenericModelTest extends TestCase { 133cdf0e10cSrcweir private static XTextDocument m_xTextDoc; 134cdf0e10cSrcweir private static Object m_dbSrc = null; 135cdf0e10cSrcweir private static DBTools.DataSourceInfo m_srcInf = null; 136cdf0e10cSrcweir /** 137cdf0e10cSrcweir * This is the name of the Data Base which the test uses: "APITestDatabase" 138cdf0e10cSrcweir */ 139cdf0e10cSrcweir protected final static String m_dbSourceName = "APITestDatabase"; 140cdf0e10cSrcweir protected final static String m_TestDB = "TestDB"; 141cdf0e10cSrcweir private DBTools m_dbTools = null; 142cdf0e10cSrcweir 143cdf0e10cSrcweir private static boolean m_ConnectionColsed = false; 144cdf0e10cSrcweir 145cdf0e10cSrcweir /** 146cdf0e10cSrcweir * descibes the kind of the shape which should be created. 147cdf0e10cSrcweir * Example: m_kindOfshape=DateFiled 148cdf0e10cSrcweir */ 149cdf0e10cSrcweir public static String m_kindOfControl = null; 150cdf0e10cSrcweir 151cdf0e10cSrcweir /** 152cdf0e10cSrcweir * If your object needs some special propery values you can specify them with this 153cdf0e10cSrcweir * <CODE>ArrayList</CODE>. You have to add a <CODE>NamedValue</CODE> to this list. 154cdf0e10cSrcweir * Example: 155cdf0e10cSrcweir * NamedValue myProp = new NamedValue(); 156cdf0e10cSrcweir * myProp.Name = "Test"; 157cdf0e10cSrcweir * myProp.Value = "My special Value"; 158cdf0e10cSrcweir * m_propertiesToSet.add(myProp); 159cdf0e10cSrcweir */ 160cdf0e10cSrcweir public static ArrayList m_propertiesToSet = new ArrayList(); 161cdf0e10cSrcweir 162cdf0e10cSrcweir /** 163cdf0e10cSrcweir * This variable contains the name of the property which should be changed while 164cdf0e10cSrcweir * interface <CODE>com::sun::star::form::XUpdateBroadcaster</CODE> is tested. The 165cdf0e10cSrcweir * interface test needs the <CODE>ObjectRelation</CODE> 166cdf0e10cSrcweir * "XUpdateBroadcaster.Checker" which is a <CODE>ifc.form._XUpdateBroadcaster.UpdateChecker</CODE>. 167cdf0e10cSrcweir * @see ifc.form._XUpdateBroadcaster.UpdateChecker 168cdf0e10cSrcweir * @see ifc.form._XUpdateBroadcaster 169cdf0e10cSrcweir */ 170cdf0e10cSrcweir public static String m_ChangePropertyName = null; 171cdf0e10cSrcweir /** 172cdf0e10cSrcweir * This variable contains the value the property should be set while 173cdf0e10cSrcweir * interface <CODE>com::sun::star::form::XUpdateBroadcaster</CODE> is tested. 174cdf0e10cSrcweir * The interface test needs the <CODE>ObjectRelation</CODE> 175cdf0e10cSrcweir * "XUpdateBroadcaster.Checker" which is a <CODE>ifc.form._XUpdateBroadcaster.UpdateChecker</CODE>. 176cdf0e10cSrcweir * Normaly the <CODE>Checker</CODE> uses <CODE>util.ValueChanger</CODE> to change 177cdf0e10cSrcweir * the value of the property. If the current of this property is NULL the 178cdf0e10cSrcweir * <CODE>ValueChanger</CODE> is unable to change the value. In this case the value 179cdf0e10cSrcweir * of this variable was used. 180cdf0e10cSrcweir */ 181cdf0e10cSrcweir public static Object m_ChangePropertyValue = null; 182cdf0e10cSrcweir 183cdf0e10cSrcweir /** 184cdf0e10cSrcweir * This variable contains the implelemtation name of the object. 185cdf0e10cSrcweir */ 186cdf0e10cSrcweir public static String m_ObjectName = null; 187cdf0e10cSrcweir 188cdf0e10cSrcweir /** 189cdf0e10cSrcweir * For local implementaions of <CODE>Checker</CODE> this variable contains the 190cdf0e10cSrcweir * <CODE>FormLoader</CODE> 191cdf0e10cSrcweir */ 192cdf0e10cSrcweir protected static XLoadable m_XFormLoader = null; 193cdf0e10cSrcweir /** 194cdf0e10cSrcweir * For local implementaions of <CODE>Checker</CODE> this variable contains the 195cdf0e10cSrcweir * <CODE>XPropertySet</CODE> 196cdf0e10cSrcweir */ 197cdf0e10cSrcweir protected static XPropertySet m_XPS = null; 198cdf0e10cSrcweir /** 199cdf0e10cSrcweir * For local implementaions of <CODE>Checker</CODE> this variable contains the 200cdf0e10cSrcweir * <CODE>Control</CODE> 201cdf0e10cSrcweir */ 202cdf0e10cSrcweir protected static XInterface m_XCtrl = null; 203cdf0e10cSrcweir /** 204cdf0e10cSrcweir * The insterface test of <CODE>ifc.form._DataWareControlModel</CODE> expects an 205cdf0e10cSrcweir * object relation <CODE>'LC'</CODE>. This is a <CODE>XControlModel</CODE> of a shape. 206cdf0e10cSrcweir * This variable contains the kind of shape to create for the interface test, 207cdf0e10cSrcweir * f.e. "FixedText" 208cdf0e10cSrcweir * @see ifc.form._DataAwareControlModel 209cdf0e10cSrcweir */ 210cdf0e10cSrcweir protected static String m_LCShape_Type = null; 211cdf0e10cSrcweir 212cdf0e10cSrcweir protected static String m_XPropertyAccess_propertyToChange = "HelpText"; 213cdf0e10cSrcweir 214cdf0e10cSrcweir protected static String m_XPropertyContainer_propertyNotRemovable = "HelpText"; 215cdf0e10cSrcweir /** 216cdf0e10cSrcweir * If this variable is true some more debug info was logged. It was setted by the parameter variable 217cdf0e10cSrcweir * <code>debug_is_active</code> 218cdf0e10cSrcweir */ 219cdf0e10cSrcweir protected static boolean debug = false; 220cdf0e10cSrcweir 221cdf0e10cSrcweir /** 222cdf0e10cSrcweir * Creates Writer document where controls are placed. 223cdf0e10cSrcweir * @param tParam the test paremter 224cdf0e10cSrcweir * @param log the log writer 225cdf0e10cSrcweir */ initialize(TestParameters tParam, PrintWriter log)226cdf0e10cSrcweir protected void initialize(TestParameters tParam, PrintWriter log) { 227cdf0e10cSrcweir log.println("creating a textdocument"); 228cdf0e10cSrcweir m_xTextDoc = WriterTools.createTextDoc(((XMultiServiceFactory) tParam.getMSF())); 229cdf0e10cSrcweir m_ConnectionColsed = false; 230cdf0e10cSrcweir debug = tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE); 231cdf0e10cSrcweir m_propertiesToSet.clear(); 232cdf0e10cSrcweir } 233cdf0e10cSrcweir 234cdf0e10cSrcweir /** 235cdf0e10cSrcweir * close the connection 236cdf0e10cSrcweir * close the data source 237cdf0e10cSrcweir * close the document 238cdf0e10cSrcweir * revoke the data source 239cdf0e10cSrcweir * @param tParam the test parameter 240cdf0e10cSrcweir * @param log the log writer 241cdf0e10cSrcweir */ cleanup(TestParameters tParam, PrintWriter log)242cdf0e10cSrcweir protected void cleanup(TestParameters tParam, PrintWriter log) { 243cdf0e10cSrcweir log.println("closing connection..."); 244cdf0e10cSrcweir 245cdf0e10cSrcweir // some interface tests call cleanup to reset the environment. If such 246cdf0e10cSrcweir // a test is the last one cleanup was called twice. The second call 247cdf0e10cSrcweir // causes then nasty exceptions... 248cdf0e10cSrcweir if (m_ConnectionColsed) return; 249cdf0e10cSrcweir 250cdf0e10cSrcweir try { 251cdf0e10cSrcweir XIndexAccess forms = UnoRuntime.queryInterface( XIndexAccess.class, 252cdf0e10cSrcweir FormTools.getForms( WriterTools.getDrawPage( m_xTextDoc ) ) ); 253cdf0e10cSrcweir XForm myForm = (XForm) AnyConverter.toObject(new Type(XForm.class), 254cdf0e10cSrcweir forms.getByIndex(0)); 255cdf0e10cSrcweir 256cdf0e10cSrcweir if (debug){ 257cdf0e10cSrcweir if (myForm == null){ 258cdf0e10cSrcweir log.println("ERROR: could not get 'Standard' from drawpage!"); 259cdf0e10cSrcweir } 260cdf0e10cSrcweir log.println("the draw page contains folowing elemtens:"); 261cdf0e10cSrcweir String[] elements = FormTools.getForms(WriterTools.getDrawPage(m_xTextDoc)).getElementNames(); 262cdf0e10cSrcweir for (int i = 0; i< elements.length; i++){ 263cdf0e10cSrcweir log.println("Element[" + i + "] :" + elements[i]); 264cdf0e10cSrcweir } 265cdf0e10cSrcweir 266cdf0e10cSrcweir } 267cdf0e10cSrcweir 268cdf0e10cSrcweir XPropertySet xSetProp = UnoRuntime.queryInterface( XPropertySet.class, myForm ); 269cdf0e10cSrcweir XConnection connection = UnoRuntime.queryInterface( XConnection.class, xSetProp.getPropertyValue( "ActiveConnection" ) ); 270cdf0e10cSrcweir if ( connection == null ) 271cdf0e10cSrcweir { 272cdf0e10cSrcweir if ( debug ) 273cdf0e10cSrcweir log.println("ERROR: could not get property 'ActiveConnection' from the XForm"); 274cdf0e10cSrcweir } 275cdf0e10cSrcweir else 276cdf0e10cSrcweir { 277cdf0e10cSrcweir connection.close(); 278cdf0e10cSrcweir } 279cdf0e10cSrcweir } catch (Exception e) { 280cdf0e10cSrcweir log.println("ERROR: Can't close the connection: " + e.toString()); 281cdf0e10cSrcweir e.printStackTrace( log ); 282cdf0e10cSrcweir } 283cdf0e10cSrcweir 284cdf0e10cSrcweir log.println("closing data source..."); 285cdf0e10cSrcweir try { 286cdf0e10cSrcweir XCloseable closer = (XCloseable) UnoRuntime.queryInterface( 287cdf0e10cSrcweir XCloseable.class, m_dbSrc); 288cdf0e10cSrcweir if ( closer == null ) 289cdf0e10cSrcweir { 290cdf0e10cSrcweir XDocumentDataSource dataSource = (XDocumentDataSource)UnoRuntime.queryInterface( 291cdf0e10cSrcweir XDocumentDataSource.class, m_dbSrc); 292cdf0e10cSrcweir if ( dataSource != null ) 293cdf0e10cSrcweir closer = (XCloseable) UnoRuntime.queryInterface( 294cdf0e10cSrcweir XCloseable.class, dataSource.getDatabaseDocument() ); 295cdf0e10cSrcweir } 296cdf0e10cSrcweir if (debug && closer==null){ 297cdf0e10cSrcweir log.println("ERROR: couldn't get 'XCloseable' from DataSource"); 298cdf0e10cSrcweir } 299cdf0e10cSrcweir closer.close(true); 300cdf0e10cSrcweir } catch (com.sun.star.util.CloseVetoException e) { 301cdf0e10cSrcweir log.println("ERROR: couldn't close data source: " + e.toString()); 302cdf0e10cSrcweir } catch (com.sun.star.lang.DisposedException e) { 303cdf0e10cSrcweir log.println("ERROR: couldn't close data source: " + e.toString()); 304cdf0e10cSrcweir } catch (Exception e) { 305cdf0e10cSrcweir log.println("ERROR: couldn't close data source: " + e.toString()); 306cdf0e10cSrcweir } 307cdf0e10cSrcweir 308cdf0e10cSrcweir log.println("disposing data source..."); 309cdf0e10cSrcweir try { 310cdf0e10cSrcweir XComponent dataSourceComp = (XComponent)UnoRuntime.queryInterface( 311cdf0e10cSrcweir XComponent.class, m_dbSrc); 312cdf0e10cSrcweir dataSourceComp.dispose(); 313cdf0e10cSrcweir } 314cdf0e10cSrcweir catch (Exception e) { 315cdf0e10cSrcweir log.println("couldn't dispose the data source"); 316cdf0e10cSrcweir } 317cdf0e10cSrcweir 318cdf0e10cSrcweir log.println("closing document..."); 319cdf0e10cSrcweir 320cdf0e10cSrcweir try { 321cdf0e10cSrcweir XCloseable closer = (XCloseable) UnoRuntime.queryInterface( 322cdf0e10cSrcweir XCloseable.class, m_xTextDoc); 323cdf0e10cSrcweir closer.close(true); 324cdf0e10cSrcweir } catch (com.sun.star.util.CloseVetoException e) { 325cdf0e10cSrcweir log.println("ERROR: couldn't close document: " + e.toString()); 326cdf0e10cSrcweir } catch (com.sun.star.lang.DisposedException e) { 327cdf0e10cSrcweir log.println("ERROR: couldn't close document: " + e.toString()); 328cdf0e10cSrcweir } catch (Exception e) { 329cdf0e10cSrcweir log.println("ERROR: couldn't close document: " + e.toString()); 330cdf0e10cSrcweir } 331cdf0e10cSrcweir 332cdf0e10cSrcweir log.println("revoking data source..."); 333cdf0e10cSrcweir try { 334cdf0e10cSrcweir m_dbTools.revokeDB(m_dbSourceName); 335cdf0e10cSrcweir } catch (com.sun.star.container.NoSuchElementException e){ 336cdf0e10cSrcweir } catch (com.sun.star.uno.Exception e) { 337cdf0e10cSrcweir log.println("ERROR: Error while object test cleaning up: " + e.toString()); 338cdf0e10cSrcweir } 339cdf0e10cSrcweir 340cdf0e10cSrcweir m_ConnectionColsed = true; 341cdf0e10cSrcweir } 342cdf0e10cSrcweir 343cdf0e10cSrcweir /** 344cdf0e10cSrcweir * Creating a Testenvironment for the interfaces to be tested. 345cdf0e10cSrcweir * First <code>TestDB</code> database is registered. 346cdf0e10cSrcweir * Creates DateField in the Form, then binds it to TestDB 347cdf0e10cSrcweir * database and returns Field's control. <p> 348cdf0e10cSrcweir * Object relations created : 349cdf0e10cSrcweir * <ul> 350cdf0e10cSrcweir * <li> <code>'OBJNAME'</code> for 351cdf0e10cSrcweir * {@link ifc.io._XPersistObject} : name of service which is 352cdf0e10cSrcweir * represented by this object. </li> 353cdf0e10cSrcweir * <li> <code>'LC'</code> for {@link ifc.form._DataAwareControlModel}. 354cdf0e10cSrcweir * Specifies the value for LabelControl property. It is 355cdf0e10cSrcweir * <code>FixedText</code> component added to the document.</li> 356cdf0e10cSrcweir * <li> <code>'FL'</code> for 357cdf0e10cSrcweir * {@link ifc.form._DataAwareControlModel} interface. 358cdf0e10cSrcweir * Specifies XLoadable implementation which connects form to 359cdf0e10cSrcweir * the data source.</li> 360cdf0e10cSrcweir * <li> <code>'XUpdateBroadcaster.Checker'</code> : <code> 361cdf0e10cSrcweir * _XUpdateBroadcaster.UpdateChecker</code> interface implementation 362cdf0e10cSrcweir * which can update, commit data and check if the data was successfully 363cdf0e10cSrcweir * commited.</li> 364cdf0e10cSrcweir * <li> <code>'DataAwareControlModel.NewFieldName'</code> : for 365cdf0e10cSrcweir * <code>com.sun.star.form.DataAwareControlModel</code> service 366cdf0e10cSrcweir * which contains new name of the field ('_DATE') to bind control to. 367cdf0e10cSrcweir * </li> 368cdf0e10cSrcweir * <li> <code>'XFastPropertySet.ExcludeProps'</code> : for 369cdf0e10cSrcweir * <code>com.sun.star.beans.XFastPropertySet</code> interface 370cdf0e10cSrcweir * the property FormatKey can have only restricted set of values. 371cdf0e10cSrcweir * </li> 372cdf0e10cSrcweir * </ul> 373cdf0e10cSrcweir * @see ifc.form._XUpdateBroadcaster 374cdf0e10cSrcweir * @param Param the test parameter 375cdf0e10cSrcweir * @param log the log writer 376cdf0e10cSrcweir * @return a test environment 377cdf0e10cSrcweir */ createTestEnvironment(TestParameters Param, PrintWriter log)378cdf0e10cSrcweir protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, 379cdf0e10cSrcweir PrintWriter log) { 380cdf0e10cSrcweir XInterface oObj = null; 381cdf0e10cSrcweir XControlShape aShape = null; 382cdf0e10cSrcweir XMultiServiceFactory xMSF = (XMultiServiceFactory) Param.getMSF(); 383cdf0e10cSrcweir 384cdf0e10cSrcweir try{ 385cdf0e10cSrcweir log.println("adding contol shape '" + m_kindOfControl + "'"); 386cdf0e10cSrcweir aShape = FormTools.createControlShape(m_xTextDoc, 3000, 387cdf0e10cSrcweir 4500, 15000, 10000, 388cdf0e10cSrcweir m_kindOfControl); 389cdf0e10cSrcweir } catch (Exception e){ 390cdf0e10cSrcweir e.printStackTrace(log); 391cdf0e10cSrcweir throw new StatusException("Couldn't create following control shape (m_kindOfControl): '" + 392cdf0e10cSrcweir m_kindOfControl + "': ", e); 393cdf0e10cSrcweir 394cdf0e10cSrcweir } 395cdf0e10cSrcweir 396cdf0e10cSrcweir WriterTools.getDrawPage(m_xTextDoc).add((XShape) aShape); 397cdf0e10cSrcweir oObj = aShape.getControl(); 398cdf0e10cSrcweir 399cdf0e10cSrcweir log.println("Implementation name: " + util.utils.getImplName(oObj)); 400cdf0e10cSrcweir 401cdf0e10cSrcweir try { 402cdf0e10cSrcweir String sourceTestDB = utils.getFullURL(utils.getFullTestDocName("TestDB/testDB.dbf")); 403cdf0e10cSrcweir String destTestDB = utils.getOfficeTemp(xMSF); 404cdf0e10cSrcweir destTestDB = utils.getFullURL(destTestDB + "testDB.dbf"); 405cdf0e10cSrcweir 406cdf0e10cSrcweir log.println("copy '"+sourceTestDB + "' -> '" + destTestDB + "'"); 407cdf0e10cSrcweir utils.copyFile(xMSF, sourceTestDB, destTestDB); 408cdf0e10cSrcweir 409cdf0e10cSrcweir m_dbTools = new DBTools( xMSF, log ); 410cdf0e10cSrcweir String tmpDir = utils.getOfficeTemp((xMSF)); 411cdf0e10cSrcweir 412cdf0e10cSrcweir m_srcInf = m_dbTools.newDataSourceInfo(); 413cdf0e10cSrcweir m_srcInf.URL = "sdbc:dbase:" + DBTools.dirToUrl(tmpDir); 414cdf0e10cSrcweir log.println("data source: " + m_srcInf.URL); 415cdf0e10cSrcweir 416cdf0e10cSrcweir m_dbSrc = m_srcInf.getDataSourceService(); 417cdf0e10cSrcweir m_dbTools.reRegisterDB(m_dbSourceName, m_dbSrc); 418cdf0e10cSrcweir 419cdf0e10cSrcweir m_XFormLoader = FormTools.bindForm(m_xTextDoc, m_dbSourceName, 420cdf0e10cSrcweir m_TestDB); 421cdf0e10cSrcweir } catch (com.sun.star.uno.Exception e) { 422cdf0e10cSrcweir log.println("!!! Can't access TestDB !!!"); 423cdf0e10cSrcweir e.printStackTrace(log); 424cdf0e10cSrcweir throw new StatusException("Can't access TestDB", e); 425cdf0e10cSrcweir } 426cdf0e10cSrcweir 427cdf0e10cSrcweir log.println("creating a new environment for object"); 428cdf0e10cSrcweir 429cdf0e10cSrcweir TestEnvironment tEnv = new TestEnvironment(oObj); 430cdf0e10cSrcweir 431cdf0e10cSrcweir tEnv.addObjRelation("OBJNAME", m_ObjectName); 432cdf0e10cSrcweir 433cdf0e10cSrcweir log.println("adding shape '" + m_LCShape_Type +"' for DataAwareControlModel test"); 434cdf0e10cSrcweir aShape = FormTools.createControlShape(m_xTextDoc, 6000, 4500, 15000, 435cdf0e10cSrcweir 10000, m_LCShape_Type); 436cdf0e10cSrcweir WriterTools.getDrawPage(m_xTextDoc).add((XShape) aShape); 437cdf0e10cSrcweir 438cdf0e10cSrcweir m_XPS = (XPropertySet) UnoRuntime.queryInterface( 439cdf0e10cSrcweir XPropertySet.class, oObj); 440cdf0e10cSrcweir 441cdf0e10cSrcweir int i = 0; 442cdf0e10cSrcweir NamedValue prop = null; 443cdf0e10cSrcweir try { 444cdf0e10cSrcweir for (i = 0; i < m_propertiesToSet.size(); i++){ 445cdf0e10cSrcweir prop = (NamedValue) m_propertiesToSet.get(i); 446cdf0e10cSrcweir 447cdf0e10cSrcweir log.println("setting property: '"+prop.Name+"' to value '"+prop.Value.toString()+"'"); 448cdf0e10cSrcweir 449cdf0e10cSrcweir m_XPS.setPropertyValue(prop.Name, prop.Value); 450cdf0e10cSrcweir } 451cdf0e10cSrcweir } catch (com.sun.star.lang.WrappedTargetException e) { 452cdf0e10cSrcweir e.printStackTrace(log); 453cdf0e10cSrcweir throw new StatusException("Couldn't set property '" + prop.Name + "': ", e); 454cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException e) { 455cdf0e10cSrcweir e.printStackTrace(log); 456cdf0e10cSrcweir throw new StatusException("Couldn't set property '" + prop.Name + "': ", e); 457cdf0e10cSrcweir } catch (com.sun.star.beans.PropertyVetoException e) { 458cdf0e10cSrcweir e.printStackTrace(log); 459cdf0e10cSrcweir throw new StatusException("Couldn't set property '" + prop.Name + "': ", e); 460cdf0e10cSrcweir } catch (com.sun.star.beans.UnknownPropertyException e) { 461cdf0e10cSrcweir e.printStackTrace(log); 462cdf0e10cSrcweir throw new StatusException("Couldn't set property '" + prop.Name + "': ", e); 463cdf0e10cSrcweir } catch (java.lang.ClassCastException e) { 464cdf0e10cSrcweir e.printStackTrace(log); 465cdf0e10cSrcweir throw new StatusException("Couldn't get property on index '" + i + "': ", e); 466cdf0e10cSrcweir } 467cdf0e10cSrcweir 468cdf0e10cSrcweir // added LabelControl for 'DataAwareControlModel' 469cdf0e10cSrcweir tEnv.addObjRelation("LC", aShape.getControl()); 470cdf0e10cSrcweir 471cdf0e10cSrcweir // added FormLoader for 'DataAwareControlModel' 472cdf0e10cSrcweir tEnv.addObjRelation("FL", m_XFormLoader); 473cdf0e10cSrcweir 474cdf0e10cSrcweir // adding relation for XUpdateBroadcaster 475cdf0e10cSrcweir m_XCtrl = oObj; 476cdf0e10cSrcweir 477cdf0e10cSrcweir tEnv.addObjRelation("XUpdateBroadcaster.Checker", 478cdf0e10cSrcweir new Checker(m_XFormLoader, m_XPS, m_XCtrl, m_ChangePropertyName, m_ChangePropertyValue)); 479cdf0e10cSrcweir 480cdf0e10cSrcweir // adding relation for DataAwareControlModel service 481cdf0e10cSrcweir tEnv.addObjRelation("DataAwareControlModel.NewFieldName", 482cdf0e10cSrcweir DBTools.TST_DATE_F); 483cdf0e10cSrcweir 484cdf0e10cSrcweir //adding ObjRelation for XPersistObject 485cdf0e10cSrcweir tEnv.addObjRelation("PSEUDOPERSISTENT", new Boolean(true)); 486cdf0e10cSrcweir 487cdf0e10cSrcweir // adding relation for XFastPropertySet 488cdf0e10cSrcweir java.util.HashSet exclude = new java.util.HashSet(); 489cdf0e10cSrcweir exclude.add("FormatKey"); 490cdf0e10cSrcweir tEnv.addObjRelation("XFastPropertySet.ExcludeProps", exclude); 491cdf0e10cSrcweir 492cdf0e10cSrcweir PropertyValue propVal = new PropertyValue(); 493cdf0e10cSrcweir propVal.Name = m_XPropertyAccess_propertyToChange; 494cdf0e10cSrcweir propVal.Value = "Text since XPropertyAccess"; 495cdf0e10cSrcweir tEnv.addObjRelation("XPropertyAccess.propertyToChange", propVal); 496cdf0e10cSrcweir tEnv.addObjRelation("XPropertyContainer.propertyNotRemovable", m_XPropertyContainer_propertyNotRemovable); 497cdf0e10cSrcweir 498cdf0e10cSrcweir 499cdf0e10cSrcweir return tEnv; 500cdf0e10cSrcweir } // finish method getTestEnvironment 501cdf0e10cSrcweir 502cdf0e10cSrcweir 503cdf0e10cSrcweir static class Checker implements ifc.form._XUpdateBroadcaster.UpdateChecker { 504cdf0e10cSrcweir private Object lastValue = null; 505cdf0e10cSrcweir XLoadable formLoaderF = null; 506cdf0e10cSrcweir XPropertySet ps = null; 507cdf0e10cSrcweir XInterface ctrl = null; 508cdf0e10cSrcweir String ChangePropertyName = null; 509cdf0e10cSrcweir Object ChangePropertyValue = null; 510cdf0e10cSrcweir Checker(XLoadable xl, XPropertySet ps, XInterface ctrl, String ChangePropertyName, Object ChangePropertyValue)511cdf0e10cSrcweir public Checker(XLoadable xl, XPropertySet ps, XInterface ctrl, String ChangePropertyName, Object ChangePropertyValue) { 512cdf0e10cSrcweir formLoaderF = xl; 513cdf0e10cSrcweir this.ps = ps; 514cdf0e10cSrcweir this.ctrl = ctrl; 515cdf0e10cSrcweir this.ChangePropertyName=ChangePropertyName; 516cdf0e10cSrcweir this.ChangePropertyValue=ChangePropertyValue; 517cdf0e10cSrcweir } 518cdf0e10cSrcweir update()519cdf0e10cSrcweir public void update() throws com.sun.star.uno.Exception { 520cdf0e10cSrcweir if (!formLoaderF.isLoaded()) { 521cdf0e10cSrcweir formLoaderF.load(); 522cdf0e10cSrcweir } 523cdf0e10cSrcweir 524cdf0e10cSrcweir lastValue = util.ValueChanger.changePValue(ps.getPropertyValue(ChangePropertyName)); 525cdf0e10cSrcweir 526cdf0e10cSrcweir if (lastValue == null){ 527cdf0e10cSrcweir 528cdf0e10cSrcweir if (ChangePropertyValue != null){ 529cdf0e10cSrcweir 530cdf0e10cSrcweir lastValue = ChangePropertyValue; 531cdf0e10cSrcweir 532cdf0e10cSrcweir } else { 533cdf0e10cSrcweir 534cdf0e10cSrcweir String msg = "The initial value of the property '" + ChangePropertyName + "' is NULL\n"; 535cdf0e10cSrcweir msg += "The member variable 'm_ChangePropertyValue' is NULL\n"; 536cdf0e10cSrcweir msg += "Could not change Property."; 537cdf0e10cSrcweir 538cdf0e10cSrcweir throw new StatusException(Status.failed(msg)); 539cdf0e10cSrcweir } 540cdf0e10cSrcweir } 541cdf0e10cSrcweir ps.setPropertyValue(ChangePropertyName, lastValue); 542cdf0e10cSrcweir } 543cdf0e10cSrcweir commit()544cdf0e10cSrcweir public void commit() throws com.sun.star.sdbc.SQLException { 545cdf0e10cSrcweir XBoundComponent bound = (XBoundComponent) UnoRuntime.queryInterface( 546cdf0e10cSrcweir XBoundComponent.class, ctrl); 547cdf0e10cSrcweir XResultSetUpdate update = (XResultSetUpdate) UnoRuntime.queryInterface( 548cdf0e10cSrcweir XResultSetUpdate.class, 549cdf0e10cSrcweir formLoaderF); 550cdf0e10cSrcweir 551cdf0e10cSrcweir bound.commit(); 552cdf0e10cSrcweir update.updateRow(); 553cdf0e10cSrcweir } 554cdf0e10cSrcweir wasCommited()555cdf0e10cSrcweir public boolean wasCommited() throws com.sun.star.uno.Exception { 556cdf0e10cSrcweir formLoaderF.reload(); 557cdf0e10cSrcweir 558cdf0e10cSrcweir Object newValue = ps.getPropertyValue(ChangePropertyName); 559cdf0e10cSrcweir 560cdf0e10cSrcweir return (newValue != null) && (util.ValueComparer.equalValue(lastValue, newValue)); 561cdf0e10cSrcweir } 562cdf0e10cSrcweir } 563cdf0e10cSrcweir } // finish class GenericModelTest 564