1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AccessibleListBox.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 import com
.sun
.star
.accessibility
.AccessibleRole
;
33 import com
.sun
.star
.accessibility
.XAccessible
;
34 import com
.sun
.star
.accessibility
.XAccessibleAction
;
35 import com
.sun
.star
.accessibility
.XAccessibleComponent
;
36 import com
.sun
.star
.accessibility
.XAccessibleSelection
;
37 import com
.sun
.star
.awt
.XExtendedToolkit
;
38 import com
.sun
.star
.awt
.XWindow
;
39 import com
.sun
.star
.beans
.PropertyValue
;
40 import com
.sun
.star
.frame
.XController
;
41 import com
.sun
.star
.frame
.XDispatch
;
42 import com
.sun
.star
.frame
.XDispatchProvider
;
43 import com
.sun
.star
.frame
.XModel
;
44 import com
.sun
.star
.lang
.XMultiServiceFactory
;
45 import com
.sun
.star
.text
.XTextDocument
;
46 import com
.sun
.star
.uno
.UnoRuntime
;
47 import com
.sun
.star
.uno
.XInterface
;
48 import com
.sun
.star
.util
.URL
;
49 import com
.sun
.star
.util
.XURLTransformer
;
51 import java
.io
.PrintWriter
;
53 import lib
.StatusException
;
55 import lib
.TestEnvironment
;
56 import lib
.TestParameters
;
58 import util
.AccessibilityTools
;
59 import util
.SOfficeFactory
;
64 * Test for object which is represented accessible component
65 * of 'File type' list box situated in 'Insert Hyperlink'
66 * dialog on tab 'New Document'. <p>
68 * Object implements the following interfaces :
70 * <li> <code>::com::sun::star::accessibility::XAccessibleExtendedComponent</code></li>
71 * <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li>
72 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
73 * <li> <code>::com::sun::star::accessibility::XAccessibleSelection</code></li>
74 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
77 * @see com.sun.star.accessibility.XAccessibleExtendedComponent
78 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
79 * @see com.sun.star.accessibility.XAccessibleComponent
80 * @see com.sun.star.accessibility.XAccessibleSelection
81 * @see com.sun.star.accessibility.XAccessibleContext
82 * @see ifc.accessibility._XAccessibleExtendedComponent
83 * @see ifc.accessibility._XAccessibleEventBroadcaster
84 * @see ifc.accessibility._XAccessibleComponent
85 * @see ifc.accessibility._XAccessibleSelection
86 * @see ifc.accessibility._XAccessibleContext
88 public class AccessibleListBox
extends TestCase
{
89 private static XTextDocument xTextDoc
= null;
90 private static XAccessibleAction action
= null;
93 * Opens 'Insert Hyperlink' dialog using document dispatch provider.
94 * Finds active top window (the dialog
95 * window) and finds button 'Close' (for closing this dialog when
96 * disposing) walking through the accessible component tree.
97 * Then the TREE component is found and the 'New Document' tab is
98 * selected to make list box visible. After that list box is obtained.
100 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
102 XInterface oObj
= null;
105 oObj
= (XInterface
) ((XMultiServiceFactory
) Param
.getMSF()).createInstance(
106 "com.sun.star.awt.Toolkit");
107 } catch (com
.sun
.star
.uno
.Exception e
) {
108 log
.println("Couldn't get toolkit");
109 e
.printStackTrace(log
);
110 throw new StatusException("Couldn't get toolkit", e
);
113 XExtendedToolkit tk
= (XExtendedToolkit
) UnoRuntime
.queryInterface(
114 XExtendedToolkit
.class, oObj
);
118 XModel aModel1
= (XModel
) UnoRuntime
.queryInterface(XModel
.class,
121 XController secondController
= aModel1
.getCurrentController();
123 XDispatchProvider aProv
= (XDispatchProvider
) UnoRuntime
.queryInterface(
124 XDispatchProvider
.class,
127 XURLTransformer urlTransf
= null;
130 XInterface transf
= (XInterface
) ((XMultiServiceFactory
) Param
.getMSF()).createInstance(
131 "com.sun.star.util.URLTransformer");
132 urlTransf
= (XURLTransformer
) UnoRuntime
.queryInterface(
133 XURLTransformer
.class, transf
);
134 } catch (com
.sun
.star
.uno
.Exception e
) {
135 e
.printStackTrace(log
);
136 throw new StatusException("Couldn't create URLTransformer", e
);
139 XDispatch getting
= null;
140 log
.println("opening HyperlinkDialog");
142 URL
[] url
= new URL
[1];
144 url
[0].Complete
= ".uno:HyperlinkDialog";
145 urlTransf
.parseStrict(url
);
146 getting
= aProv
.queryDispatch(url
[0], "", 0);
148 PropertyValue
[] noArgs
= new PropertyValue
[0];
149 getting
.dispatch(url
[0], noArgs
);
153 AccessibilityTools at
= new AccessibilityTools();
155 XWindow xWindow
= (XWindow
) UnoRuntime
.queryInterface(XWindow
.class,
156 tk
.getActiveTopWindow());
158 XAccessible xRoot
= at
.getAccessibleObject(xWindow
);
160 at
.printAccessibleTree(log
, xRoot
, Param
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
));
163 // obtaining 'Close' button
164 oObj
= at
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.PUSH_BUTTON
,
166 action
= (XAccessibleAction
) UnoRuntime
.queryInterface(
167 XAccessibleAction
.class, oObj
);
169 // Selecting 'New Document' tab
171 oObj
= at
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.TREE
);
173 XAccessibleSelection xAccSel
= (XAccessibleSelection
) UnoRuntime
.queryInterface(
174 XAccessibleSelection
.class,
176 xAccSel
.selectAccessibleChild(3);
178 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
179 throw new StatusException("Can't switch to required tab", e
);
182 oObj
= at
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.PANEL
, "",
183 "com.sun.star.comp.toolkit.AccessibleListBox");
185 Object list
= at
.getAccessibleObjectForRole(at
.SearchedAccessible
,
186 AccessibleRole
.LIST
);
188 log
.println("ImplementationName " + utils
.getImplName(oObj
));
190 TestEnvironment tEnv
= new TestEnvironment(oObj
);
192 final XAccessibleComponent acomp
= (XAccessibleComponent
) UnoRuntime
.queryInterface(
193 XAccessibleComponent
.class,
195 final XAccessibleComponent acomp1
= (XAccessibleComponent
) UnoRuntime
.queryInterface(
196 XAccessibleComponent
.class,
199 tEnv
.addObjRelation("EventProducer",
200 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
201 public void fireEvent() {
202 System
.out
.println("Grabbing focus ... ");
212 * Closes dialog using action of button 'Close'
214 protected void cleanup(TestParameters Param
, PrintWriter log
) {
215 log
.println(" Closing dialog ... ");
218 action
.doAccessibleAction(0);
219 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException ioe
) {
220 log
.println("Couldn't close dialog");
221 } catch (com
.sun
.star
.lang
.DisposedException de
) {
222 log
.println("Dialog already disposed");
225 util
.DesktopTools
.closeDoc(xTextDoc
);
230 * Creates writer document
232 protected void initialize(TestParameters Param
, PrintWriter log
) {
234 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
235 (XMultiServiceFactory
) Param
.getMSF());
236 xTextDoc
= SOF
.createTextDoc(null);
237 } catch (com
.sun
.star
.uno
.Exception e
) {
238 throw new StatusException("Can't create document", e
);
243 * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
246 private void shortWait() {
249 } catch (InterruptedException e
) {
250 log
.println("While waiting :" + e
);