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 com.sun.star.container.NoSuchElementException; 27 import java.io.PrintWriter; 28 29 import lib.StatusException; 30 import lib.TestCase; 31 import lib.TestEnvironment; 32 import lib.TestParameters; 33 import util.SOfficeFactory; 34 35 import com.sun.star.container.XIndexAccess; 36 import com.sun.star.container.XNameContainer; 37 import com.sun.star.drawing.XDrawPage; 38 import com.sun.star.drawing.XDrawPages; 39 import com.sun.star.drawing.XDrawPagesSupplier; 40 import com.sun.star.drawing.XShape; 41 import com.sun.star.form.XForm; 42 import com.sun.star.frame.XController; 43 import com.sun.star.frame.XModel; 44 import com.sun.star.lang.WrappedTargetException; 45 import com.sun.star.lang.XComponent; 46 import com.sun.star.lang.XMultiServiceFactory; 47 import com.sun.star.sheet.XSpreadsheetDocument; 48 import com.sun.star.sheet.XViewPane; 49 import com.sun.star.table.CellRangeAddress; 50 import com.sun.star.uno.AnyConverter; 51 import com.sun.star.uno.Type; 52 import com.sun.star.uno.UnoRuntime; 53 import com.sun.star.uno.XInterface; 54 import util.FormTools; 55 56 /** 57 * Test for object which is represented by service 58 * <code>com.sun.star.sheet.SpreadsheetViewPane</code>. <p> 59 * Object implements the following interfaces : 60 * <ul> 61 * <li> <code>com::sun::star::sheet::XViewPane</code></li> 62 * <li> <code>com::sun::star::sheet::XCellRangeReferrer</code></li> 63 * </ul> 64 * @see com.sun.star.sheet.SpreadsheetViewPane 65 * @see com.sun.star.sheet.XViewPane 66 * @see com.sun.star.sheet.XCellRangeReferrer 67 * @see ifc.sheet._XViewPane 68 * @see ifc.sheet._XCellRangeReferrer 69 */ 70 public class ScViewPaneObj extends TestCase { 71 static private XSpreadsheetDocument xSpreadsheetDoc; 72 static private SOfficeFactory SOF; 73 static private XInterface oObj; 74 75 /** 76 * Creates Spreadsheet document. 77 */ initialize( TestParameters Param, PrintWriter log )78 public void initialize( TestParameters Param, PrintWriter log ) { 79 // get a soffice factory object 80 SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF()); 81 82 try { 83 log.println("creating a spreadsheetdocument"); 84 xSpreadsheetDoc = SOF.createCalcDoc(null); 85 } catch (com.sun.star.uno.Exception e) { 86 e.printStackTrace( log ); 87 throw new StatusException( "Couldn't create document ", e ); 88 } 89 } 90 91 /** 92 * Disposes Spreadsheet document. 93 */ cleanup( TestParameters tParam, PrintWriter log )94 protected void cleanup( TestParameters tParam, PrintWriter log ) { 95 log.println("disposing xSpreadsheetDocument"); 96 XComponent oComp = (XComponent) 97 UnoRuntime.queryInterface(XComponent.class, xSpreadsheetDoc); 98 util.DesktopTools.closeDoc(oComp); 99 } 100 101 /** 102 * Creating a Testenvironment for the interfaces to be tested. 103 * Retieves the current controller of the spreadsheet document using the 104 * interface <code>XModel</code>. The controller contains the collection 105 * of the view panes so retrieves the view pane with index 0 from 106 * the collection. The retrieved view pane is the instance of the service 107 * <code>com.sun.star.sheet.SpreadsheetViewPane</code>. Retrieves the address 108 * of the cell range that consists of the cells which are visible in the pane. 109 * Object relations created : 110 * <ul> 111 * <li> <code>'DATAAREA'</code> for 112 * {@link ifc.sheet._XViewPane}(the retrieved address)</li> 113 * </ul> 114 * @see com.sun.star.frame.XModel 115 */ createTestEnvironment(TestParameters Param, PrintWriter log)116 protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) { 117 XDrawPage oDrawPage; 118 119 XModel xm = (XModel) 120 UnoRuntime.queryInterface(XModel.class, xSpreadsheetDoc); 121 XController xc = xm.getCurrentController(); 122 XIndexAccess xIA = (XIndexAccess) 123 UnoRuntime.queryInterface(XIndexAccess.class, xc); 124 try { 125 oObj = (XInterface) AnyConverter.toObject( 126 new Type(XInterface.class),xIA.getByIndex(0)); 127 } catch (com.sun.star.lang.WrappedTargetException e) { 128 e.printStackTrace(log); 129 throw new StatusException("Couldn't get by index", e); 130 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 131 e.printStackTrace(log); 132 throw new StatusException("Couldn't get by index", e); 133 } catch (com.sun.star.lang.IllegalArgumentException e) { 134 e.printStackTrace(log); 135 throw new StatusException("Couldn't get by index", e); 136 } 137 138 TestEnvironment tEnv = new TestEnvironment(oObj); 139 140 //Relation for XControlAccess 141 tEnv.addObjRelation("DOCUMENT", UnoRuntime.queryInterface(XComponent.class,xSpreadsheetDoc)); 142 tEnv.addObjRelation("XControlAccess.isSheet", Boolean.TRUE); 143 144 XViewPane VP = (XViewPane) 145 UnoRuntime.queryInterface(XViewPane.class, oObj); 146 CellRangeAddress dataArea = VP.getVisibleRange(); 147 tEnv.addObjRelation("DATAAREA", dataArea); 148 149 // XForm for com.sun.star.view.XFormLayerAccess 150 log.println("adding relation for com.sun.star.view.XFormLayerAccess: XForm"); 151 152 XForm myForm = null; 153 String kindOfControl="CommandButton"; 154 XShape aShape = null; 155 try{ 156 log.println("adding contol shape '" + kindOfControl + "'"); 157 XComponent oComp = (XComponent) UnoRuntime.queryInterface(XComponent.class, xSpreadsheetDoc) ; 158 159 aShape = FormTools.createControlShape(oComp, 3000, 4500, 15000, 10000, kindOfControl); 160 161 } catch (Exception e){ 162 e.printStackTrace(log); 163 throw new StatusException("Couldn't create following control shape : '" + 164 kindOfControl + "': ", e); 165 } 166 167 try { 168 log.println( "getting Drawpages" ); 169 XDrawPagesSupplier oDPS = (XDrawPagesSupplier) 170 UnoRuntime.queryInterface(XDrawPagesSupplier.class,xSpreadsheetDoc); 171 XDrawPages oDP = (XDrawPages) oDPS.getDrawPages(); 172 oDP.insertNewByIndex(1); 173 oDP.insertNewByIndex(2); 174 oDrawPage = (XDrawPage) AnyConverter.toObject( 175 new Type(XDrawPage.class),oDP.getByIndex(0)); 176 if (oDrawPage == null) 177 log.println("ERROR: could not get DrawPage: null"); 178 179 oDrawPage.add(aShape); 180 log.println("getting XForm"); 181 XNameContainer xForm = FormTools.getForms(oDrawPage); 182 try { 183 myForm = (XForm) AnyConverter.toObject(new Type(XForm.class),xForm.getByName("Standard")); 184 } catch (WrappedTargetException ex) { 185 log.println("ERROR: could not XFormm 'Standard': " + ex.toString()); 186 } catch (com.sun.star.lang.IllegalArgumentException ex) { 187 log.println("ERROR: could not XFormm 'Standard': " + ex.toString()); 188 } catch (NoSuchElementException ex) { 189 log.println("ERROR: could not XFormm 'Standard': " + ex.toString()); 190 } 191 if (myForm == null) 192 log.println("ERROR: could not get XForm: null"); 193 tEnv.addObjRelation("XFormLayerAccess.XForm", myForm); 194 } catch (com.sun.star.lang.IndexOutOfBoundsException ex) { 195 log.println("ERROR: could not add ObjectRelation 'XFormLayerAccess.XForm': " + ex.toString()); 196 } catch (WrappedTargetException ex) { 197 log.println("ERROR: could not add ObjectRelation 'XFormLayerAccess.XForm': " + ex.toString()); 198 } catch (com.sun.star.lang.IllegalArgumentException ex) { 199 log.println("ERROR: could not add ObjectRelation 'XFormLayerAccess.XForm': " + ex.toString()); 200 } 201 202 return tEnv; 203 } 204 } 205 206