2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 import com
.sun
.star
.accessibility
.AccessibleRole
;
21 import com
.sun
.star
.accessibility
.XAccessible
;
22 import com
.sun
.star
.accessibility
.XAccessibleAction
;
23 import com
.sun
.star
.accessibility
.XAccessibleComponent
;
24 import com
.sun
.star
.accessibility
.XAccessibleContext
;
25 import com
.sun
.star
.accessibility
.XAccessibleSelection
;
26 import com
.sun
.star
.awt
.XExtendedToolkit
;
27 import com
.sun
.star
.awt
.XWindow
;
28 import com
.sun
.star
.beans
.PropertyValue
;
29 import com
.sun
.star
.frame
.XController
;
30 import com
.sun
.star
.frame
.XDispatch
;
31 import com
.sun
.star
.frame
.XDispatchProvider
;
32 import com
.sun
.star
.frame
.XModel
;
33 import com
.sun
.star
.lang
.XMultiServiceFactory
;
34 import com
.sun
.star
.text
.XTextDocument
;
35 import com
.sun
.star
.uno
.UnoRuntime
;
36 import com
.sun
.star
.uno
.XInterface
;
37 import com
.sun
.star
.util
.URL
;
38 import com
.sun
.star
.util
.XURLTransformer
;
40 import java
.io
.PrintWriter
;
42 import lib
.StatusException
;
44 import lib
.TestEnvironment
;
45 import lib
.TestParameters
;
47 import util
.AccessibilityTools
;
48 import util
.SOfficeFactory
;
52 public class AccessibleList
extends TestCase
{
53 private static XTextDocument xTextDoc
= null;
54 private static XAccessibleAction action
= null;
55 private static XMultiServiceFactory msf
= null;
58 * Opens 'Insert Hyperlink' dialog using document dispatch provider.
59 * Finds active top window (the dialog
60 * window) and finds button 'Close' (for closing this dialog when
61 * disposing) walking through the accessible component tree.
62 * Then the TREE component is found and the 'New Document' tab is
63 * selected to make list box visible. After that list box is obtained.
66 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
68 XInterface oObj
= null;
71 oObj
= (XInterface
) msf
.createInstance("com.sun.star.awt.Toolkit");
72 } catch (com
.sun
.star
.uno
.Exception e
) {
73 log
.println("Couldn't get toolkit");
74 e
.printStackTrace(log
);
75 throw new StatusException("Couldn't get toolkit", e
);
78 XExtendedToolkit tk
= UnoRuntime
.queryInterface(
79 XExtendedToolkit
.class, oObj
);
81 util
.utils
.pause(1000);
83 XModel aModel1
= UnoRuntime
.queryInterface(XModel
.class,
86 XController secondController
= aModel1
.getCurrentController();
88 XDispatchProvider aProv
= UnoRuntime
.queryInterface(
89 XDispatchProvider
.class,
92 XURLTransformer urlTransf
= null;
95 XInterface transf
= (XInterface
) msf
.createInstance(
96 "com.sun.star.util.URLTransformer");
97 urlTransf
= UnoRuntime
.queryInterface(
98 XURLTransformer
.class, transf
);
99 } catch (com
.sun
.star
.uno
.Exception e
) {
100 e
.printStackTrace(log
);
101 throw new StatusException("Couldn't create URLTransformer", e
);
104 XDispatch getting
= null;
105 log
.println("opening HyperlinkDialog");
107 URL
[] url
= new URL
[1];
109 url
[0].Complete
= ".uno:HyperlinkDialog";
110 urlTransf
.parseStrict(url
);
111 getting
= aProv
.queryDispatch(url
[0], "", 0);
113 PropertyValue
[] noArgs
= new PropertyValue
[0];
114 getting
.dispatch(url
[0], noArgs
);
116 util
.utils
.pause(1000);
118 XWindow xWindow
= UnoRuntime
.queryInterface(XWindow
.class,
119 tk
.getActiveTopWindow());
121 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
124 AccessibilityTools
.printAccessibleTree(log
, xRoot
, Param
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
));
125 // obtaining 'Close' button
126 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.PUSH_BUTTON
,
128 action
= UnoRuntime
.queryInterface(
129 XAccessibleAction
.class, oObj
);
131 // Selecting 'New Document' tab
133 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.TREE
);
135 XAccessibleSelection xAccSel
= UnoRuntime
.queryInterface(
136 XAccessibleSelection
.class,
138 xAccSel
.selectAccessibleChild(3);
139 util
.utils
.pause(1000);
140 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
141 throw new StatusException("Can't switch to required tab", e
);
144 log
.println("# Getting the ListBox");
146 XAccessibleContext parent
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
,
147 AccessibleRole
.PANEL
,
149 "com.sun.star.comp.toolkit.AccessibleListBox");
151 log
.println("# Getting the first child");
154 oObj
= parent
.getAccessibleChild(0);
155 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
158 log
.println("ImplementationName " + utils
.getImplName(oObj
));
160 TestEnvironment tEnv
= new TestEnvironment(oObj
);
162 tEnv
.addObjRelation("XAccessibleSelection.multiSelection",
165 final XAccessibleComponent acomp
= UnoRuntime
.queryInterface(
166 XAccessibleComponent
.class,
168 final XAccessibleComponent acomp1
= UnoRuntime
.queryInterface(
169 XAccessibleComponent
.class,
172 tEnv
.addObjRelation("EventProducer",
173 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
174 public void fireEvent() {
175 System
.out
.println("Grabbing focus ... ");
185 * Closes dialog using action of button 'Close'
188 protected void cleanup(TestParameters Param
, PrintWriter log
) {
189 log
.println(" Closing dialog ... ");
192 action
.doAccessibleAction(0);
193 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException ioe
) {
194 log
.println("Couldn't close dialog");
195 } catch (com
.sun
.star
.lang
.DisposedException de
) {
196 log
.println("Dialog already disposed");
199 util
.DesktopTools
.closeDoc(xTextDoc
);
203 * Creates writer document
206 protected void initialize(TestParameters Param
, PrintWriter log
) {
208 msf
= Param
.getMSF();
210 SOfficeFactory SOF
= SOfficeFactory
.getFactory(msf
);
211 xTextDoc
= SOF
.createTextDoc(null);
212 } catch (com
.sun
.star
.uno
.Exception e
) {
213 throw new StatusException("Can't create document", e
);