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