1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 package mod._forms; 24 25 import com.sun.star.beans.NamedValue; 26 import com.sun.star.beans.XPropertySet; 27 import com.sun.star.form.XBoundComponent; 28 import com.sun.star.form.XLoadable; 29 30 31 import com.sun.star.sdbc.SQLException; 32 import com.sun.star.sdbc.XResultSetUpdate; 33 import com.sun.star.uno.Exception; 34 import com.sun.star.uno.UnoRuntime; 35 import com.sun.star.uno.XInterface; 36 import ifc.form._XUpdateBroadcaster.UpdateChecker; 37 import java.io.PrintWriter; 38 import lib.TestEnvironment; 39 import lib.TestParameters; 40 import util.DBTools; 41 42 43 /** 44 * Test for object which is represented by service 45 * <code>com.sun.star.form.component.DatabaseListBox</code>. <p> 46 * Object implements the following interfaces : 47 * <ul> 48 * <li> <code>com::sun::star::io::XPersistObject</code></li> 49 * <li> <code>com::sun::star::awt::UnoControlListBoxModel</code></li> 50 * <li> <code>com::sun::star::form::XReset</code></li> 51 * <li> <code>com::sun::star::form::XBoundComponent</code></li> 52 * <li> <code>com::sun::star::form::FormComponent</code></li> 53 * <li> <code>com::sun::star::form::component::ListBox</code></li> 54 * <li> <code>com::sun::star::beans::XFastPropertySet</code></li> 55 * <li> <code>com::sun::star::beans::XMultiPropertySet</code></li> 56 * <li> <code>com::sun::star::form::XUpdateBroadcaster</code></li> 57 * <li> <code>com::sun::star::form::DataAwareControlModel</code></li> 58 * <li> <code>com::sun::star::beans::XPropertyState</code></li> 59 * <li> <code>com::sun::star::form::FormControlModel</code></li> 60 * <li> <code>com::sun::star::container::XNamed</code></li> 61 * <li> <code>com::sun::star::lang::XComponent</code></li> 62 * <li> <code>com::sun::star::lang::XEventListener</code></li> 63 * <li> <code>com::sun::star::beans::XPropertyAccess</code></li> 64 * <li> <code>com::sun::star::beans::XPropertyContainer</code></li> 65 * <li> <code>com::sun::star::beans::XPropertySet</code></li> 66 * <li> <code>com::sun::star::form::XLoadListener</code></li> 67 * <li> <code>com::sun::star::form::component::DatabaseListBox</code></li> 68 * <li> <code>com::sun::star::container::XChild</code></li> 69 * </ul> <p> 70 * This object test <b> is NOT </b> designed to be run in several 71 * threads concurently. 72 * @see com.sun.star.io.XPersistObject 73 * @see com.sun.star.awt.UnoControlListBoxModel 74 * @see com.sun.star.form.XReset 75 * @see com.sun.star.form.XBoundComponent 76 * @see com.sun.star.form.FormComponent 77 * @see com.sun.star.form.component.ListBox 78 * @see com.sun.star.beans.XFastPropertySet 79 * @see com.sun.star.beans.XMultiPropertySet 80 * @see com.sun.star.form.XUpdateBroadcaster 81 * @see com.sun.star.form.DataAwareControlModel 82 * @see com.sun.star.beans.XPropertyState 83 * @see com.sun.star.form 84 * @see com.sun.star.container.XNamed 85 * @see com.sun.star.lang.XComponent 86 * @see com.sun.star.lang.XEventListener 87 * @see com.sun.star.beans.XPropertyAccess 88 * @see com.sun.star.beans.XPropertyContainer 89 * @see com.sun.star.beans.XPropertySet 90 * @see com.sun.star.form.XLoadListener 91 * @see com.sun.star.form.component.DatabaseListBox 92 * @see com.sun.star.container.XChild 93 * @see ifc.io._XPersistObject 94 * @see ifc.awt._UnoControlListBoxModel 95 * @see ifc.form._XReset 96 * @see ifc.form._XBoundComponent 97 * @see ifc.form._FormComponent 98 * @see ifc.form.component._ListBox 99 * @see ifc.beans._XFastPropertySet 100 * @see ifc.beans._XMultiPropertySet 101 * @see ifc.form._XUpdateBroadcaster 102 * @see ifc.form._DataAwareControlModel 103 * @see ifc.beans._XPropertyState 104 * @see ifc.form._FormControlModel 105 * @see ifc.container._XNamed 106 * @see ifc.lang._XComponent 107 * @see ifc.lang._XEventListener 108 * @see ifc.beans._XPropertySet 109 * @see ifc.form._XLoadListener 110 * @see ifc.form.component._DatabaseListBox 111 * @see ifc.container._XChild 112 */ 113 public class OListBoxModel extends GenericModelTest { 114 /** 115 * Set some member variable of the super class <CODE>GenericModelTest</CODE>: 116 * <pre> 117 * super.m_ChangePropertyName = "Date"; 118 * super.m_kindOfControl="DateField"; 119 * super.m_ObjectName = "stardiv.one.form.component.DateField"; 120 * NamedValue DataField = new NamedValue(); 121 * DataField.Name = "DataField"; 122 * DataField.Value = DBTools.TST_DATE_F; 123 * super.m_propertiesToSet.add(DataField); 124 * 125 * NamedValue ListSource = new NamedValue(); 126 * ListSource.Name = "ListSource"; 127 * ListSource.Value = new String[] { 128 * "OListBoxModel1", "OListBoxModel2", "OListBoxModel3"}; 129 * super.m_propertiesToSet.add(ListSource); 130 * super.m_LCShape_Type = "FixedText"; 131 * </pre> 132 * Then <CODE>super.initialize()</CODE> was called. 133 * @param tParam the test parameter 134 * @param log the log writer 135 */ initialize(TestParameters tParam, PrintWriter log)136 protected void initialize(TestParameters tParam, PrintWriter log) { 137 138 super.initialize(tParam, log); 139 140 super.m_ChangePropertyName = "SelectedItems"; 141 142 super.m_kindOfControl="ListBox"; 143 144 super.m_ObjectName = "stardiv.one.form.component.ListBox"; 145 146 NamedValue DataField = new NamedValue(); 147 DataField.Name = "DataField"; 148 DataField.Value = DBTools.TST_STRING_F; 149 super.m_propertiesToSet.add(DataField); 150 151 NamedValue ListSource = new NamedValue(); 152 ListSource.Name = "ListSource"; 153 ListSource.Value = new String[] { 154 "OListBoxModel1", "OListBoxModel2", "OListBoxModel3"}; 155 super.m_propertiesToSet.add(ListSource); 156 157 super.m_LCShape_Type = "FixedText"; 158 159 } 160 /** 161 * calls <CODE>cleanup()</CODE> from it's super class 162 * @param tParam the test parameter 163 * @param log the log writer 164 */ cleanup(TestParameters tParam, PrintWriter log)165 protected void cleanup(TestParameters tParam, PrintWriter log) { 166 super.cleanup(tParam, log); 167 } 168 169 170 /** 171 * calls <CODE>createTestEnvironment()</CODE> from it's super class 172 * This test uses not the generic implementaion of <CODE>cecker()</CODE> of its 173 * super class. This tests uses its own implementation of <CODE>checker()</CODE> 174 * to test <CODE>com::sun::star::form::XUpdateBroadcaster</CODE> 175 * @param Param the test parameter 176 * @param log the log writer 177 * @return lib.TestEnvironment 178 */ createTestEnvironment(TestParameters Param, PrintWriter log)179 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, 180 PrintWriter log) { 181 TestEnvironment tEnv = super.createTestEnvironment(Param, log); 182 183 tEnv.addObjRelation("XUpdateBroadcaster.Checker", 184 new Checker(m_XFormLoader, m_XPS, m_XCtrl, m_ChangePropertyName, m_ChangePropertyValue)); 185 return tEnv; 186 } 187 188 static class Checker implements UpdateChecker { 189 private short lastItem = (short) 0; 190 XLoadable formLoaderF = null; 191 XPropertySet ps = null; 192 XInterface ctrl = null; 193 String ChangePropertyName = null; 194 Object ChangePropertyValue = null; 195 Checker(XLoadable xl, XPropertySet ps, XInterface ctrl, String ChangePropertyName, Object ChangePropertyValue)196 public Checker(XLoadable xl, XPropertySet ps, XInterface ctrl, String ChangePropertyName, Object ChangePropertyValue) { 197 formLoaderF = xl; 198 this.ps = ps; 199 this.ctrl = ctrl; 200 this.ChangePropertyName=ChangePropertyName; 201 this.ChangePropertyValue=ChangePropertyValue; 202 } 203 update()204 public void update() throws Exception { 205 if (!formLoaderF.isLoaded()) { 206 formLoaderF.load(); 207 } 208 lastItem = (short) (1 - lastItem); 209 ps.setPropertyValue(ChangePropertyName, new short[] { lastItem }); 210 } 211 commit()212 public void commit() throws SQLException { 213 XBoundComponent bound = (XBoundComponent) UnoRuntime.queryInterface( 214 XBoundComponent.class, ctrl); 215 XResultSetUpdate update = (XResultSetUpdate) UnoRuntime.queryInterface( 216 XResultSetUpdate.class, 217 formLoaderF); 218 219 bound.commit(); 220 update.updateRow(); 221 } 222 wasCommited()223 public boolean wasCommited() throws Exception { 224 formLoaderF.reload(); 225 226 short[] getS = (short[]) ps.getPropertyValue(ChangePropertyName); 227 228 return (getS.length > 0) && (lastItem == getS[0]); 229 } 230 } 231 232 } // finish class OListBoxModel 233