1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package mod._sc; 25 26 import java.io.PrintWriter; 27 28 import lib.StatusException; 29 import lib.TestCase; 30 import lib.TestEnvironment; 31 import lib.TestParameters; 32 import util.SOfficeFactory; 33 import util.utils; 34 35 import com.sun.star.beans.PropertyValue; 36 import com.sun.star.beans.XPropertySet; 37 import com.sun.star.container.XEnumerationAccess; 38 import com.sun.star.container.XIndexAccess; 39 import com.sun.star.lang.XComponent; 40 import com.sun.star.lang.XMultiServiceFactory; 41 import com.sun.star.sheet.ConditionOperator; 42 import com.sun.star.sheet.XSheetConditionalEntries; 43 import com.sun.star.sheet.XSpreadsheet; 44 import com.sun.star.sheet.XSpreadsheetDocument; 45 import com.sun.star.sheet.XSpreadsheets; 46 import com.sun.star.table.CellAddress; 47 import com.sun.star.uno.AnyConverter; 48 import com.sun.star.uno.Type; 49 import com.sun.star.uno.UnoRuntime; 50 import com.sun.star.uno.XInterface; 51 52 public class ScIndexEnumeration_TableConditionalEntryEnumeration extends TestCase { 53 static XSpreadsheetDocument xSpreadsheetDoc = null; 54 55 /** 56 * Creates Spreadsheet document. 57 */ 58 protected void initialize( TestParameters tParam, PrintWriter log ) { 59 // get a soffice factory object 60 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF()); 61 62 try { 63 log.println( "creating a sheetdocument" ); 64 xSpreadsheetDoc = SOF.createCalcDoc(null); 65 } catch (com.sun.star.uno.Exception e) { 66 // Some exception occures.FAILED 67 e.printStackTrace( log ); 68 throw new StatusException( "Couldn't create document", e ); 69 } 70 } 71 72 /** 73 * Disposes Spreadsheet document. 74 */ 75 protected void cleanup( TestParameters tParam, PrintWriter log ) { 76 log.println( " disposing xSheetDoc " ); 77 XComponent oComp = (XComponent) 78 UnoRuntime.queryInterface (XComponent.class, xSpreadsheetDoc) ; 79 util.DesktopTools.closeDoc(oComp); 80 } 81 82 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) { 83 84 XInterface oObj = null; 85 log.println("getting sheets"); 86 XSpreadsheets xSpreadsheets = (XSpreadsheets)xSpreadsheetDoc.getSheets(); 87 88 log.println("getting a sheet"); 89 XSpreadsheet oSheet = null; 90 XIndexAccess oIndexAccess = (XIndexAccess) 91 UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets); 92 93 try { 94 oSheet = (XSpreadsheet) AnyConverter.toObject( 95 new Type(XSpreadsheet.class),oIndexAccess.getByIndex(0)); 96 } catch (com.sun.star.lang.WrappedTargetException e) { 97 e.printStackTrace(log); 98 throw new StatusException( "Couldn't get a spreadsheet", e); 99 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 100 e.printStackTrace(log); 101 throw new StatusException( "Couldn't get a spreadsheet", e); 102 } catch (com.sun.star.lang.IllegalArgumentException e) { 103 e.printStackTrace(log); 104 throw new StatusException( "Couldn't get a spreadsheet", e); 105 } 106 107 log.println("filling some cells"); 108 try { 109 oSheet.getCellByPosition(5, 5).setValue(15); 110 oSheet.getCellByPosition(1, 4).setValue(10); 111 oSheet.getCellByPosition(2, 0).setValue(-5.15); 112 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 113 log.println("Exception occurred while filling cells"); 114 e.printStackTrace(log); 115 } 116 117 Object CFormat = null; 118 XPropertySet Props = null; 119 120 try { 121 Props = (XPropertySet) 122 UnoRuntime.queryInterface(XPropertySet.class, oSheet); 123 CFormat = Props.getPropertyValue("ConditionalFormat"); 124 if (utils.isVoid(CFormat)) { 125 log.println("Property 'ConditionalFormat' is void"); 126 } 127 } catch (com.sun.star.lang.WrappedTargetException e){ 128 e.printStackTrace(log); 129 throw new StatusException("Couldn't create instance", e); 130 } catch (com.sun.star.beans.UnknownPropertyException e){ 131 e.printStackTrace(log); 132 throw new StatusException("Couldn't create instance", e); 133 } 134 135 try { 136 XSheetConditionalEntries xSCE = (XSheetConditionalEntries) 137 UnoRuntime.queryInterface(XSheetConditionalEntries.class, CFormat); 138 xSCE.addNew(Conditions()); 139 Props.setPropertyValue("ConditionalFormat", xSCE); 140 oObj = xSCE; 141 } catch (com.sun.star.lang.WrappedTargetException e) { 142 e.printStackTrace(log); 143 throw new StatusException( 144 "Exception occurred while getting Entry", e); 145 } catch (com.sun.star.lang.IllegalArgumentException e) { 146 e.printStackTrace(log); 147 throw new StatusException( 148 "Exception occurred while getting Entry", e); 149 } catch (com.sun.star.beans.PropertyVetoException e) { 150 e.printStackTrace(log); 151 throw new StatusException( 152 "Exception occurred while getting Entry", e); 153 } catch (com.sun.star.beans.UnknownPropertyException e) { 154 e.printStackTrace(log); 155 throw new StatusException( 156 "Exception occurred while getting Entry", e); 157 } 158 159 log.println("creating a new environment for object"); 160 XEnumerationAccess ea = (XEnumerationAccess) 161 UnoRuntime.queryInterface(XEnumerationAccess.class,oObj); 162 163 oObj = ea.createEnumeration(); 164 165 log.println("ImplementationName: "+util.utils.getImplName(oObj)); 166 // creating test environment 167 TestEnvironment tEnv = new TestEnvironment( oObj ); 168 169 tEnv.addObjRelation("ENUM",ea); 170 171 return tEnv; 172 } // finish method getTestEnvironment 173 174 /** 175 * Returns the array of the property values that was filled by condition 176 * values. 177 */ 178 protected PropertyValue[] Conditions() { 179 PropertyValue[] con = new PropertyValue[5]; 180 CellAddress ca = new CellAddress(); 181 ca.Column = 1; 182 ca.Row = 5; 183 ca.Sheet = 0; 184 con[0] = new PropertyValue(); 185 con[0].Name = "StyleName"; 186 con[0].Value = "Result2"; 187 con[1] = new PropertyValue(); 188 con[1].Name = "Formula1"; 189 con[1].Value = "$Sheet1.$B$5"; 190 con[2] = new PropertyValue(); 191 con[2].Name = "Formula2"; 192 con[2].Value = ""; 193 con[3] = new PropertyValue(); 194 con[3].Name = "Operator"; 195 con[3].Value = ConditionOperator.EQUAL; 196 con[4] = new PropertyValue(); 197 con[4].Name = "SourcePosition"; 198 con[4].Value = ca; 199 return con; 200 } 201 202 } // finish class ScTableConditionalEntry 203 204