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