1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package mod._sc; 29 30 import java.io.PrintWriter; 31 32 import lib.StatusException; 33 import lib.TestCase; 34 import lib.TestEnvironment; 35 import lib.TestParameters; 36 import util.AccessibilityTools; 37 import util.SOfficeFactory; 38 import util.utils; 39 40 import com.sun.star.accessibility.AccessibleRole; 41 import com.sun.star.accessibility.XAccessible; 42 import com.sun.star.awt.XWindow; 43 import com.sun.star.beans.XPropertySet; 44 import com.sun.star.container.XIndexAccess; 45 import com.sun.star.frame.XModel; 46 import com.sun.star.lang.XComponent; 47 import com.sun.star.lang.XMultiServiceFactory; 48 import com.sun.star.sheet.XSpreadsheet; 49 import com.sun.star.sheet.XSpreadsheetDocument; 50 import com.sun.star.sheet.XSpreadsheets; 51 import com.sun.star.table.XCell; 52 import com.sun.star.table.XColumnRowRange; 53 import com.sun.star.table.XTableColumns; 54 import com.sun.star.uno.AnyConverter; 55 import com.sun.star.uno.Type; 56 import com.sun.star.uno.UnoRuntime; 57 import com.sun.star.uno.XInterface; 58 59 /** 60 * Test for object which is represented by accessible component of 61 * a cell in the spreadsheet. <p> 62 * Object implements the following interfaces : 63 * <ul> 64 * <li> <code>::com::sun::star::accessibility::XAccessibleSelection</code></li> 65 * <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li> 66 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li> 67 * <li> <code>::com::sun::star::accessibility::XAccessibleTable</code></li> 68 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li> 69 * </ul> <p> 70 * 71 * @see com.sun.star.accessibility.XAccessibleSelection 72 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster 73 * @see com.sun.star.accessibility.XAccessibleComponent 74 * @see com.sun.star.accessibility.XAccessibleTable 75 * @see com.sun.star.accessibility.XAccessibleContext 76 * @see ifc.n.star.accessibility._XAccessibleSelection 77 * @see ifc.n.star.accessibility._XAccessibleEventBroadcaster 78 * @see ifc.n.star.accessibility._XAccessibleComponent 79 * @see ifc.n.star.accessibility._XAccessibleTable 80 * @see ifc.n.star.accessibility._XAccessibleContext 81 */ 82 public class ScAccessibleCell extends TestCase { 83 84 static XSpreadsheetDocument xSpreadsheetDoc = null; 85 86 /** 87 * Called to create an instance of <code>TestEnvironment</code> 88 * with an object to test and related objects. 89 * Switchs the document to Print Preview mode. 90 * Obtains accissible object for the page view. 91 * 92 * @param tParam test parameters 93 * @param log writer to log information while testing 94 * 95 * @see TestEnvironment 96 * @see #getTestEnvironment() 97 */ 98 protected TestEnvironment createTestEnvironment( 99 TestParameters Param, PrintWriter log) { 100 101 // get a soffice factory object 102 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory) Param.getMSF()); 103 104 try { 105 log.println("creating a spreadsheetdocument"); 106 xSpreadsheetDoc = SOF.createCalcDoc(null); 107 } catch (com.sun.star.uno.Exception e) { 108 e.printStackTrace( log ); 109 throw new StatusException( "Couldn't create document ", e ); 110 } 111 112 XInterface oObj = null; 113 114 XModel aModel = (XModel) 115 UnoRuntime.queryInterface(XModel.class, xSpreadsheetDoc); 116 117 XWindow xWindow = AccessibilityTools.getCurrentWindow( (XMultiServiceFactory) Param.getMSF(), aModel); 118 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow); 119 120 oObj = AccessibilityTools.getAccessibleObjectForRole 121 (xRoot, AccessibleRole.TABLE_CELL, "B1"); 122 123 log.println("ImplementationName " + utils.getImplName(oObj)); 124 125 TestEnvironment tEnv = new TestEnvironment(oObj); 126 127 // relation for XAccessibleEventBroadcaster 128 XCell xCell = null; 129 final String text = "XAccessibleText"; 130 try { 131 XSpreadsheets oSheets = xSpreadsheetDoc.getSheets() ; 132 XIndexAccess oIndexSheets = (XIndexAccess) 133 UnoRuntime.queryInterface(XIndexAccess.class, oSheets); 134 XSpreadsheet oSheet = null; 135 try { 136 oSheet = (XSpreadsheet) AnyConverter.toObject( 137 new Type(XSpreadsheet.class),oIndexSheets.getByIndex(0)); 138 } catch (com.sun.star.lang.IllegalArgumentException iae) { 139 throw new StatusException("couldn't get sheet",iae); 140 } 141 xCell = oSheet.getCellByPosition(1, 0) ; 142 xCell.setFormula(text); 143 XColumnRowRange oColumnRowRange = (XColumnRowRange) 144 UnoRuntime.queryInterface(XColumnRowRange.class, oSheet); 145 XTableColumns oColumns = (XTableColumns) oColumnRowRange.getColumns(); 146 XIndexAccess oIndexAccess = (XIndexAccess) 147 UnoRuntime.queryInterface(XIndexAccess.class, oColumns); 148 XPropertySet column = (XPropertySet) UnoRuntime.queryInterface( 149 XPropertySet.class,oIndexAccess.getByIndex(1)); 150 column.setPropertyValue("OptimalWidth", new Boolean(true)); 151 } catch(com.sun.star.lang.WrappedTargetException e) { 152 log.println("Exception ceating relation :"); 153 e.printStackTrace(log); 154 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 155 log.println("Exception ceating relation :"); 156 e.printStackTrace(log); 157 } catch(com.sun.star.beans.UnknownPropertyException e) { 158 log.println("Exception ceating relation :"); 159 e.printStackTrace(log); 160 } catch(com.sun.star.beans.PropertyVetoException e) { 161 log.println("Exception ceating relation :"); 162 e.printStackTrace(log); 163 } catch(com.sun.star.lang.IllegalArgumentException e) { 164 log.println("Exception ceating relation :"); 165 e.printStackTrace(log); 166 } 167 168 tEnv.addObjRelation("EditOnly", 169 "This method is only supported if the Cell is in edit mode"); 170 171 final XCell fCell = xCell ; 172 173 tEnv.addObjRelation("EventProducer", 174 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer(){ 175 public void fireEvent() { 176 fCell.setFormula("firing event"); 177 fCell.setFormula(text); 178 } 179 }); 180 181 tEnv.addObjRelation("XAccessibleText.Text", text); 182 183 return tEnv; 184 185 } 186 187 /** 188 * Called while disposing a <code>TestEnvironment</code>. 189 * Disposes calc document. 190 * @param tParam test parameters 191 * @param tEnv the environment to cleanup 192 * @param log writer to log information while testing 193 */ 194 protected void cleanup( TestParameters Param, PrintWriter log) { 195 log.println( " disposing xSheetDoc " ); 196 XComponent oComp = (XComponent) 197 UnoRuntime.queryInterface (XComponent.class, xSpreadsheetDoc) ; 198 util.DesktopTools.closeDoc(oComp); 199 } 200 }