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: AccessibleBrowseBoxTable.java,v $
10 * $Revision: 1.8.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 ************************************************************************/
32 import com
.sun
.star
.view
.XSelectionSupplier
;
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
.XMultiServiceFactory
;
55 import com
.sun
.star
.text
.XTextDocument
;
56 import com
.sun
.star
.uno
.UnoRuntime
;
57 import com
.sun
.star
.uno
.XInterface
;
58 import com
.sun
.star
.util
.URL
;
62 * Test for object that implements the following interfaces :
65 * <code>::com::sun::star::accessibility::XAccessibleContext
68 * <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster
72 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
73 * @see com.sun.star.accessibility.XAccessibleContext
74 * @see ifc.accessibility._XAccessibleEventBroadcaster
75 * @see ifc.accessibility._XAccessibleContext
77 public class AccessibleBrowseBoxTable
extends TestCase
{
78 static XDesktop the_Desk
;
79 static XTextDocument xTextDoc
;
82 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
84 protected void initialize(TestParameters Param
, PrintWriter log
) {
85 the_Desk
= (XDesktop
) UnoRuntime
.queryInterface(XDesktop
.class,
86 DesktopTools
.createDesktop(
87 (XMultiServiceFactory
)Param
.getMSF()));
91 * Disposes the document, if exists, created in
92 * <code>createTestEnvironment</code> method.
94 protected void cleanup(TestParameters Param
, PrintWriter log
) {
95 log
.println("disposing xTextDoc");
97 if (xTextDoc
!= null) {
103 * Creates a text document. Opens the DataSource browser.
104 * Creates an instance of the service
105 * <code>com.sun.star.awt.Toolkit</code> and gets active top window.
106 * Then obtains an accessible object with the role
107 * <code>AccessibleRole.TABLE</code> and with the name
108 * <code>"Table"</code>.
109 * Object relations created :
111 * <li> <code>'EventProducer'</code> for
112 * {@link ifc.accessibility._XAccessibleEventBroadcaster}:
113 * method <code>fireEvent()</code> is empty because object is transient
117 * @param tParam test parameters
118 * @param log writer to log information while testing
120 * @see com.sun.star.awt.Toolkit
121 * @see com.sun.star.accessibility.AccessibleRole
122 * @see ifc.accessibility._XAccessibleEventBroadcaster
123 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
125 protected TestEnvironment
createTestEnvironment(TestParameters tParam
,
127 log
.println("creating a test environment");
129 if (xTextDoc
!= null) {
133 // get a soffice factory object
134 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
135 (XMultiServiceFactory
)tParam
.getMSF());
138 log
.println("creating a text document");
139 xTextDoc
= SOF
.createTextDoc(null);
140 } catch (com
.sun
.star
.uno
.Exception e
) {
141 // Some exception occures.FAILED
142 e
.printStackTrace(log
);
143 throw new StatusException("Couldn't create document", e
);
148 XModel aModel1
= (XModel
) UnoRuntime
.queryInterface(XModel
.class,
151 XController secondController
= aModel1
.getCurrentController();
153 XDispatchProvider aProv
= (XDispatchProvider
)UnoRuntime
.queryInterface(
154 XDispatchProvider
.class,
157 XDispatch getting
= null;
159 log
.println("opening DatasourceBrowser");
161 URL the_url
= new URL();
162 the_url
.Complete
= ".component:DB/DataSourceBrowser";
163 getting
= aProv
.queryDispatch(the_url
, "_beamer", 12);
165 PropertyValue
[] noArgs
= new PropertyValue
[0];
166 getting
.dispatch(the_url
, noArgs
);
170 XFrame the_frame1
= the_Desk
.getCurrentFrame();
172 if (the_frame1
== null) {
173 log
.println("Current frame was not found !!!");
176 XFrame the_frame2
= the_frame1
.findFrame("_beamer", 4);
177 XController xCont
= the_frame2
.getController();
179 the_frame2
.setName("DatasourceBrowser");
181 final PropertyValue
[] params
= new PropertyValue
[3];
182 PropertyValue param1
= new PropertyValue();
183 param1
.Name
= "DataSourceName";
184 param1
.Value
= "Bibliography";
187 PropertyValue param2
= new PropertyValue();
188 param2
.Name
= "CommandType";
189 param2
.Value
= new Integer(com
.sun
.star
.sdb
.CommandType
.TABLE
);
192 PropertyValue param3
= new PropertyValue();
193 param3
.Name
= "Command";
194 param3
.Value
= "biblio";
197 final XSelectionSupplier xSelect
= (XSelectionSupplier
) UnoRuntime
.queryInterface(
198 XSelectionSupplier
.class, xCont
);
201 final Object
[] initArgs
= params
;
203 XInterface oObj
= null;
206 oObj
= (XInterface
)((XMultiServiceFactory
)tParam
.getMSF())
207 .createInstance("com.sun.star.awt.Toolkit");
208 } catch (com
.sun
.star
.uno
.Exception e
) {
209 log
.println("Couldn't get toolkit");
210 e
.printStackTrace(log
);
211 throw new StatusException("Couldn't get toolkit", e
);
214 XExtendedToolkit tk
= (XExtendedToolkit
) UnoRuntime
.queryInterface(
215 XExtendedToolkit
.class, oObj
);
217 AccessibilityTools at
= new AccessibilityTools();
219 XWindow xWindow
= (XWindow
) UnoRuntime
.queryInterface(XWindow
.class,
220 tk
.getActiveTopWindow());
222 XAccessible xRoot
= at
.getAccessibleObject(xWindow
);
224 oObj
= at
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.TABLE
,
227 log
.println("ImplementationName: " + util
.utils
.getImplName(oObj
));
229 TestEnvironment tEnv
= new TestEnvironment(oObj
);
231 tEnv
.addObjRelation("EventProducer",
232 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
233 public void fireEvent() {
235 xSelect
.select(params
);
236 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
245 * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
248 private void shortWait() {
251 } catch (InterruptedException e
) {
252 System
.out
.println("While waiting :" + e
);