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: AccessibleEditableTextPara_HeaderFooter.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 java
.io
.PrintWriter
;
34 import lib
.StatusException
;
36 import lib
.TestEnvironment
;
37 import lib
.TestParameters
;
38 import util
.AccessibilityTools
;
39 import util
.SOfficeFactory
;
42 import com
.sun
.star
.accessibility
.AccessibleRole
;
43 import com
.sun
.star
.accessibility
.XAccessible
;
44 import com
.sun
.star
.accessibility
.XAccessibleAction
;
45 import com
.sun
.star
.accessibility
.XAccessibleContext
;
46 import com
.sun
.star
.accessibility
.XAccessibleEditableText
;
47 import com
.sun
.star
.accessibility
.XAccessibleText
;
48 import com
.sun
.star
.awt
.XExtendedToolkit
;
49 import com
.sun
.star
.awt
.XWindow
;
50 import com
.sun
.star
.frame
.XController
;
51 import com
.sun
.star
.frame
.XDispatch
;
52 import com
.sun
.star
.frame
.XDispatchProvider
;
53 import com
.sun
.star
.frame
.XModel
;
54 import com
.sun
.star
.lang
.XComponent
;
55 import com
.sun
.star
.lang
.XMultiServiceFactory
;
56 import com
.sun
.star
.uno
.UnoRuntime
;
57 import com
.sun
.star
.util
.URL
;
58 import com
.sun
.star
.util
.XURLTransformer
;
61 public class AccessibleEditableTextPara_HeaderFooter
extends TestCase
{
62 protected static XComponent xCalcDoc
= null;
63 protected static XMultiServiceFactory msf
= null;
64 protected static XAccessibleAction action
= null;
66 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
68 XAccessibleContext oObj
= null;
69 Object toolkit
= null;
72 toolkit
= msf
.createInstance("com.sun.star.awt.Toolkit");
73 } catch (com
.sun
.star
.uno
.Exception e
) {
74 log
.println("Couldn't get toolkit");
75 e
.printStackTrace(log
);
76 throw new StatusException("Couldn't get toolkit", e
);
79 XExtendedToolkit tk
= (XExtendedToolkit
) UnoRuntime
.queryInterface(
80 XExtendedToolkit
.class, toolkit
);
82 util
.utils
.shortWait(Param
.getInt("ShortWait"));
84 DiagThread psDiag
= new DiagThread(xCalcDoc
, msf
);
87 util
.utils
.shortWait(Param
.getInt("ShortWait")*5);
89 Object atw
= tk
.getActiveTopWindow();
91 XWindow xWindow
= (XWindow
) UnoRuntime
.queryInterface(XWindow
.class,
94 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
96 util
.utils
.shortWait(Param
.getInt("ShortWait"));
98 AccessibilityTools
.printAccessibleTree(log
, xRoot
, Param
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
));
99 XAccessibleContext ok_button
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
,
100 AccessibleRole
.PUSH_BUTTON
,
103 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.PARAGRAPH
);
105 log
.println("ImplementationName " + utils
.getImplName(oObj
));
106 log
.println("AccessibleName " + oObj
.getAccessibleName());
107 log
.println("ParentDescription " +
108 oObj
.getAccessibleParent().getAccessibleContext()
109 .getAccessibleDescription());
111 TestEnvironment tEnv
= new TestEnvironment(oObj
);
113 action
= (XAccessibleAction
) UnoRuntime
.queryInterface(
114 XAccessibleAction
.class, ok_button
);
116 XAccessibleText text
= (XAccessibleText
) UnoRuntime
.queryInterface(
117 XAccessibleText
.class, oObj
);
119 XAccessibleEditableText eText
= (XAccessibleEditableText
) UnoRuntime
.queryInterface(
120 XAccessibleEditableText
.class,
123 eText
.setText("LEFT");
125 tEnv
.addObjRelation("XAccessibleText.Text", text
.getText());
127 tEnv
.addObjRelation("Destroy", "AccessibleEditableTextPara_PreviewCell");
129 final XAccessibleEditableText editText
= eText
;
131 tEnv
.addObjRelation("EventProducer",
132 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
133 public void fireEvent() {
134 editText
.setText("LEFT_EVENT");
142 * Closes the dialog using accessible button 'OK' found in
143 * <code>createTestEnvironment()</code>.
145 protected void cleanup(TestParameters Param
, PrintWriter log
) {
146 log
.println(" disposing xCalcDoc ");
149 action
.doAccessibleAction(0);
150 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException ioe
) {
151 log
.println("Couldn't close dialog");
152 } catch (com
.sun
.star
.lang
.DisposedException de
) {
153 log
.println("Dialog already disposed");
156 util
.DesktopTools
.closeDoc(xCalcDoc
);
160 * Opens new writer document.
162 protected void initialize(TestParameters Param
, PrintWriter log
) {
163 msf
= (XMultiServiceFactory
) Param
.getMSF();
166 SOfficeFactory SOF
= SOfficeFactory
.getFactory(msf
);
167 xCalcDoc
= (XComponent
) UnoRuntime
.queryInterface(XComponent
.class,
170 } catch (com
.sun
.star
.uno
.Exception e
) {
171 throw new StatusException("Can't create document", e
);
177 * Thread for opening modal dialog 'Print Settings'.
179 public class DiagThread
extends Thread
{
180 public XComponent xCalcDoc
= null;
181 public XMultiServiceFactory msf
= null;
183 public DiagThread(XComponent xCalcDoc
, XMultiServiceFactory msf
) {
184 this.xCalcDoc
= xCalcDoc
;
189 XModel aModel
= (XModel
) UnoRuntime
.queryInterface(XModel
.class,
192 XController xController
= aModel
.getCurrentController();
194 //Opening HeaderFooterDialog
196 String aSlotID
= ".uno:EditHeaderAndFooter";
197 XDispatchProvider xDispProv
= (XDispatchProvider
) UnoRuntime
.queryInterface(
198 XDispatchProvider
.class,
200 XURLTransformer xParser
= (com
.sun
.star
.util
.XURLTransformer
) UnoRuntime
.queryInterface(
201 XURLTransformer
.class,
203 "com.sun.star.util.URLTransformer"));
205 // Because it's an in/out parameter
206 // we must use an array of URL objects.
207 URL
[] aParseURL
= new URL
[1];
208 aParseURL
[0] = new URL();
209 aParseURL
[0].Complete
= aSlotID
;
210 xParser
.parseStrict(aParseURL
);
212 URL aURL
= aParseURL
[0];
213 XDispatch xDispatcher
= xDispProv
.queryDispatch(aURL
, "", 0);
215 if (xDispatcher
!= null) {
216 xDispatcher
.dispatch(aURL
, null);
218 } catch (com
.sun
.star
.uno
.Exception e
) {
219 log
.println("Couldn't open dialog");