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_SubTotalFieldsEnumeration.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
.container
.XEnumerationAccess
;
42 import com
.sun
.star
.container
.XIndexAccess
;
43 import com
.sun
.star
.lang
.XComponent
;
44 import com
.sun
.star
.lang
.XMultiServiceFactory
;
45 import com
.sun
.star
.sheet
.GeneralFunction
;
46 import com
.sun
.star
.sheet
.SubTotalColumn
;
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
.sheet
.XSubTotalCalculatable
;
51 import com
.sun
.star
.sheet
.XSubTotalDescriptor
;
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
;
57 public class ScIndexEnumeration_SubTotalFieldsEnumeration
extends TestCase
{
58 public static XSpreadsheetDocument xSpreadsheetDoc
;
61 * Creates Spreadsheet document.
63 public void initialize( TestParameters Param
, PrintWriter log
) {
64 // creation of the testobject here
65 // first we write what we are intend to do to log file
66 log
.println("creating a test environment");
68 // get a soffice factory object
69 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)Param
.getMSF());
72 log
.println("creating a spreadsheetdocument");
73 xSpreadsheetDoc
= SOF
.createCalcDoc(null);
74 } catch (com
.sun
.star
.uno
.Exception e
) {
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, xSpreadsheetDoc
) ;
87 util
.DesktopTools
.closeDoc(oComp
);
90 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
92 log
.println("getting sheets");
93 XSpreadsheets xSpreadsheets
= (XSpreadsheets
)xSpreadsheetDoc
.getSheets();
95 log
.println("getting a sheet");
96 XSpreadsheet oSheet
= null;
97 XIndexAccess oIndexAccess
= (XIndexAccess
)
98 UnoRuntime
.queryInterface(XIndexAccess
.class, xSpreadsheets
);
100 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
101 new Type(XSpreadsheet
.class),oIndexAccess
.getByIndex(0));
102 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
103 e
.printStackTrace(log
);
104 throw new StatusException( "Couldn't get a spreadsheet", e
);
105 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
106 e
.printStackTrace(log
);
107 throw new StatusException( "Couldn't get a spreadsheet", e
);
108 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
109 e
.printStackTrace(log
);
110 throw new StatusException( "Couldn't get a spreadsheet", e
);
113 XSubTotalCalculatable xSTC
= (XSubTotalCalculatable
)
114 UnoRuntime
.queryInterface(XSubTotalCalculatable
.class, oSheet
);
116 XSubTotalDescriptor xSTD
= xSTC
.createSubTotalDescriptor(true);
118 SubTotalColumn
[] columns
= new SubTotalColumn
[1];
119 SubTotalColumn column
= new SubTotalColumn();
121 column
.Function
= GeneralFunction
.SUM
;
123 xSTD
.addNew(columns
, 1);
125 XIndexAccess oDescIndex
= (XIndexAccess
)
126 UnoRuntime
.queryInterface(XIndexAccess
.class, xSTD
);
128 XInterface oObj
= null;
130 XEnumerationAccess ea
= (XEnumerationAccess
)
131 UnoRuntime
.queryInterface(XEnumerationAccess
.class,oDescIndex
);
133 oObj
= ea
.createEnumeration();
135 log
.println("ImplementationName: "+util
.utils
.getImplName(oObj
));
136 // creating test environment
137 TestEnvironment tEnv
= new TestEnvironment( oObj
);
139 tEnv
.addObjRelation("ENUM",ea
);
143 } // finish method getTestEnvironment