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_TableConditionalEntryEnumeration.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
;
42 import com
.sun
.star
.beans
.PropertyValue
;
43 import com
.sun
.star
.beans
.XPropertySet
;
44 import com
.sun
.star
.container
.XEnumerationAccess
;
45 import com
.sun
.star
.container
.XIndexAccess
;
46 import com
.sun
.star
.lang
.XComponent
;
47 import com
.sun
.star
.lang
.XMultiServiceFactory
;
48 import com
.sun
.star
.sheet
.ConditionOperator
;
49 import com
.sun
.star
.sheet
.XSheetConditionalEntries
;
50 import com
.sun
.star
.sheet
.XSpreadsheet
;
51 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
52 import com
.sun
.star
.sheet
.XSpreadsheets
;
53 import com
.sun
.star
.table
.CellAddress
;
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
;
59 public class ScIndexEnumeration_TableConditionalEntryEnumeration
extends TestCase
{
60 static XSpreadsheetDocument xSpreadsheetDoc
= null;
63 * Creates Spreadsheet document.
65 protected void initialize( TestParameters tParam
, PrintWriter log
) {
66 // get a soffice factory object
67 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF());
70 log
.println( "creating a sheetdocument" );
71 xSpreadsheetDoc
= SOF
.createCalcDoc(null);;
72 } catch (com
.sun
.star
.uno
.Exception e
) {
73 // Some exception occures.FAILED
74 e
.printStackTrace( log
);
75 throw new StatusException( "Couldn't create document", e
);
80 * Disposes Spreadsheet document.
82 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
83 log
.println( " disposing xSheetDoc " );
84 XComponent oComp
= (XComponent
)
85 UnoRuntime
.queryInterface (XComponent
.class, xSpreadsheetDoc
) ;
86 util
.DesktopTools
.closeDoc(oComp
);
89 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
91 XInterface oObj
= null;
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
);
101 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
102 new Type(XSpreadsheet
.class),oIndexAccess
.getByIndex(0));
103 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
104 e
.printStackTrace(log
);
105 throw new StatusException( "Couldn't get a spreadsheet", e
);
106 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
107 e
.printStackTrace(log
);
108 throw new StatusException( "Couldn't get a spreadsheet", e
);
109 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
110 e
.printStackTrace(log
);
111 throw new StatusException( "Couldn't get a spreadsheet", e
);
114 log
.println("filling some cells");
116 oSheet
.getCellByPosition(5, 5).setValue(15);
117 oSheet
.getCellByPosition(1, 4).setValue(10);
118 oSheet
.getCellByPosition(2, 0).setValue(-5.15);
119 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
120 log
.println("Exception occurred while filling cells");
121 e
.printStackTrace(log
);
124 Object CFormat
= null;
125 XPropertySet Props
= null;
128 Props
= (XPropertySet
)
129 UnoRuntime
.queryInterface(XPropertySet
.class, oSheet
);
130 CFormat
= Props
.getPropertyValue("ConditionalFormat");
131 if (utils
.isVoid(CFormat
)) {
132 log
.println("Property 'ConditionalFormat' is void");
134 } catch (com
.sun
.star
.lang
.WrappedTargetException e
){
135 e
.printStackTrace(log
);
136 throw new StatusException("Couldn't create instance", e
);
137 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
){
138 e
.printStackTrace(log
);
139 throw new StatusException("Couldn't create instance", e
);
143 XSheetConditionalEntries xSCE
= (XSheetConditionalEntries
)
144 UnoRuntime
.queryInterface(XSheetConditionalEntries
.class, CFormat
);
145 xSCE
.addNew(Conditions());
146 Props
.setPropertyValue("ConditionalFormat", xSCE
);
148 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
149 e
.printStackTrace(log
);
150 throw new StatusException(
151 "Exception occurred while getting Entry", e
);
152 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
153 e
.printStackTrace(log
);
154 throw new StatusException(
155 "Exception occurred while getting Entry", e
);
156 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
157 e
.printStackTrace(log
);
158 throw new StatusException(
159 "Exception occurred while getting Entry", e
);
160 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
161 e
.printStackTrace(log
);
162 throw new StatusException(
163 "Exception occurred while getting Entry", e
);
166 log
.println("creating a new environment for object");
167 XEnumerationAccess ea
= (XEnumerationAccess
)
168 UnoRuntime
.queryInterface(XEnumerationAccess
.class,oObj
);
170 oObj
= ea
.createEnumeration();
172 log
.println("ImplementationName: "+util
.utils
.getImplName(oObj
));
173 // creating test environment
174 TestEnvironment tEnv
= new TestEnvironment( oObj
);
176 tEnv
.addObjRelation("ENUM",ea
);
179 } // finish method getTestEnvironment
182 * Returns the array of the property values that was filled by condition
185 protected PropertyValue
[] Conditions() {
186 PropertyValue
[] con
= new PropertyValue
[5];
187 CellAddress ca
= new CellAddress();
191 con
[0] = new PropertyValue();
192 con
[0].Name
= "StyleName";
193 con
[0].Value
= "Result2";
194 con
[1] = new PropertyValue();
195 con
[1].Name
= "Formula1";
196 con
[1].Value
= "$Sheet1.$B$5";
197 con
[2] = new PropertyValue();
198 con
[2].Name
= "Formula2";
200 con
[3] = new PropertyValue();
201 con
[3].Name
= "Operator";
202 con
[3].Value
= ConditionOperator
.EQUAL
;
203 con
[4] = new PropertyValue();
204 con
[4].Name
= "SourcePosition";
209 } // finish class ScTableConditionalEntry