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: AccessibleTreeListBox.java,v $
10 * $Revision: 1.7.8.1 $
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 ************************************************************************/
33 import java
.io
.PrintWriter
;
35 import lib
.StatusException
;
37 import lib
.TestEnvironment
;
38 import lib
.TestParameters
;
39 import util
.AccessibilityTools
;
40 import util
.DesktopTools
;
41 import util
.SOfficeFactory
;
43 import com
.sun
.star
.accessibility
.AccessibleRole
;
44 import com
.sun
.star
.accessibility
.XAccessible
;
45 import com
.sun
.star
.awt
.XExtendedToolkit
;
46 import com
.sun
.star
.awt
.XWindow
;
47 import com
.sun
.star
.beans
.PropertyValue
;
48 import com
.sun
.star
.frame
.XController
;
49 import com
.sun
.star
.frame
.XDesktop
;
50 import com
.sun
.star
.frame
.XDispatch
;
51 import com
.sun
.star
.frame
.XDispatchProvider
;
52 import com
.sun
.star
.frame
.XFrame
;
53 import com
.sun
.star
.frame
.XModel
;
54 import com
.sun
.star
.lang
.XInitialization
;
55 import com
.sun
.star
.lang
.XMultiServiceFactory
;
56 import com
.sun
.star
.text
.XTextDocument
;
57 import com
.sun
.star
.uno
.UnoRuntime
;
58 import com
.sun
.star
.uno
.XInterface
;
59 import com
.sun
.star
.util
.URL
;
62 * Test for object that implements the following interfaces :
64 * <li><code>::com::sun::star::accessibility::XAccessibleComponent
66 * <li><code>::com::sun::star::accessibility::XAccessibleEventBroadcaster
68 * <li><code>::com::sun::star::accessibility::XAccessibleContext
70 * <li><code>::com::sun::star::accessibility::XAccessibleSelection
74 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
75 * @see com.sun.star.accessibility.XAccessibleContext
76 * @see com.sun.star.accessibility.XAccessibleComponent
77 * @see com.sun.star.accessibility.XAccessibleSelection
78 * @see ifc.accessibility._XAccessibleEventBroadcaster
79 * @see ifc.accessibility._XAccessibleContext
80 * @see ifc.accessibility._XAccessibleComponent
81 * @see ifc.accessibility._XAccessibleSelection
83 public class AccessibleTreeListBox
extends TestCase
{
85 static XDesktop the_Desk
;
86 static XTextDocument xTextDoc
;
89 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
91 protected void initialize(TestParameters Param
, PrintWriter log
) {
92 the_Desk
= (XDesktop
) UnoRuntime
.queryInterface(
93 XDesktop
.class, DesktopTools
.createDesktop((XMultiServiceFactory
)Param
.getMSF()));
97 * Disposes the document, if exists, created in
98 * <code>createTestEnvironment</code> method.
100 protected void cleanup( TestParameters Param
, PrintWriter log
) {
102 log
.println("disposing xTextDoc");
104 if (xTextDoc
!= null) {
110 * Creates a text document. Opens the DataSource browser.
111 * Creates an instance of the service <code>com.sun.star.awt.Toolkit</code>
112 * and gets active top window. Then obtains an accessible object with
113 * the role <code>AccessibleRole.TREE</code>.
114 * Object relations created :
116 * <li> <code>'EventProducer'</code> for
117 * {@link ifc.accessibility._XAccessibleEventBroadcaster}:
119 * <li> <code>'XAccessibleSelection.multiSelection'</code>
120 * of type <code>Boolean</code> for
121 * {@link ifc.accessibility._XAccessibleSelection}:
122 * indicates that component supports single selection mode.</li>
125 * @param tParam test parameters
126 * @param log writer to log information while testing
128 * @see com.sun.star.awt.Toolkit
129 * @see com.sun.star.accessibility.AccessibleRole
130 * @see ifc.accessibility._XAccessibleEventBroadcaster
131 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
133 protected TestEnvironment
createTestEnvironment(
134 TestParameters tParam
, PrintWriter log
) {
136 log
.println( "creating a test environment" );
138 if (xTextDoc
!= null) xTextDoc
.dispose();
140 // get a soffice factory object
141 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF());
144 log
.println( "creating a text document" );
145 xTextDoc
= SOF
.createTextDoc(null);
146 } catch ( com
.sun
.star
.uno
.Exception e
) {
147 // Some exception occures.FAILED
148 e
.printStackTrace( log
);
149 throw new StatusException( "Couldn't create document", e
);
154 XModel aModel1
= (XModel
)
155 UnoRuntime
.queryInterface(XModel
.class, xTextDoc
);
157 XController secondController
= aModel1
.getCurrentController();
159 XDispatchProvider aProv
= (XDispatchProvider
)UnoRuntime
.
160 queryInterface(XDispatchProvider
.class, secondController
);
162 XDispatch getting
= null;
164 log
.println( "opening DatasourceBrowser" );
165 URL the_url
= new URL();
166 the_url
.Complete
= ".component:DB/DataSourceBrowser";
167 getting
= aProv
.queryDispatch(the_url
, "_beamer", 12);
168 PropertyValue
[] noArgs
= new PropertyValue
[0];
169 getting
.dispatch(the_url
, noArgs
);
173 XFrame the_frame1
= the_Desk
.getCurrentFrame();
175 if (the_frame1
== null) {
176 log
.println("Current frame was not found !!!");
179 XFrame the_frame2
= the_frame1
.findFrame("_beamer", 4);
181 the_frame2
.setName("DatasourceBrowser");
183 XInterface oObj
= null;
186 oObj
= (XInterface
) ((XMultiServiceFactory
)tParam
.getMSF()).createInstance
187 ("com.sun.star.awt.Toolkit") ;
188 } catch (com
.sun
.star
.uno
.Exception e
) {
189 log
.println("Couldn't get toolkit");
190 e
.printStackTrace(log
);
191 throw new StatusException("Couldn't get toolkit", e
);
194 XExtendedToolkit tk
= (XExtendedToolkit
)
195 UnoRuntime
.queryInterface(XExtendedToolkit
.class, oObj
);
197 AccessibilityTools at
= new AccessibilityTools();
199 XWindow xWindow
= (XWindow
)
200 UnoRuntime
.queryInterface(XWindow
.class, tk
.getActiveTopWindow());
202 XAccessible xRoot
= at
.getAccessibleObject(xWindow
);
204 oObj
= at
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.TREE
);
206 log
.println("ImplementationName: "+ util
.utils
.getImplName(oObj
));
208 TestEnvironment tEnv
= new TestEnvironment(oObj
);
210 final XInitialization xInit
= (XInitialization
)
211 UnoRuntime
.queryInterface(
212 XInitialization
.class, the_frame2
.getController());
214 Object
[] params
= new Object
[3];
215 PropertyValue param1
= new PropertyValue();
216 param1
.Name
= "DataSourceName";
217 param1
.Value
= "Bibliography";
219 PropertyValue param2
= new PropertyValue();
220 param2
.Name
= "CommandType";
221 param2
.Value
= new Integer(com
.sun
.star
.sdb
.CommandType
.TABLE
);
223 PropertyValue param3
= new PropertyValue();
224 param3
.Name
= "Command";
225 param3
.Value
= "biblio";
228 final Object
[] fParams
= params
;
230 // tEnv.addObjRelation("EventProducer",
231 // new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer(){
232 // public void fireEvent() {
233 // fXComp.grabFocus();
237 tEnv
.addObjRelation("EventProducer",
238 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer(){
239 public void fireEvent() {
241 xInit
.initialize(fParams
);
242 } catch(com
.sun
.star
.uno
.Exception e
) {
248 tEnv
.addObjRelation("XAccessibleSelection.multiSelection",
255 * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
258 private void shortWait() {
261 } catch (InterruptedException e
) {
262 System
.out
.println("While waiting :" + e
) ;