1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package mod._sc;
29 
30 import java.io.PrintWriter;
31 
32 import lib.StatusException;
33 import lib.TestCase;
34 import lib.TestEnvironment;
35 import lib.TestParameters;
36 import util.SOfficeFactory;
37 
38 import com.sun.star.container.XEnumerationAccess;
39 import com.sun.star.container.XIndexAccess;
40 import com.sun.star.lang.XComponent;
41 import com.sun.star.lang.XMultiServiceFactory;
42 import com.sun.star.sheet.XSheetAnnotations;
43 import com.sun.star.sheet.XSheetAnnotationsSupplier;
44 import com.sun.star.sheet.XSpreadsheet;
45 import com.sun.star.sheet.XSpreadsheetDocument;
46 import com.sun.star.sheet.XSpreadsheets;
47 import com.sun.star.uno.AnyConverter;
48 import com.sun.star.uno.Type;
49 import com.sun.star.uno.UnoRuntime;
50 import com.sun.star.uno.XInterface;
51 
52 
53 public class ScIndexEnumeration_CellAnnotationsEnumeration extends TestCase {
54     static XSpreadsheetDocument xSheetDoc = null;
55 
56     /**
57     * Creates Spreadsheet document.
58     */
59     protected void initialize( TestParameters tParam, PrintWriter log ) {
60         // get a soffice factory object
61         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
62 
63         try {
64             log.println( "creating a sheetdocument" );
65             xSheetDoc = SOF.createCalcDoc(null);;
66         } catch (com.sun.star.uno.Exception e) {
67             // Some exception occures.FAILED
68             e.printStackTrace( log );
69             throw new StatusException( "Couldn't create document", e );
70         }
71     }
72 
73     /**
74     * Disposes Spreadsheet document.
75     */
76     protected void cleanup( TestParameters tParam, PrintWriter log ) {
77         log.println( "    disposing xSheetDoc " );
78         XComponent oComp = (XComponent)
79             UnoRuntime.queryInterface (XComponent.class, xSheetDoc);
80         util.DesktopTools.closeDoc(oComp);
81     }
82 
83     protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
84 
85         XInterface oObj = null;
86 
87         log.println("getting sheets");
88         XSpreadsheets xSpreadsheets = (XSpreadsheets)xSheetDoc.getSheets();
89 
90         log.println("getting a sheet");
91         XSpreadsheet oSheet = null;
92         XIndexAccess oIndexAccess = (XIndexAccess)
93             UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets);
94         try {
95             oSheet = (XSpreadsheet) AnyConverter.toObject(
96                     new Type(XSpreadsheet.class),oIndexAccess.getByIndex(0));
97         } catch (com.sun.star.lang.WrappedTargetException e) {
98             e.printStackTrace(log);
99             throw new StatusException( "Couldn't get a spreadsheet", e);
100         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
101             e.printStackTrace(log);
102             throw new StatusException( "Couldn't get a spreadsheet", e);
103         } catch (com.sun.star.lang.IllegalArgumentException e) {
104             e.printStackTrace(log);
105             throw new StatusException( "Couldn't get a spreadsheet", e);
106         }
107 
108         log.println("filling some cells");
109         try {
110             oSheet.getCellByPosition(5, 5).setValue(15);
111             oSheet.getCellByPosition(1, 4).setValue(10);
112             oSheet.getCellByPosition(2, 0).setValue(-5.15);
113         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
114             e.printStackTrace(log);
115             throw new StatusException(
116                 "Exception occurred while filling cells", e);
117         }
118 
119         XSheetAnnotationsSupplier sas = (XSheetAnnotationsSupplier)
120             UnoRuntime.queryInterface(XSheetAnnotationsSupplier.class, oSheet);
121 
122         XSheetAnnotations anno = sas.getAnnotations();
123         XEnumerationAccess ea = (XEnumerationAccess)
124                     UnoRuntime.queryInterface(XEnumerationAccess.class, anno);
125 
126         oObj = ea.createEnumeration();
127 
128         log.println("ImplementationName: "+util.utils.getImplName(oObj));
129 
130         log.println("creating a new environment for object");
131         TestEnvironment tEnv = new TestEnvironment(oObj);
132 
133         tEnv.addObjRelation("ENUM",ea);
134 
135         return tEnv;
136     }
137 }
138 
139