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 package mod._toolkit; 28 29 import com.sun.star.accessibility.AccessibleRole; 30 import com.sun.star.accessibility.XAccessible; 31 import com.sun.star.accessibility.XAccessibleAction; 32 import com.sun.star.accessibility.XAccessibleComponent; 33 import com.sun.star.accessibility.XAccessibleContext; 34 import com.sun.star.accessibility.XAccessibleSelection; 35 import com.sun.star.awt.XExtendedToolkit; 36 import com.sun.star.awt.XWindow; 37 import com.sun.star.beans.PropertyValue; 38 import com.sun.star.frame.XController; 39 import com.sun.star.frame.XDispatch; 40 import com.sun.star.frame.XDispatchProvider; 41 import com.sun.star.frame.XModel; 42 import com.sun.star.lang.XMultiServiceFactory; 43 import com.sun.star.text.XTextDocument; 44 import com.sun.star.uno.UnoRuntime; 45 import com.sun.star.uno.XInterface; 46 import com.sun.star.util.URL; 47 import com.sun.star.util.XURLTransformer; 48 49 import java.io.PrintWriter; 50 51 import lib.StatusException; 52 import lib.TestCase; 53 import lib.TestEnvironment; 54 import lib.TestParameters; 55 56 import util.AccessibilityTools; 57 import util.SOfficeFactory; 58 import util.utils; 59 60 61 public class AccessibleList extends TestCase { 62 private static XTextDocument xTextDoc = null; 63 private static XAccessibleAction action = null; 64 private static XMultiServiceFactory msf = null; 65 66 /** 67 * Opens 'Insert Hyperlink' dialog using document dispatch provider. 68 * Finds active top window (the dialog 69 * window) and finds button 'Close' (for closing this dialog when 70 * disposing) walking through the accessible component tree. 71 * Then the TREE component is found and the 'New Document' tab is 72 * selected to make list box visible. After that list box is obtained. 73 */ 74 protected TestEnvironment createTestEnvironment(TestParameters Param, 75 PrintWriter log) { 76 XInterface oObj = null; 77 78 try { 79 oObj = (XInterface) msf.createInstance("com.sun.star.awt.Toolkit"); 80 } catch (com.sun.star.uno.Exception e) { 81 log.println("Couldn't get toolkit"); 82 e.printStackTrace(log); 83 throw new StatusException("Couldn't get toolkit", e); 84 } 85 86 XExtendedToolkit tk = (XExtendedToolkit) UnoRuntime.queryInterface( 87 XExtendedToolkit.class, oObj); 88 89 shortWait(); 90 91 XModel aModel1 = (XModel) UnoRuntime.queryInterface(XModel.class, 92 xTextDoc); 93 94 XController secondController = aModel1.getCurrentController(); 95 96 XDispatchProvider aProv = (XDispatchProvider) UnoRuntime.queryInterface( 97 XDispatchProvider.class, 98 secondController); 99 100 XURLTransformer urlTransf = null; 101 102 try { 103 XInterface transf = (XInterface) msf.createInstance( 104 "com.sun.star.util.URLTransformer"); 105 urlTransf = (XURLTransformer) UnoRuntime.queryInterface( 106 XURLTransformer.class, transf); 107 } catch (com.sun.star.uno.Exception e) { 108 e.printStackTrace(log); 109 throw new StatusException("Couldn't create URLTransformer", e); 110 } 111 112 XDispatch getting = null; 113 log.println("opening HyperlinkDialog"); 114 115 URL[] url = new URL[1]; 116 url[0] = new URL(); 117 url[0].Complete = ".uno:HyperlinkDialog"; 118 urlTransf.parseStrict(url); 119 getting = aProv.queryDispatch(url[0], "", 0); 120 121 PropertyValue[] noArgs = new PropertyValue[0]; 122 getting.dispatch(url[0], noArgs); 123 124 shortWait(); 125 126 AccessibilityTools at = new AccessibilityTools(); 127 128 XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class, 129 tk.getActiveTopWindow()); 130 131 XAccessible xRoot = at.getAccessibleObject(xWindow); 132 133 134 at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE)); 135 // obtaining 'Close' button 136 oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.PUSH_BUTTON, 137 "Close"); 138 action = (XAccessibleAction) UnoRuntime.queryInterface( 139 XAccessibleAction.class, oObj); 140 141 // Selecting 'New Document' tab 142 try { 143 oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.TREE); 144 145 XAccessibleSelection xAccSel = (XAccessibleSelection) UnoRuntime.queryInterface( 146 XAccessibleSelection.class, 147 oObj); 148 xAccSel.selectAccessibleChild(3); 149 shortWait(); 150 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 151 throw new StatusException("Can't switch to required tab", e); 152 } 153 154 log.println("# Getting the ListBox"); 155 156 XAccessibleContext parent = at.getAccessibleObjectForRole(xRoot, 157 AccessibleRole.PANEL, 158 "", 159 "com.sun.star.comp.toolkit.AccessibleListBox"); 160 161 log.println("# Getting the first child"); 162 163 try { 164 oObj = parent.getAccessibleChild(0); 165 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 166 } 167 168 log.println("ImplementationName " + utils.getImplName(oObj)); 169 170 TestEnvironment tEnv = new TestEnvironment(oObj); 171 172 tEnv.addObjRelation("XAccessibleSelection.multiSelection", 173 new Boolean(false)); 174 175 final XAccessibleComponent acomp = (XAccessibleComponent) UnoRuntime.queryInterface( 176 XAccessibleComponent.class, 177 oObj); 178 final XAccessibleComponent acomp1 = (XAccessibleComponent) UnoRuntime.queryInterface( 179 XAccessibleComponent.class, 180 action); 181 182 tEnv.addObjRelation("EventProducer", 183 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() { 184 public void fireEvent() { 185 System.out.println("Grabbing focus ... "); 186 acomp1.grabFocus(); 187 acomp.grabFocus(); 188 } 189 }); 190 191 return tEnv; 192 } 193 194 /** 195 * Closes dialog using action of button 'Close' 196 */ 197 protected void cleanup(TestParameters Param, PrintWriter log) { 198 log.println(" Closing dialog ... "); 199 200 try { 201 action.doAccessibleAction(0); 202 } catch (com.sun.star.lang.IndexOutOfBoundsException ioe) { 203 log.println("Couldn't close dialog"); 204 } catch (com.sun.star.lang.DisposedException de) { 205 log.println("Dialog already disposed"); 206 } 207 208 util.DesktopTools.closeDoc(xTextDoc); 209 ; 210 } 211 212 /** 213 * Creates writer document 214 */ 215 protected void initialize(TestParameters Param, PrintWriter log) { 216 try { 217 msf = (XMultiServiceFactory) Param.getMSF(); 218 219 SOfficeFactory SOF = SOfficeFactory.getFactory(msf); 220 xTextDoc = SOF.createTextDoc(null); 221 } catch (com.sun.star.uno.Exception e) { 222 throw new StatusException("Can't create document", e); 223 } 224 } 225 226 /** 227 * Sleeps for 0.5 sec. to allow StarOffice to react on <code> 228 * reset</code> call. 229 */ 230 private void shortWait() { 231 try { 232 Thread.sleep(1000); 233 } catch (InterruptedException e) { 234 log.println("While waiting :" + e); 235 } 236 } 237 }