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 
34 import com.sun.star.container.XIndexAccess;
35 import com.sun.star.lang.XComponent;
36 import com.sun.star.lang.XMultiServiceFactory;
37 import com.sun.star.sheet.XSheetAnnotation;
38 import com.sun.star.sheet.XSheetAnnotationAnchor;
39 import com.sun.star.sheet.XSpreadsheet;
40 import com.sun.star.sheet.XSpreadsheetDocument;
41 import com.sun.star.sheet.XSpreadsheets;
42 import com.sun.star.table.CellAddress;
43 import com.sun.star.table.XCell;
44 import com.sun.star.table.XCellRange;
45 import com.sun.star.text.XSimpleText;
46 import com.sun.star.uno.UnoRuntime;
47 import com.sun.star.uno.XInterface;
48 
49 
50 /**
51  *
52  * initial description
53  * @see com.sun.star.beans.XPropertySet
54  * @see com.sun.star.beans.XPropertyState
55  * @see com.sun.star.document.XDocumentInsertable
56  * @see com.sun.star.style.CharacterProperties
57  * @see com.sun.star.style.ParagraphProperties
58  * @see com.sun.star.text.XParagraphCursor
59  * @see com.sun.star.text.XSentenceCursor
60  * @see com.sun.star.text.XTextCursor
61  * @see com.sun.star.text.XTextRange
62  * @see com.sun.star.text.XWordCursor
63  * @see com.sun.star.util.XSortable
64  *
65  */
66 public class ScAnnotationTextCursor extends TestCase {
67 
68     static XSpreadsheetDocument xSheetDoc = null;
69 
initialize( TestParameters tParam, PrintWriter log )70     protected void initialize( TestParameters tParam, PrintWriter log ) {
71         SOfficeFactory SOF = SOfficeFactory.getFactory(  (XMultiServiceFactory) tParam.getMSF() );
72 
73         try {
74             log.println( "creating a Spreadsheet document" );
75             xSheetDoc = SOF.createCalcDoc(null);
76         } catch ( com.sun.star.uno.Exception e ) {
77             // Some exception occured.FAILED
78             e.printStackTrace( log );
79             throw new StatusException( "Couldn't create document", e );
80         }
81 
82     }
83 
cleanup( TestParameters tParam, PrintWriter log )84     protected void cleanup( TestParameters tParam, PrintWriter log ) {
85         log.println( "    disposing xSheetDoc " );
86         XComponent oComp = (XComponent) UnoRuntime.queryInterface
87             (XComponent.class, xSheetDoc) ;
88         util.DesktopTools.closeDoc(oComp);
89     }
90 
91 
92     /**
93      *    creating a Testenvironment for the interfaces to be tested
94      */
createTestEnvironment( TestParameters Param, PrintWriter log )95     public synchronized TestEnvironment createTestEnvironment
96             ( TestParameters Param, PrintWriter log )
97             throws StatusException {
98 
99         XInterface oObj = null;
100 
101         // creation of testobject here
102         // first we write what we are intend to do to log file
103         log.println( "Creating a test environment" );
104 
105         CellAddress cellPos = new CellAddress((short)0, 1, 2);
106 
107         try {
108             log.println("Getting test object ") ;
109 
110             XSpreadsheetDocument xArea = (XSpreadsheetDocument)
111                 UnoRuntime.queryInterface(XSpreadsheetDocument.class, xSheetDoc);
112 
113             XSpreadsheets oSheets = (XSpreadsheets) xArea.getSheets();
114 
115             XIndexAccess XAccess = (XIndexAccess)
116                         UnoRuntime.queryInterface(XIndexAccess.class, oSheets);
117 
118             XSpreadsheet oSheet = (XSpreadsheet)XAccess.getByIndex(cellPos.Sheet);
119 
120             XCellRange oCRange = (XCellRange)
121                             UnoRuntime.queryInterface(XCellRange.class, oSheet);
122 
123             XCell oCell = oCRange.getCellByPosition(cellPos.Column, cellPos.Row);
124 
125             XSheetAnnotationAnchor oAnnoA = (XSheetAnnotationAnchor)
126                 UnoRuntime.queryInterface(XSheetAnnotationAnchor.class, oCell);
127 
128             XSheetAnnotation oAnno = oAnnoA.getAnnotation();
129             XSimpleText aText = (XSimpleText)
130                             UnoRuntime.queryInterface(XSimpleText.class,oAnno);
131             aText.setString("A nice little Test");
132             oObj = aText.createTextCursor();
133 
134         } catch (Exception e) {
135             e.printStackTrace(log) ;
136             throw new StatusException(
137                     "Error getting test object from spreadsheet document",e) ;
138         }
139 
140         TestEnvironment tEnv = new TestEnvironment( oObj );
141 
142         // Other parameters required for interface tests
143 
144         return tEnv;
145     }
146 
147 }    // finish class ScAnnotationTextCursor
148 
149