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 .
20 import com
.sun
.star
.container
.XIndexAccess
;
21 import com
.sun
.star
.lang
.XComponent
;
22 import com
.sun
.star
.sheet
.XSheetAnnotation
;
23 import com
.sun
.star
.sheet
.XSheetAnnotationAnchor
;
24 import com
.sun
.star
.sheet
.XSheetAnnotationShapeSupplier
;
25 import com
.sun
.star
.sheet
.XSpreadsheet
;
26 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
27 import com
.sun
.star
.sheet
.XSpreadsheets
;
28 import com
.sun
.star
.table
.CellAddress
;
29 import com
.sun
.star
.table
.XCell
;
30 import com
.sun
.star
.table
.XCellRange
;
31 import com
.sun
.star
.text
.XSimpleText
;
32 import com
.sun
.star
.uno
.AnyConverter
;
33 import com
.sun
.star
.uno
.Type
;
34 import com
.sun
.star
.uno
.UnoRuntime
;
35 import com
.sun
.star
.uno
.XInterface
;
38 import lib
.TestEnvironment
;
39 import lib
.TestParameters
;
41 import util
.SOfficeFactory
;
44 import java
.io
.PrintWriter
;
45 import util
.DefaultDsc
;
46 import util
.InstCreator
;
50 * Test for object which represents some text annotation
51 * anchored to some cell in spreadsheet (implement
52 * <code>com.sun.star.sheet.CellAnnotation</code>).<p>
53 * Object implements the following interfaces :
55 * <li> <code>com::sun::star::text::XSimpleText</code></li>
56 * <li> <code>com::sun::star::text::XTextRange</code></li>
57 * <li> <code>com::sun::star::sheet::XSheetAnnotation</code></li>
59 * This object test <b> is NOT </b> designed to be run in several
60 * threads concurrently.
61 * @see com.sun.star.sheet.CellAnnotation
62 * @see com.sun.star.text.XSimpleText
63 * @see com.sun.star.text.XTextRange
64 * @see com.sun.star.sheet.XSheetAnnotation
65 * @see ifc.text._XSimpleText
66 * @see ifc.text._XTextRange
67 * @see ifc.sheet._XSheetAnnotation
69 public class ScAnnotationShapeObj
extends TestCase
{
70 private XSpreadsheetDocument xSheetDoc
= null;
73 * Creates a spreadsheet document.
76 protected void initialize(TestParameters tParam
, PrintWriter log
) throws Exception
{
78 SOfficeFactory
.getFactory(tParam
81 log
.println("creating a Spreadsheet document");
82 log
.println("Loading: "+utils
.getFullTestURL(
83 "ScAnnotationShapeObj.sxc"));
85 UnoRuntime
.queryInterface(XSpreadsheetDocument
.class,
86 SOF
.loadDocument(utils
.getFullTestURL(
87 "ScAnnotationShapeObj.sxc")));
91 * Disposes a spreadsheet document.
94 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
95 log
.println(" disposing xSheetDoc ");
98 UnoRuntime
.queryInterface(XComponent
.class,
100 util
.DesktopTools
.closeDoc(oComp
);
104 * Creating a TestEnvironment for the interfaces to be tested.
105 * Retrieves a collection of spreadsheets from a document,
106 * and takes one them. Then a single cell is retrieved, and
107 * using its <code>com.sun.star.sheet.XSheetAnnotationAnchor</code>
108 * interface an annotation is got.
109 * Object relations created :
111 * <li> <code>'CELLPOS'</code> for
112 * {@link ifc.sheet._XSheetAnnotation} (of <code>
113 * com.sun.star.table.CellAddress</code> type) which
114 * contains the annotation cell address.</li>
118 public TestEnvironment
createTestEnvironment(
119 TestParameters Param
, PrintWriter log
) throws Exception
{
120 XInterface oObj
= null;
122 // creation of testobject here
123 // first we write what we are intend to do to log file
124 log
.println("Creating a test environment");
126 CellAddress cellPos
= new CellAddress((short) 0, 1, 2);
128 log
.println("Getting test object ");
130 XSpreadsheetDocument xArea
=
131 UnoRuntime
.queryInterface(XSpreadsheetDocument
.class,
133 XSpreadsheets oSheets
= xArea
.getSheets();
135 XIndexAccess XAccess
=
136 UnoRuntime
.queryInterface(XIndexAccess
.class,
140 XSpreadsheet oSheet
=
141 (XSpreadsheet
) AnyConverter
.toObject(new Type(
143 XAccess
.getByIndex(cellPos
.Sheet
));
145 UnoRuntime
.queryInterface(XCellRange
.class,
148 oCRange
.getCellByPosition(cellPos
.Column
, cellPos
.Row
);
150 XSheetAnnotationAnchor oAnnoA
=
151 UnoRuntime
.queryInterface(XSheetAnnotationAnchor
.class,
153 XSheetAnnotation oAnno
= oAnnoA
.getAnnotation();
155 XSimpleText xAnnoText
=
156 UnoRuntime
.queryInterface(XSimpleText
.class,
158 xAnnoText
.setString("ScAnnotationShapeObj");
160 XSheetAnnotationShapeSupplier xSheetAnnotationShapeSupplier
=
161 UnoRuntime
.queryInterface(XSheetAnnotationShapeSupplier
.class,
164 oObj
= xSheetAnnotationShapeSupplier
.getAnnotationShape();
166 log
.println("ImplementationName: "
167 + util
.utils
.getImplName(oObj
));
169 TestEnvironment tEnv
= new TestEnvironment(oObj
);
171 //adding ObjRelation for RotationDescriptor
172 tEnv
.addObjRelation("NoShear", Boolean
.TRUE
);
174 //adding ObjRelation for XText
175 DefaultDsc tDsc
= new DefaultDsc("com.sun.star.text.XTextContent",
176 "com.sun.star.text.TextField.DateTime");
178 log
.println( "adding InstCreator object" );
180 "XTEXTINFO", new InstCreator( xSheetDoc
, tDsc
) );
185 // finish class ScAnnotationShapeObj