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