merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sc / AccessibleEditableTextPara_PreviewCell.java
blob8f4328af68cc72870335d5557bb627f3c2086472
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AccessibleEditableTextPara_PreviewCell.java,v $
10 * $Revision: 1.7 $
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 ************************************************************************/
31 package mod._sc;
33 import java.io.PrintWriter;
35 import lib.Status;
36 import lib.StatusException;
37 import lib.TestCase;
38 import lib.TestEnvironment;
39 import lib.TestParameters;
40 import util.AccessibilityTools;
41 import util.SOfficeFactory;
42 import util.utils;
44 import com.sun.star.accessibility.AccessibleRole;
45 import com.sun.star.accessibility.XAccessible;
46 import com.sun.star.accessibility.XAccessibleContext;
47 import com.sun.star.awt.XWindow;
48 import com.sun.star.container.XIndexAccess;
49 import com.sun.star.frame.XController;
50 import com.sun.star.frame.XDispatch;
51 import com.sun.star.frame.XDispatchProvider;
52 import com.sun.star.frame.XModel;
53 import com.sun.star.lang.XComponent;
54 import com.sun.star.lang.XMultiServiceFactory;
55 import com.sun.star.sheet.XSpreadsheet;
56 import com.sun.star.sheet.XSpreadsheetDocument;
57 import com.sun.star.sheet.XSpreadsheets;
58 import com.sun.star.table.XCell;
59 import com.sun.star.uno.AnyConverter;
60 import com.sun.star.uno.Type;
61 import com.sun.star.uno.UnoRuntime;
62 import com.sun.star.util.URL;
63 import com.sun.star.util.XURLTransformer;
66 public class AccessibleEditableTextPara_PreviewCell extends TestCase {
67 static XSpreadsheetDocument xSheetDoc = null;
69 /**
70 * Creates a spreadsheet document.
72 protected void initialize( TestParameters tParam, PrintWriter log ) {
73 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory) tParam.getMSF() );
74 try {
75 log.println( "creating a Spreadsheet document" );
76 xSheetDoc = SOF.createCalcDoc(null);
77 } catch ( com.sun.star.uno.Exception e ) {
78 // Some exception occures.FAILED
79 e.printStackTrace( log );
80 throw new StatusException( "Couldn't create document", e );
84 /**
85 * Disposes a spreadsheet document.
87 protected void cleanup( TestParameters tParam, PrintWriter log ) {
88 log.println( " disposing xSheetDoc " );
89 XComponent oComp = (XComponent)UnoRuntime.queryInterface
90 (XComponent.class, xSheetDoc);
91 util.DesktopTools.closeDoc(oComp);
95 /**
96 * Creating a Testenvironment for the interfaces to be tested.
97 * Obtains the accessible object for a one of cell in preview mode.
99 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
101 XAccessibleContext oObj = null;
102 XCell xCell = null;
104 try {
105 log.println("Getting spreadsheet") ;
106 XSpreadsheets oSheets = xSheetDoc.getSheets() ;
107 XIndexAccess oIndexSheets = (XIndexAccess)
108 UnoRuntime.queryInterface(XIndexAccess.class, oSheets);
109 XSpreadsheet oSheet = (XSpreadsheet) AnyConverter.toObject(
110 new Type(XSpreadsheet.class),oIndexSheets.getByIndex(0));
112 log.println("Getting a cell from sheet") ;
113 xCell = oSheet.getCellByPosition(0, 0);
114 } catch (com.sun.star.lang.WrappedTargetException e) {
115 e.printStackTrace(log);
116 throw new StatusException(
117 "Error getting cell object from spreadsheet document", e);
118 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
119 e.printStackTrace(log);
120 throw new StatusException(
121 "Error getting cell object from spreadsheet document", e);
122 } catch (com.sun.star.lang.IllegalArgumentException e) {
123 e.printStackTrace(log);
124 throw new StatusException(
125 "Error getting cell object from spreadsheet document", e);
128 xCell.setFormula("Value");
130 XModel xModel = (XModel)
131 UnoRuntime.queryInterface(XModel.class, xSheetDoc);
133 XController xController = xModel.getCurrentController();
135 //switch to 'Print Preview' mode
136 try {
137 XDispatchProvider xDispProv = (XDispatchProvider)
138 UnoRuntime.queryInterface(XDispatchProvider.class, xController);
139 XURLTransformer xParser = (com.sun.star.util.XURLTransformer)
140 UnoRuntime.queryInterface(XURLTransformer.class,
141 ( (XMultiServiceFactory) Param.getMSF()).createInstance("com.sun.star.util.URLTransformer"));
142 URL[] aParseURL = new URL[1];
143 aParseURL[0] = new URL();
144 aParseURL[0].Complete = ".uno:PrintPreview";
145 xParser.parseStrict(aParseURL);
146 URL aURL = aParseURL[0];
147 XDispatch xDispatcher = xDispProv.queryDispatch(aURL, "", 0);
148 if(xDispatcher != null)
149 xDispatcher.dispatch( aURL, null );
150 } catch (com.sun.star.uno.Exception e) {
151 log.println("Couldn't change mode");
152 throw new StatusException(Status.failed("Couldn't change mode"));
155 shortWait();
158 XWindow xWindow = AccessibilityTools.getCurrentWindow( (XMultiServiceFactory) Param.getMSF(), xModel);
159 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
160 //AccessibilityTools.printAccessibleTree(log,xRoot);
161 AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.TABLE_CELL,true);
163 xRoot = AccessibilityTools.SearchedAccessible;
165 //AccessibilityTools.printAccessibleTree(log,xRoot);
167 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot,AccessibleRole.PARAGRAPH);
169 log.println("ImplementationName " + utils.getImplName(oObj));
170 log.println("AccessibleName " + oObj.getAccessibleName());
171 log.println("Parent " + utils.getImplName(oObj.getAccessibleParent()));
173 TestEnvironment tEnv = new TestEnvironment( oObj );
175 tEnv.addObjRelation("EditOnly", "AccessibleEditableTextPara_PreviewCell");
176 tEnv.addObjRelation("Destroy", "AccessibleEditableTextPara_PreviewCell");
178 final XCell cell_to_change = xCell;
179 tEnv.addObjRelation("EventProducer",
180 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer(){
181 public void fireEvent() {
182 cell_to_change.setFormula("NewString");
186 return tEnv;
189 protected void shortWait() {
190 try {
191 Thread.sleep(1000) ;
192 } catch (InterruptedException e) {
193 System.out.println("While waiting :" + e);