2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import com
.sun
.star
.container
.NoSuchElementException
;
22 import java
.io
.PrintWriter
;
24 import lib
.StatusException
;
26 import lib
.TestEnvironment
;
27 import lib
.TestParameters
;
28 import util
.SOfficeFactory
;
30 import com
.sun
.star
.container
.XIndexAccess
;
31 import com
.sun
.star
.container
.XNameContainer
;
32 import com
.sun
.star
.drawing
.XDrawPage
;
33 import com
.sun
.star
.drawing
.XDrawPages
;
34 import com
.sun
.star
.drawing
.XDrawPagesSupplier
;
35 import com
.sun
.star
.drawing
.XShape
;
36 import com
.sun
.star
.form
.XForm
;
37 import com
.sun
.star
.frame
.XController
;
38 import com
.sun
.star
.frame
.XModel
;
39 import com
.sun
.star
.lang
.WrappedTargetException
;
40 import com
.sun
.star
.lang
.XComponent
;
41 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
42 import com
.sun
.star
.sheet
.XViewPane
;
43 import com
.sun
.star
.table
.CellRangeAddress
;
44 import com
.sun
.star
.uno
.AnyConverter
;
45 import com
.sun
.star
.uno
.Type
;
46 import com
.sun
.star
.uno
.UnoRuntime
;
47 import com
.sun
.star
.uno
.XInterface
;
48 import util
.FormTools
;
51 * Test for object which is represented by service
52 * <code>com.sun.star.sheet.SpreadsheetViewPane</code>. <p>
53 * Object implements the following interfaces :
55 * <li> <code>com::sun::star::sheet::XViewPane</code></li>
56 * <li> <code>com::sun::star::sheet::XCellRangeReferrer</code></li>
58 * @see com.sun.star.sheet.SpreadsheetViewPane
59 * @see com.sun.star.sheet.XViewPane
60 * @see com.sun.star.sheet.XCellRangeReferrer
61 * @see ifc.sheet._XViewPane
62 * @see ifc.sheet._XCellRangeReferrer
64 public class ScViewPaneObj
extends TestCase
{
65 static private XSpreadsheetDocument xSpreadsheetDoc
;
66 static private SOfficeFactory SOF
;
67 static private XInterface oObj
;
70 * Creates Spreadsheet document.
73 public void initialize( TestParameters Param
, PrintWriter log
) {
74 // get a soffice factory object
75 SOF
= SOfficeFactory
.getFactory( Param
.getMSF());
78 log
.println("creating a spreadsheetdocument");
79 xSpreadsheetDoc
= SOF
.createCalcDoc(null);
80 } catch (com
.sun
.star
.uno
.Exception e
) {
81 e
.printStackTrace( log
);
82 throw new StatusException( "Couldn't create document ", e
);
87 * Disposes Spreadsheet document.
90 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
91 log
.println("disposing xSpreadsheetDocument");
92 XComponent oComp
= UnoRuntime
.queryInterface(XComponent
.class, xSpreadsheetDoc
);
93 util
.DesktopTools
.closeDoc(oComp
);
97 * Creating a Testenvironment for the interfaces to be tested.
98 * Retieves the current controller of the spreadsheet document using the
99 * interface <code>XModel</code>. The controller contains the collection
100 * of the view panes so retrieves the view pane with index 0 from
101 * the collection. The retrieved view pane is the instance of the service
102 * <code>com.sun.star.sheet.SpreadsheetViewPane</code>. Retrieves the address
103 * of the cell range that consists of the cells which are visible in the pane.
104 * Object relations created :
106 * <li> <code>'DATAAREA'</code> for
107 * {@link ifc.sheet._XViewPane}(the retrieved address)</li>
109 * @see com.sun.star.frame.XModel
112 protected TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
115 XModel xm
= UnoRuntime
.queryInterface(XModel
.class, xSpreadsheetDoc
);
116 XController xc
= xm
.getCurrentController();
117 XIndexAccess xIA
= UnoRuntime
.queryInterface(XIndexAccess
.class, xc
);
119 oObj
= (XInterface
) AnyConverter
.toObject(
120 new Type(XInterface
.class),xIA
.getByIndex(0));
121 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
122 e
.printStackTrace(log
);
123 throw new StatusException("Couldn't get by index", e
);
124 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
125 e
.printStackTrace(log
);
126 throw new StatusException("Couldn't get by index", e
);
127 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
128 e
.printStackTrace(log
);
129 throw new StatusException("Couldn't get by index", e
);
132 TestEnvironment tEnv
= new TestEnvironment(oObj
);
134 //Relation for XControlAccess
135 tEnv
.addObjRelation("DOCUMENT", UnoRuntime
.queryInterface(XComponent
.class,xSpreadsheetDoc
));
136 tEnv
.addObjRelation("XControlAccess.isSheet", Boolean
.TRUE
);
138 XViewPane VP
= UnoRuntime
.queryInterface(XViewPane
.class, oObj
);
139 CellRangeAddress dataArea
= VP
.getVisibleRange();
140 tEnv
.addObjRelation("DATAAREA", dataArea
);
142 // XForm for com.sun.star.view.XFormLayerAccess
143 log
.println("adding relation for com.sun.star.view.XFormLayerAccess: XForm");
146 String kindOfControl
="CommandButton";
147 XShape aShape
= null;
149 log
.println("adding contol shape '" + kindOfControl
+ "'");
150 XComponent oComp
= UnoRuntime
.queryInterface(XComponent
.class, xSpreadsheetDoc
) ;
152 aShape
= FormTools
.createControlShape(oComp
, 3000, 4500, 15000, 10000, kindOfControl
);
154 } catch (Exception e
){
155 e
.printStackTrace(log
);
156 throw new StatusException("Couldn't create following control shape : '" +
157 kindOfControl
+ "': ", e
);
161 log
.println( "getting Drawpages" );
162 XDrawPagesSupplier oDPS
= UnoRuntime
.queryInterface(XDrawPagesSupplier
.class,xSpreadsheetDoc
);
163 XDrawPages oDP
= oDPS
.getDrawPages();
164 oDP
.insertNewByIndex(1);
165 oDP
.insertNewByIndex(2);
166 oDrawPage
= (XDrawPage
) AnyConverter
.toObject(
167 new Type(XDrawPage
.class),oDP
.getByIndex(0));
168 if (oDrawPage
== null)
169 log
.println("ERROR: could not get DrawPage: null");
171 oDrawPage
.add(aShape
);
172 log
.println("getting XForm");
173 XNameContainer xForm
= FormTools
.getForms(oDrawPage
);
175 myForm
= (XForm
) AnyConverter
.toObject(new Type(XForm
.class),xForm
.getByName("Standard"));
176 } catch (WrappedTargetException ex
) {
177 log
.println("ERROR: could not XFormm 'Standard': " + ex
.toString());
178 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
179 log
.println("ERROR: could not XFormm 'Standard': " + ex
.toString());
180 } catch (NoSuchElementException ex
) {
181 log
.println("ERROR: could not XFormm 'Standard': " + ex
.toString());
184 log
.println("ERROR: could not get XForm: null");
185 tEnv
.addObjRelation("XFormLayerAccess.XForm", myForm
);
186 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException ex
) {
187 log
.println("ERROR: could not add ObjectRelation 'XFormLayerAccess.XForm': " + ex
.toString());
188 } catch (WrappedTargetException ex
) {
189 log
.println("ERROR: could not add ObjectRelation 'XFormLayerAccess.XForm': " + ex
.toString());
190 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
191 log
.println("ERROR: could not add ObjectRelation 'XFormLayerAccess.XForm': " + ex
.toString());