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 25cdf0e10cSrcweir import com.sun.star.beans.NamedValue; 26cdf0e10cSrcweir import com.sun.star.beans.XPropertySet; 27cdf0e10cSrcweir import com.sun.star.form.XBoundComponent; 28cdf0e10cSrcweir import com.sun.star.form.XLoadable; 29cdf0e10cSrcweir import com.sun.star.sdbc.XResultSetUpdate; 30cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 31cdf0e10cSrcweir import com.sun.star.uno.XInterface; 32cdf0e10cSrcweir import java.io.PrintWriter; 33cdf0e10cSrcweir import java.util.HashSet; 34cdf0e10cSrcweir import ifc.form._XUpdateBroadcaster.UpdateChecker; 35cdf0e10cSrcweir 36cdf0e10cSrcweir import lib.TestEnvironment; 37cdf0e10cSrcweir import lib.TestParameters; 38cdf0e10cSrcweir import util.DBTools; 39cdf0e10cSrcweir 40cdf0e10cSrcweir 41cdf0e10cSrcweir 42cdf0e10cSrcweir /** 43cdf0e10cSrcweir * Test for object which is represented by service 44cdf0e10cSrcweir * <code>com.sun.star.form.component.TimeField</code>. <p> 45cdf0e10cSrcweir * Object implements the following interfaces : 46cdf0e10cSrcweir * <ul> 47cdf0e10cSrcweir * <li> <code>com::sun::star::awt::UnoControlTimeFieldModel</code></li> 48cdf0e10cSrcweir * <li> <code>com::sun::star::io::XPersistObject</code></li> 49cdf0e10cSrcweir * <li> <code>com::sun::star::form::component::TimeField</code></li> 50cdf0e10cSrcweir * <li> <code>com::sun::star::form::XReset</code></li> 51cdf0e10cSrcweir * <li> <code>com::sun::star::form::XBoundComponent</code></li> 52cdf0e10cSrcweir * <li> <code>com::sun::star::form::FormComponent</code></li> 53cdf0e10cSrcweir * <li> <code>com::sun::star::beans::XFastPropertySet</code></li> 54cdf0e10cSrcweir * <li> <code>com::sun::star::beans::XMultiPropertySet</code></li> 55cdf0e10cSrcweir * <li> <code>com::sun::star::form::XUpdateBroadcaster</code></li> 56cdf0e10cSrcweir * <li> <code>com::sun::star::form::DataAwareControlModel</code></li> 57cdf0e10cSrcweir * <li> <code>com::sun::star::beans::XPropertyState</code></li> 58cdf0e10cSrcweir * <li> <code>com::sun::star::form::FormControlModel</code></li> 59cdf0e10cSrcweir * <li> <code>com::sun::star::container::XNamed</code></li> 60cdf0e10cSrcweir * <li> <code>com::sun::star::lang::XComponent</code></li> 61cdf0e10cSrcweir * <li> <code>com::sun::star::lang::XEventListener</code></li> 62cdf0e10cSrcweir * <li> <code>com::sun::star::beans::XPropertyAccess</code></li> 63cdf0e10cSrcweir * <li> <code>com::sun::star::beans::XPropertyContainer</code></li> 64cdf0e10cSrcweir * <li> <code>com::sun::star::beans::XPropertySet</code></li> 65cdf0e10cSrcweir * <li> <code>com::sun::star::form::XLoadListener</code></li> 66cdf0e10cSrcweir * <li> <code>com::sun::star::container::XChild</code></li> 67cdf0e10cSrcweir * </ul> 68cdf0e10cSrcweir * The following files used by this test : 69cdf0e10cSrcweir * <ul> 70cdf0e10cSrcweir * <li><b> TestDB </b> (directory) : directory with test database </li> 71cdf0e10cSrcweir * <li><b> TestDB/TestDB.dbf </b> : table file. See 72cdf0e10cSrcweir * {@link util.DBTools DBTools} class for more information.</li> 73cdf0e10cSrcweir * </ul> <p> 74cdf0e10cSrcweir * This object test <b> is NOT </b> designed to be run in several 75cdf0e10cSrcweir * threads concurently. 76cdf0e10cSrcweir * @see com.sun.star.awt.UnoControlTimeFieldModel 77cdf0e10cSrcweir * @see com.sun.star.io.XPersistObject 78cdf0e10cSrcweir * @see com.sun.star.form.component.TimeField 79cdf0e10cSrcweir * @see com.sun.star.form.XReset 80cdf0e10cSrcweir * @see com.sun.star.form.XBoundComponent 81cdf0e10cSrcweir * @see com.sun.star.form.FormComponent 82cdf0e10cSrcweir * @see com.sun.star.beans.XFastPropertySet 83cdf0e10cSrcweir * @see com.sun.star.beans.XMultiPropertySet 84cdf0e10cSrcweir * @see com.sun.star.form.XUpdateBroadcaster 85cdf0e10cSrcweir * @see com.sun.star.form.DataAwareControlModel 86cdf0e10cSrcweir * @see com.sun.star.beans.XPropertyState 87*5496b966SPedro Giffuni * @see com.sun.star.form 88cdf0e10cSrcweir * @see com.sun.star.container.XNamed 89cdf0e10cSrcweir * @see com.sun.star.lang.XComponent 90cdf0e10cSrcweir * @see com.sun.star.lang.XEventListener 91cdf0e10cSrcweir * @see com.sun.star.beans.XPropertyAccess 92cdf0e10cSrcweir * @see com.sun.star.beans.XPropertyContainer 93cdf0e10cSrcweir * @see com.sun.star.beans.XPropertySet 94cdf0e10cSrcweir * @see com.sun.star.form.XLoadListener 95cdf0e10cSrcweir * @see com.sun.star.container.XChild 96cdf0e10cSrcweir * @see ifc.awt._UnoControlTimeFieldModel 97cdf0e10cSrcweir * @see ifc.io._XPersistObject 98cdf0e10cSrcweir * @see ifc.form.component._TimeField 99cdf0e10cSrcweir * @see ifc.form._XReset 100cdf0e10cSrcweir * @see ifc.form._XBoundComponent 101cdf0e10cSrcweir * @see ifc.form._FormComponent 102cdf0e10cSrcweir * @see ifc.beans._XFastPropertySet 103cdf0e10cSrcweir * @see ifc.beans._XMultiPropertySet 104cdf0e10cSrcweir * @see ifc.form._XUpdateBroadcaster 105cdf0e10cSrcweir * @see ifc.form._DataAwareControlModel 106cdf0e10cSrcweir * @see ifc.beans._XPropertyState 107cdf0e10cSrcweir * @see ifc.form._FormControlModel 108cdf0e10cSrcweir * @see ifc.container._XNamed 109cdf0e10cSrcweir * @see ifc.lang._XComponent 110cdf0e10cSrcweir * @see ifc.lang._XEventListener 111cdf0e10cSrcweir * @see ifc.beans._XPropertySet 112cdf0e10cSrcweir * @see ifc.form._XLoadListener 113cdf0e10cSrcweir * @see ifc.container._XChild 114cdf0e10cSrcweir */ 115cdf0e10cSrcweir public class OTimeModel extends GenericModelTest { 116cdf0e10cSrcweir /** 117cdf0e10cSrcweir * Set some member variable of the super class <CODE>GenericModelTest</CODE>: 118cdf0e10cSrcweir * <pre> 119cdf0e10cSrcweir * super.m_ChangePropertyName = "Time"; 120cdf0e10cSrcweir * super.m_kindOfControl="TimeField"; 121cdf0e10cSrcweir * super.m_ObjectName = "stardiv.one.form.component.TimeField"; 122cdf0e10cSrcweir * NamedValue DataField = new NamedValue(); 123cdf0e10cSrcweir * DataField.Name = "DataField"; 124cdf0e10cSrcweir * DataField.Value = DBTools.TST_INT_F; 125cdf0e10cSrcweir * super.m_propertiesToSet.add(DataField); 126cdf0e10cSrcweir * 127cdf0e10cSrcweir * super.m_LCShape_Type = "FixedText"; 128cdf0e10cSrcweir * </pre> 129cdf0e10cSrcweir * Then <CODE>super.initialize()</CODE> was called. 130cdf0e10cSrcweir * @param tParam the test parameter 131cdf0e10cSrcweir * @param log the log writer 132cdf0e10cSrcweir */ initialize(TestParameters tParam, PrintWriter log)133cdf0e10cSrcweir protected void initialize(TestParameters tParam, PrintWriter log) { 134cdf0e10cSrcweir 135cdf0e10cSrcweir super.initialize(tParam, log); 136cdf0e10cSrcweir 137cdf0e10cSrcweir super.m_ChangePropertyName = "Time"; 138cdf0e10cSrcweir 139cdf0e10cSrcweir super.m_kindOfControl="TimeField"; 140cdf0e10cSrcweir 141cdf0e10cSrcweir super.m_ObjectName = "stardiv.one.form.component.TimeField"; 142cdf0e10cSrcweir 143cdf0e10cSrcweir NamedValue DataField = new NamedValue(); 144cdf0e10cSrcweir DataField.Name = "DataField"; 145cdf0e10cSrcweir DataField.Value = DBTools.TST_INT_F; 146cdf0e10cSrcweir super.m_propertiesToSet.add(DataField); 147cdf0e10cSrcweir 148cdf0e10cSrcweir super.m_LCShape_Type = "FixedText"; 149cdf0e10cSrcweir 150cdf0e10cSrcweir } /** 151cdf0e10cSrcweir * calls <CODE>cleanup()</CODE> from it's super class 152cdf0e10cSrcweir * @param tParam the test parameter 153cdf0e10cSrcweir * @param log the log writer 154cdf0e10cSrcweir */ cleanup(TestParameters tParam, PrintWriter log)155cdf0e10cSrcweir protected void cleanup(TestParameters tParam, PrintWriter log) { 156cdf0e10cSrcweir super.cleanup(tParam, log); 157cdf0e10cSrcweir } 158cdf0e10cSrcweir 159cdf0e10cSrcweir /** 160cdf0e10cSrcweir * calls <CODE>createTestEnvironment()</CODE> from it's super class 161cdf0e10cSrcweir * This test uses not the generic implementaion of <CODE>cecker()</CODE> of its 162cdf0e10cSrcweir * super class. This tests uses its own implementation of <CODE>checker()</CODE> 163cdf0e10cSrcweir * to test <CODE>com::sun::star::form::XUpdateBroadcaster</CODE> 164cdf0e10cSrcweir * @param Param the test parameter 165cdf0e10cSrcweir * @param log the log writer 166cdf0e10cSrcweir * @return lib.TestEnvironment 167cdf0e10cSrcweir */ createTestEnvironment(TestParameters Param, PrintWriter log)168cdf0e10cSrcweir protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, 169cdf0e10cSrcweir PrintWriter log) { 170cdf0e10cSrcweir TestEnvironment tEnv = super.createTestEnvironment(Param, log); 171cdf0e10cSrcweir 172cdf0e10cSrcweir HashSet exclude = new HashSet(); 173cdf0e10cSrcweir 174cdf0e10cSrcweir exclude.add("FormatKey"); 175cdf0e10cSrcweir 176cdf0e10cSrcweir tEnv.addObjRelation("XUpdateBroadcaster.Checker", 177cdf0e10cSrcweir new Checker(m_XFormLoader, m_XPS, m_XCtrl, m_ChangePropertyName, m_ChangePropertyValue)); 178cdf0e10cSrcweir return tEnv; 179cdf0e10cSrcweir } 180cdf0e10cSrcweir 181cdf0e10cSrcweir static class Checker implements UpdateChecker { 182cdf0e10cSrcweir private short lastItem = (short) 0; 183cdf0e10cSrcweir XLoadable formLoaderF = null; 184cdf0e10cSrcweir XPropertySet ps = null; 185cdf0e10cSrcweir XInterface ctrl = null; 186cdf0e10cSrcweir String ChangePropertyName = null; 187cdf0e10cSrcweir Object ChangePropertyValue = null; 188cdf0e10cSrcweir Checker(XLoadable xl, XPropertySet ps, XInterface ctrl, String ChangePropertyName, Object ChangePropertyValue)189cdf0e10cSrcweir public Checker(XLoadable xl, XPropertySet ps, XInterface ctrl, String ChangePropertyName, Object ChangePropertyValue) { 190cdf0e10cSrcweir formLoaderF = xl; 191cdf0e10cSrcweir this.ps = ps; 192cdf0e10cSrcweir this.ctrl = ctrl; 193cdf0e10cSrcweir this.ChangePropertyName=ChangePropertyName; 194cdf0e10cSrcweir this.ChangePropertyValue=ChangePropertyValue; 195cdf0e10cSrcweir } 196cdf0e10cSrcweir 197cdf0e10cSrcweir private int lastTime = 0; 198cdf0e10cSrcweir update()199cdf0e10cSrcweir public void update() throws com.sun.star.uno.Exception { 200cdf0e10cSrcweir if (!formLoaderF.isLoaded()) { 201cdf0e10cSrcweir formLoaderF.load(); 202cdf0e10cSrcweir } 203cdf0e10cSrcweir 204cdf0e10cSrcweir Integer time = (Integer) ps.getPropertyValue("Time"); 205cdf0e10cSrcweir 206cdf0e10cSrcweir if (time != null) { 207cdf0e10cSrcweir lastTime = time.intValue() + 150000; 208cdf0e10cSrcweir } 209cdf0e10cSrcweir 210cdf0e10cSrcweir ps.setPropertyValue("Time", new Integer(lastTime)); 211cdf0e10cSrcweir } 212cdf0e10cSrcweir commit()213cdf0e10cSrcweir public void commit() throws com.sun.star.sdbc.SQLException { 214cdf0e10cSrcweir XBoundComponent bound = (XBoundComponent) UnoRuntime.queryInterface( 215cdf0e10cSrcweir XBoundComponent.class, ctrl); 216cdf0e10cSrcweir XResultSetUpdate update = (XResultSetUpdate) UnoRuntime.queryInterface( 217cdf0e10cSrcweir XResultSetUpdate.class, 218cdf0e10cSrcweir formLoaderF); 219cdf0e10cSrcweir 220cdf0e10cSrcweir bound.commit(); 221cdf0e10cSrcweir update.updateRow(); 222cdf0e10cSrcweir } 223cdf0e10cSrcweir wasCommited()224cdf0e10cSrcweir public boolean wasCommited() throws com.sun.star.uno.Exception { 225cdf0e10cSrcweir formLoaderF.reload(); 226cdf0e10cSrcweir 227cdf0e10cSrcweir Integer getT = (Integer) ps.getPropertyValue("Time"); 228cdf0e10cSrcweir 229cdf0e10cSrcweir return (getT != null) && 230cdf0e10cSrcweir (Math.abs(getT.intValue() - lastTime) < 100); 231cdf0e10cSrcweir } 232cdf0e10cSrcweir } 233cdf0e10cSrcweir } // finish class OTimeModel 234