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.SOfficeFactory; 37 38 import com.sun.star.awt.Rectangle; 39 import com.sun.star.container.XEnumerationAccess; 40 import com.sun.star.container.XIndexAccess; 41 import com.sun.star.lang.XComponent; 42 import com.sun.star.lang.XMultiServiceFactory; 43 import com.sun.star.sheet.XCellRangeAddressable; 44 import com.sun.star.sheet.XSpreadsheet; 45 import com.sun.star.sheet.XSpreadsheetDocument; 46 import com.sun.star.sheet.XSpreadsheets; 47 import com.sun.star.table.CellRangeAddress; 48 import com.sun.star.table.XCell; 49 import com.sun.star.table.XCellRange; 50 import com.sun.star.table.XTableCharts; 51 import com.sun.star.table.XTableChartsSupplier; 52 import com.sun.star.uno.AnyConverter; 53 import com.sun.star.uno.Type; 54 import com.sun.star.uno.UnoRuntime; 55 import com.sun.star.uno.XInterface; 56 57 public class ScIndexEnumeration_TableChartsEnumeration extends TestCase { 58 static XSpreadsheetDocument xSheetDoc = null; 59 60 /** 61 * Creates Spreadsheet document. 62 */ 63 protected void initialize( TestParameters tParam, PrintWriter log ) { 64 // get a soffice factory object 65 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF()); 66 67 try { 68 log.println( "creating a sheetdocument" ); 69 xSheetDoc = SOF.createCalcDoc(null);; 70 } catch (com.sun.star.uno.Exception e) { 71 // Some exception occures.FAILED 72 e.printStackTrace( log ); 73 throw new StatusException( "Couldn't create document", e ); 74 } 75 } 76 77 /** 78 * Disposes Spreadsheet document. 79 */ 80 protected void cleanup( TestParameters tParam, PrintWriter log ) { 81 log.println( " disposing xSheetDoc " ); 82 XComponent oComp = (XComponent) 83 UnoRuntime.queryInterface(XComponent.class, xSheetDoc); 84 util.DesktopTools.closeDoc(oComp); 85 } 86 87 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) { 88 89 XSpreadsheet oSheet=null; 90 91 try { 92 log.println("Getting spreadsheet") ; 93 XSpreadsheets oSheets = xSheetDoc.getSheets() ; 94 XIndexAccess oIndexSheets = (XIndexAccess) 95 UnoRuntime.queryInterface(XIndexAccess.class, oSheets); 96 oSheet = (XSpreadsheet) AnyConverter.toObject( 97 new Type(XSpreadsheet.class),oIndexSheets.getByIndex(0)); 98 } catch (com.sun.star.lang.WrappedTargetException e) { 99 log.println("Couldn't get Sheet "); 100 e.printStackTrace(log); 101 throw new StatusException("Couldn't get sheet", e); 102 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 103 log.println("Couldn't get Sheet "); 104 e.printStackTrace(log); 105 throw new StatusException("Couldn't get sheet", e); 106 } catch (com.sun.star.lang.IllegalArgumentException e) { 107 log.println("Couldn't get Sheet "); 108 e.printStackTrace(log); 109 throw new StatusException("Couldn't get sheet", e); 110 } 111 112 log.println("Creating the Header") ; 113 114 insertIntoCell(1,0,"JAN",oSheet,""); 115 insertIntoCell(2,0,"FEB",oSheet,""); 116 insertIntoCell(3,0,"MAR",oSheet,""); 117 insertIntoCell(4,0,"APR",oSheet,""); 118 insertIntoCell(5,0,"MAI",oSheet,""); 119 insertIntoCell(6,0,"JUN",oSheet,""); 120 insertIntoCell(7,0,"JUL",oSheet,""); 121 insertIntoCell(8,0,"AUG",oSheet,""); 122 insertIntoCell(9,0,"SEP",oSheet,""); 123 insertIntoCell(10,0,"OCT",oSheet,""); 124 insertIntoCell(11,0,"NOV",oSheet,""); 125 insertIntoCell(12,0,"DEC",oSheet,""); 126 insertIntoCell(13,0,"SUM",oSheet,""); 127 128 log.println("Fill the lines"); 129 130 insertIntoCell(0,1,"Smith",oSheet,""); 131 insertIntoCell(1,1,"42",oSheet,"V"); 132 insertIntoCell(2,1,"58.9",oSheet,"V"); 133 insertIntoCell(3,1,"-66.5",oSheet,"V"); 134 insertIntoCell(4,1,"43.4",oSheet,"V"); 135 insertIntoCell(5,1,"44.5",oSheet,"V"); 136 insertIntoCell(6,1,"45.3",oSheet,"V"); 137 insertIntoCell(7,1,"-67.3",oSheet,"V"); 138 insertIntoCell(8,1,"30.5",oSheet,"V"); 139 insertIntoCell(9,1,"23.2",oSheet,"V"); 140 insertIntoCell(10,1,"-97.3",oSheet,"V"); 141 insertIntoCell(11,1,"22.4",oSheet,"V"); 142 insertIntoCell(12,1,"23.5",oSheet,"V"); 143 insertIntoCell(13,1,"=SUM(B2:M2)",oSheet,""); 144 145 insertIntoCell(0,2,"Jones",oSheet,""); 146 insertIntoCell(1,2,"21",oSheet,"V"); 147 insertIntoCell(2,2,"40.9",oSheet,"V"); 148 insertIntoCell(3,2,"-57.5",oSheet,"V"); 149 insertIntoCell(4,2,"-23.4",oSheet,"V"); 150 insertIntoCell(5,2,"34.5",oSheet,"V"); 151 insertIntoCell(6,2,"59.3",oSheet,"V"); 152 insertIntoCell(7,2,"27.3",oSheet,"V"); 153 insertIntoCell(8,2,"-38.5",oSheet,"V"); 154 insertIntoCell(9,2,"43.2",oSheet,"V"); 155 insertIntoCell(10,2,"57.3",oSheet,"V"); 156 insertIntoCell(11,2,"25.4",oSheet,"V"); 157 insertIntoCell(12,2,"28.5",oSheet,"V"); 158 insertIntoCell(13,2,"=SUM(B3:M3)",oSheet,""); 159 160 insertIntoCell(0,3,"Brown",oSheet,""); 161 insertIntoCell(1,3,"31.45",oSheet,"V"); 162 insertIntoCell(2,3,"-20.9",oSheet,"V"); 163 insertIntoCell(3,3,"-117.5",oSheet,"V"); 164 insertIntoCell(4,3,"23.4",oSheet,"V"); 165 insertIntoCell(5,3,"-114.5",oSheet,"V"); 166 insertIntoCell(6,3,"115.3",oSheet,"V"); 167 insertIntoCell(7,3,"-171.3",oSheet,"V"); 168 insertIntoCell(8,3,"89.5",oSheet,"V"); 169 insertIntoCell(9,3,"41.2",oSheet,"V"); 170 insertIntoCell(10,3,"71.3",oSheet,"V"); 171 insertIntoCell(11,3,"25.4",oSheet,"V"); 172 insertIntoCell(12,3,"38.5",oSheet,"V"); 173 insertIntoCell(13,3,"=SUM(A4:L4)",oSheet,""); 174 175 // insert a chart 176 Rectangle oRect = new Rectangle(500, 3000, 25000, 11000); 177 178 XCellRange oRange = (XCellRange) 179 UnoRuntime.queryInterface(XCellRange.class, oSheet); 180 XCellRange myRange = oRange.getCellRangeByName("A1:N4"); 181 XCellRangeAddressable oRangeAddr = (XCellRangeAddressable) 182 UnoRuntime.queryInterface(XCellRangeAddressable.class, myRange); 183 CellRangeAddress myAddr = oRangeAddr.getRangeAddress(); 184 185 CellRangeAddress[] oAddr = new CellRangeAddress[1]; 186 oAddr[0] = myAddr; 187 XTableChartsSupplier oSupp = (XTableChartsSupplier) 188 UnoRuntime.queryInterface(XTableChartsSupplier.class, oSheet); 189 190 191 log.println("Insert Chart"); 192 XTableCharts oCharts = oSupp.getCharts(); 193 oCharts.addNewByName("ScChartObj", oRect, oAddr, true, true); 194 195 log.println("creating a new environment for object"); 196 XEnumerationAccess ea = (XEnumerationAccess) 197 UnoRuntime.queryInterface(XEnumerationAccess.class,oCharts); 198 199 XInterface oObj = ea.createEnumeration(); 200 201 TestEnvironment tEnv = new TestEnvironment(oObj); 202 203 // tEnv.addObjRelation("RECT", oRect); 204 // tEnv.addObjRelation("ADDR", oAddr); 205 206 return tEnv; 207 } 208 209 /** 210 * Inserts a value or a formula in the cell of the spreasheet. 211 * @param CellX is the column index of the cell 212 * @param CellY is the row index of the cell 213 * @param theValue string representation of the value 214 * @param TT1 specify the spreadsheet, the interface 215 * <code>com.sun.star.sheet.XSpreadsheet</code> 216 * @param flag if it's equal to <code>'V'</code> then the method inserts 217 * a double-value in the cell else it inserts a formula in the cell 218 */ 219 public static void insertIntoCell( 220 int CellX, int CellY, String theValue, XSpreadsheet TT1, String flag) { 221 222 XCell oCell = null; 223 224 try { 225 oCell = TT1.getCellByPosition(CellX, CellY); 226 } catch (com.sun.star.lang.IndexOutOfBoundsException ex) { 227 System.out.println("Could not get Cell"); 228 } 229 230 if (flag.equals("V")) { 231 oCell.setValue(new Float(theValue).floatValue()); 232 } else { 233 oCell.setFormula(theValue); 234 } 235 236 } // end of insertIntoCell 237 } 238 239