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 package mod._sc; 28 29 import com.sun.star.container.XIndexAccess; 30 import com.sun.star.lang.XComponent; 31 import com.sun.star.lang.XMultiServiceFactory; 32 import com.sun.star.sheet.XSheetAnnotation; 33 import com.sun.star.sheet.XSheetAnnotationAnchor; 34 import com.sun.star.sheet.XSheetAnnotationShapeSupplier; 35 import com.sun.star.sheet.XSpreadsheet; 36 import com.sun.star.sheet.XSpreadsheetDocument; 37 import com.sun.star.sheet.XSpreadsheets; 38 import com.sun.star.table.CellAddress; 39 import com.sun.star.table.XCell; 40 import com.sun.star.table.XCellRange; 41 import com.sun.star.text.XSimpleText; 42 import com.sun.star.uno.AnyConverter; 43 import com.sun.star.uno.Type; 44 import com.sun.star.uno.UnoRuntime; 45 import com.sun.star.uno.XInterface; 46 47 import lib.StatusException; 48 import lib.TestCase; 49 import lib.TestEnvironment; 50 import lib.TestParameters; 51 52 import util.SOfficeFactory; 53 import util.utils; 54 55 import java.io.PrintWriter; 56 import util.DefaultDsc; 57 import util.InstCreator; 58 59 60 /** 61 * Test for object which represents some text annotation 62 * anchored to some cell in spreadsheet (implement 63 * <code>com.sun.star.sheet.CellAnnotation</code>).<p> 64 * Object implements the following interfaces : 65 * <ul> 66 * <li> <code>com::sun::star::text::XSimpleText</code></li> 67 * <li> <code>com::sun::star::text::XTextRange</code></li> 68 * <li> <code>com::sun::star::sheet::XSheetAnnotation</code></li> 69 * </ul> 70 * This object test <b> is NOT </b> designed to be run in several 71 * threads concurently. 72 * @see com.sun.star.sheet.CellAnnotation 73 * @see com.sun.star.text.XSimpleText 74 * @see com.sun.star.text.XTextRange 75 * @see com.sun.star.sheet.XSheetAnnotation 76 * @see ifc.text._XSimpleText 77 * @see ifc.text._XTextRange 78 * @see ifc.sheet._XSheetAnnotation 79 */ 80 public class ScAnnotationShapeObj extends TestCase { 81 static XSpreadsheetDocument xSheetDoc = null; 82 83 /** 84 * Creates a spreadsheet document. 85 */ 86 protected void initialize(TestParameters tParam, PrintWriter log) { 87 SOfficeFactory SOF = 88 SOfficeFactory.getFactory((XMultiServiceFactory) tParam 89 .getMSF()); 90 91 try { 92 log.println("creating a Spreadsheet document"); 93 log.println("Loading: "+utils.getFullTestURL( 94 "ScAnnotationShapeObj.sxc")); 95 xSheetDoc = 96 (XSpreadsheetDocument) UnoRuntime.queryInterface(XSpreadsheetDocument.class, 97 SOF.loadDocument(utils.getFullTestURL( 98 "ScAnnotationShapeObj.sxc"))); 99 } catch (com.sun.star.uno.Exception e) { 100 // Some exception occures.FAILED 101 e.printStackTrace(log); 102 throw new StatusException("Couldn't create document", e); 103 } 104 } 105 106 /** 107 * Disposes a spreadsheet document. 108 */ 109 protected void cleanup(TestParameters tParam, PrintWriter log) { 110 log.println(" disposing xSheetDoc "); 111 112 XComponent oComp = 113 (XComponent) UnoRuntime.queryInterface(XComponent.class, 114 xSheetDoc); 115 util.DesktopTools.closeDoc(oComp); 116 } 117 118 /** 119 * Creating a Testenvironment for the interfaces to be tested. 120 * Retrieves a collection of spreadsheets from a document, 121 * and takes one them. Then a single cell is retrieved, and 122 * using its <code>com.sun.star.sheet.XSheetAnnotationAnchor</code> 123 * interface an annotation is got. 124 * Object relations created : 125 * <ul> 126 * <li> <code>'CELLPOS'</code> for 127 * {@link ifc.sheet._XSheetAnnotation} (of <code> 128 * com.sun.star.table.CellAddress</code> type) which 129 * contains the annotation cell address.</li> 130 * </ul> 131 */ 132 public synchronized TestEnvironment createTestEnvironment( 133 TestParameters Param, PrintWriter log) throws StatusException { 134 XInterface oObj = null; 135 136 // creation of testobject here 137 // first we write what we are intend to do to log file 138 log.println("Creating a test environment"); 139 140 CellAddress cellPos = new CellAddress((short) 0, 1, 2); 141 142 log.println("Getting test object "); 143 144 XSpreadsheetDocument xArea = 145 (XSpreadsheetDocument) UnoRuntime.queryInterface(XSpreadsheetDocument.class, 146 xSheetDoc); 147 XSpreadsheets oSheets = (XSpreadsheets) xArea.getSheets(); 148 149 XIndexAccess XAccess = 150 (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, 151 oSheets); 152 XCell oCell = null; 153 154 try { 155 XSpreadsheet oSheet = 156 (XSpreadsheet) AnyConverter.toObject(new Type( 157 XSpreadsheet.class), 158 XAccess.getByIndex(cellPos.Sheet)); 159 XCellRange oCRange = 160 (XCellRange) UnoRuntime.queryInterface(XCellRange.class, 161 oSheet); 162 oCell = 163 oCRange.getCellByPosition(cellPos.Column, cellPos.Row); 164 } catch (com.sun.star.lang.WrappedTargetException e) { 165 e.printStackTrace(log); 166 throw new StatusException("Error getting test object from spreadsheet document", 167 e); 168 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 169 e.printStackTrace(log); 170 throw new StatusException("Error getting test object from spreadsheet document", 171 e); 172 } catch (com.sun.star.lang.IllegalArgumentException e) { 173 e.printStackTrace(log); 174 throw new StatusException("Error getting test object from spreadsheet document", 175 e); 176 } 177 178 XSheetAnnotationAnchor oAnnoA = 179 (XSheetAnnotationAnchor) UnoRuntime.queryInterface(XSheetAnnotationAnchor.class, 180 oCell); 181 XSheetAnnotation oAnno = oAnnoA.getAnnotation(); 182 183 XSimpleText xAnnoText = 184 (XSimpleText) UnoRuntime.queryInterface(XSimpleText.class, 185 oAnno); 186 xAnnoText.setString("ScAnnotationShapeObj"); 187 188 XSheetAnnotationShapeSupplier xSheetAnnotationShapeSupplier = 189 (XSheetAnnotationShapeSupplier) UnoRuntime.queryInterface(XSheetAnnotationShapeSupplier.class, 190 oAnno); 191 192 oObj = xSheetAnnotationShapeSupplier.getAnnotationShape(); 193 194 log.println("ImplementationName: " 195 + util.utils.getImplName(oObj)); 196 197 TestEnvironment tEnv = new TestEnvironment(oObj); 198 199 //adding ObjRelation for RotationDescriptor 200 tEnv.addObjRelation("NoShear", Boolean.TRUE); 201 202 //adding ObjRelation for XText 203 DefaultDsc tDsc = new DefaultDsc("com.sun.star.text.XTextContent", 204 "com.sun.star.text.TextField.DateTime"); 205 206 log.println( "adding InstCreator object" ); 207 tEnv.addObjRelation( 208 "XTEXTINFO", new InstCreator( xSheetDoc, tDsc ) ); 209 210 return tEnv; 211 } 212 } 213 // finish class ScAnnotationShapeObj 214