1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package mod._svtools; 29 30 import java.io.PrintWriter; 31 32 import lib.StatusException; 33 import lib.TestCase; 34 import lib.TestEnvironment; 35 import lib.TestParameters; 36 import util.AccessibilityTools; 37 import util.DesktopTools; 38 import util.SOfficeFactory; 39 40 import com.sun.star.accessibility.AccessibleRole; 41 import com.sun.star.accessibility.XAccessible; 42 import com.sun.star.awt.XWindow; 43 import com.sun.star.beans.PropertyValue; 44 import com.sun.star.frame.XController; 45 import com.sun.star.frame.XDesktop; 46 import com.sun.star.frame.XDispatch; 47 import com.sun.star.frame.XDispatchProvider; 48 import com.sun.star.frame.XFrame; 49 import com.sun.star.frame.XModel; 50 import com.sun.star.lang.XInitialization; 51 import com.sun.star.lang.XMultiServiceFactory; 52 import com.sun.star.text.XTextDocument; 53 import com.sun.star.uno.UnoRuntime; 54 import com.sun.star.uno.XInterface; 55 import com.sun.star.util.URL; 56 57 /** 58 * Test for object that implements the following interfaces : 59 * <ul> 60 * <li><code>::com::sun::star::accessibility::XAccessibleComponent 61 * </code></li> 62 * <li><code>::com::sun::star::accessibility::XAccessibleEventBroadcaster 63 * </code></li> 64 * <li><code>::com::sun::star::accessibility::XAccessibleContext 65 * </code></li> 66 * <li><code>::com::sun::star::accessibility::XAccessibleSelection 67 * </code></li> 68 * </ul> <p> 69 * 70 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster 71 * @see com.sun.star.accessibility.XAccessibleContext 72 * @see com.sun.star.accessibility.XAccessibleComponent 73 * @see com.sun.star.accessibility.XAccessibleSelection 74 * @see ifc.accessibility._XAccessibleEventBroadcaster 75 * @see ifc.accessibility._XAccessibleContext 76 * @see ifc.accessibility._XAccessibleComponent 77 * @see ifc.accessibility._XAccessibleSelection 78 */ 79 public class AccessibleTreeListBox extends TestCase { 80 81 static XDesktop the_Desk; 82 static XTextDocument xTextDoc; 83 84 /** 85 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>). 86 */ 87 protected void initialize(TestParameters Param, PrintWriter log) { 88 the_Desk = (XDesktop) UnoRuntime.queryInterface( 89 XDesktop.class, DesktopTools.createDesktop((XMultiServiceFactory)Param.getMSF())); 90 } 91 92 /** 93 * Disposes the document, if exists, created in 94 * <code>createTestEnvironment</code> method. 95 */ 96 protected void cleanup( TestParameters Param, PrintWriter log) { 97 98 log.println("disposing xTextDoc"); 99 100 if (xTextDoc != null) { 101 xTextDoc.dispose(); 102 } 103 } 104 105 /** 106 * Creates a text document. Opens the DataSource browser. 107 * Creates an instance of the service <code>com.sun.star.awt.Toolkit</code> 108 * and gets active top window. Then obtains an accessible object with 109 * the role <code>AccessibleRole.TREE</code>. 110 * Object relations created : 111 * <ul> 112 * <li> <code>'EventProducer'</code> for 113 * {@link ifc.accessibility._XAccessibleEventBroadcaster}: 114 * </li> 115 * <li> <code>'XAccessibleSelection.multiSelection'</code> 116 * of type <code>Boolean</code> for 117 * {@link ifc.accessibility._XAccessibleSelection}: 118 * indicates that component supports single selection mode.</li> 119 * </ul> 120 * 121 * @param tParam test parameters 122 * @param log writer to log information while testing 123 * 124 * @see com.sun.star.awt.Toolkit 125 * @see com.sun.star.accessibility.AccessibleRole 126 * @see ifc.accessibility._XAccessibleEventBroadcaster 127 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster 128 */ 129 protected TestEnvironment createTestEnvironment( 130 TestParameters tParam, PrintWriter log) { 131 132 log.println( "creating a test environment" ); 133 134 if (xTextDoc != null) xTextDoc.dispose(); 135 136 // get a soffice factory object 137 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF()); 138 139 try { 140 log.println( "creating a text document" ); 141 xTextDoc = SOF.createTextDoc(null); 142 } catch ( com.sun.star.uno.Exception e ) { 143 // Some exception occures.FAILED 144 e.printStackTrace( log ); 145 throw new StatusException( "Couldn't create document", e ); 146 } 147 148 shortWait(); 149 150 XModel aModel1 = (XModel) 151 UnoRuntime.queryInterface(XModel.class, xTextDoc); 152 153 XController secondController = aModel1.getCurrentController(); 154 155 XDispatchProvider aProv = (XDispatchProvider)UnoRuntime. 156 queryInterface(XDispatchProvider.class, secondController); 157 158 XDispatch getting = null; 159 160 log.println( "opening DatasourceBrowser" ); 161 URL the_url = new URL(); 162 the_url.Complete = ".component:DB/DataSourceBrowser"; 163 getting = aProv.queryDispatch(the_url, "_beamer", 12); 164 PropertyValue[] noArgs = new PropertyValue[0]; 165 getting.dispatch(the_url, noArgs); 166 167 shortWait(); 168 169 XFrame the_frame1 = the_Desk.getCurrentFrame(); 170 171 if (the_frame1 == null) { 172 log.println("Current frame was not found !!!"); 173 } 174 175 XFrame the_frame2 = the_frame1.findFrame("_beamer", 4); 176 177 the_frame2.setName("DatasourceBrowser"); 178 179 XInterface oObj = null; 180 181 AccessibilityTools at = new AccessibilityTools(); 182 183 XWindow xWindow = secondController.getFrame().getContainerWindow(); 184 185 XAccessible xRoot = at.getAccessibleObject(xWindow); 186 187 oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.TREE); 188 189 log.println("ImplementationName: "+ util.utils.getImplName(oObj)); 190 191 TestEnvironment tEnv = new TestEnvironment(oObj); 192 193 final XInitialization xInit = (XInitialization) 194 UnoRuntime.queryInterface( 195 XInitialization.class, the_frame2.getController()); 196 197 Object[] params = new Object[3]; 198 PropertyValue param1 = new PropertyValue(); 199 param1.Name = "DataSourceName"; 200 param1.Value = "Bibliography"; 201 params[0] = param1; 202 PropertyValue param2 = new PropertyValue(); 203 param2.Name = "CommandType"; 204 param2.Value = new Integer(com.sun.star.sdb.CommandType.TABLE); 205 params[1] = param2; 206 PropertyValue param3 = new PropertyValue(); 207 param3.Name = "Command"; 208 param3.Value = "biblio"; 209 params[2] = param3; 210 211 final Object[] fParams = params; 212 213 // tEnv.addObjRelation("EventProducer", 214 // new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer(){ 215 // public void fireEvent() { 216 // fXComp.grabFocus(); 217 // } 218 // }); 219 220 tEnv.addObjRelation("EventProducer", 221 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer(){ 222 public void fireEvent() { 223 try { 224 xInit.initialize(fParams); 225 } catch(com.sun.star.uno.Exception e) { 226 e.printStackTrace(); 227 } 228 } 229 }); 230 231 tEnv.addObjRelation("XAccessibleSelection.multiSelection", 232 new Boolean(false)); 233 234 return tEnv; 235 } 236 237 /** 238 * Sleeps for 0.5 sec. to allow StarOffice to react on <code> 239 * reset</code> call. 240 */ 241 private void shortWait() { 242 try { 243 Thread.sleep(5000); 244 } catch (InterruptedException e) { 245 System.out.println("While waiting :" + e) ; 246 } 247 } 248 249 } 250