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
.beans
.XPropertySet
;
22 import com
.sun
.star
.container
.XEnumeration
;
23 import com
.sun
.star
.container
.XEnumerationAccess
;
24 import com
.sun
.star
.container
.XIndexAccess
;
25 import com
.sun
.star
.container
.XNameAccess
;
26 import com
.sun
.star
.lang
.XMultiServiceFactory
;
27 import com
.sun
.star
.sheet
.XSpreadsheet
;
28 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
29 import com
.sun
.star
.sheet
.XSpreadsheets
;
30 import com
.sun
.star
.table
.XCell
;
31 import com
.sun
.star
.text
.XDependentTextField
;
32 import com
.sun
.star
.text
.XText
;
33 import com
.sun
.star
.text
.XTextContent
;
34 import com
.sun
.star
.text
.XTextCursor
;
35 import com
.sun
.star
.text
.XTextFieldsSupplier
;
36 import com
.sun
.star
.uno
.AnyConverter
;
37 import com
.sun
.star
.uno
.Type
;
38 import com
.sun
.star
.uno
.UnoRuntime
;
39 import com
.sun
.star
.uno
.XInterface
;
40 import lib
.MultiMethodTest
;
41 import lib
.StatusException
;
46 public class _XTextFieldsSupplier
extends MultiMethodTest
{
48 public XTextFieldsSupplier oObj
= null; // oObj filled by MultiMethodTest
49 private boolean mDispose
= false;
50 private boolean mbCreateFieldMaster
= true;
53 * Insert some text fields into a cell on the sheet, so this interface test
56 protected void before() {
57 Object o
= tEnv
.getObjRelation("XTextFieldsSupplier.MAKEENTRY");
58 if (o
!= null && ((Boolean
)o
).booleanValue()) {
60 mbCreateFieldMaster
= false;
61 XCell xCell
= (XCell
)tEnv
.getObjRelation("MAKEENTRYINCELL");
63 XSpreadsheetDocument xSheetDoc
= (XSpreadsheetDocument
)tEnv
.getObjRelation("SPREADSHEET");
66 XTextContent oContent
= null;
67 XInterface aField
= null;
70 // we want to create an instance of ScCellFieldObj.
71 // to do this we must get an MultiServiceFactory.
73 XMultiServiceFactory _oMSF
= UnoRuntime
.queryInterface(XMultiServiceFactory
.class, xSheetDoc
);
76 _oMSF
.createInstance("com.sun.star.text.TextField.URL");
77 oContent
= UnoRuntime
.queryInterface(XTextContent
.class, aField
);
79 XSpreadsheets oSheets
= xSheetDoc
.getSheets() ;
80 XIndexAccess oIndexSheets
= UnoRuntime
.queryInterface(XIndexAccess
.class, oSheets
);
81 AnyConverter
.toObject(
82 new Type(XSpreadsheet
.class),oIndexSheets
.getByIndex(0));
84 String
[] services
= _oMSF
.getAvailableServiceNames();
85 for (int i
=0; i
<services
.length
; i
++) {
86 if (services
[i
].startsWith("com.sun.star.text.FieldMaster")) {
87 mbCreateFieldMaster
= true;
88 log
.println("service " + i
+ ": " + services
[i
]);
92 if (mbCreateFieldMaster
) {
93 Object FieldMaster
= _oMSF
.createInstance("com.sun.star.text.FieldMaster.User");
94 XPropertySet PFieldMaster
= UnoRuntime
.queryInterface
95 (XPropertySet
.class,FieldMaster
);
97 XDependentTextField xTF
= UnoRuntime
.queryInterface(XDependentTextField
.class,aField
);
99 PFieldMaster
.setPropertyValue("Content","Some content");
101 xTF
.attachTextFieldMaster(PFieldMaster
);
104 oText
= UnoRuntime
.queryInterface(XText
.class, xCell
);
105 XTextCursor the_Cursor
= oText
.createTextCursor();
107 oText
.insertTextContent(
108 the_Cursor
, oContent
, true);
110 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
111 log
.println("Exception occurred while creating test Object.");
112 e
.printStackTrace(log
);
113 throw new StatusException("Couldn't insert textField.URL", e
);
114 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
115 log
.println("Exception occurred while creating test Object.");
116 e
.printStackTrace(log
);
117 throw new StatusException("Couldn't insert textField.URL", e
);
118 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
119 log
.println("Exception occurred while creating test Object.");
120 e
.printStackTrace(log
);
121 throw new StatusException("Couldn't insert textField.URL", e
);
122 } catch (com
.sun
.star
.uno
.Exception e
) {
123 log
.println("Exception occurred while creating test Object.");
124 e
.printStackTrace(log
);
125 throw new StatusException("Couldn't insert textField.URL", e
);
131 public void _getTextFields() {
132 XEnumerationAccess xEnumAccess
= oObj
.getTextFields();
133 XEnumeration xEnum
= xEnumAccess
.createEnumeration();
134 while(xEnum
!= null && xEnum
.hasMoreElements()) {
138 catch(com
.sun
.star
.container
.NoSuchElementException e
) {
139 setMethodFalse("getTextFields()", e
);
141 catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
142 setMethodFalse("getTextFields()", e
);
145 tRes
.tested("getTextFields()", xEnum
!= null);
148 public void _getTextFieldMasters() {
149 if (mbCreateFieldMaster
) {
150 XNameAccess xName
= oObj
.getTextFieldMasters();
151 util
.dbg
.printInterfaces(xName
);
152 tRes
.tested("getTextFieldMasters()", xName
!= null);
155 log
.println("Could not test 'getTextFieldMasters' because no field masters can be created on this object.");
156 tRes
.tested("getTextFieldMasters()", true);
161 * Just for convenience: log the exception and set the method false.
162 * @param method The name of the method to set to false.
163 * @param e The Exception that occurred.
165 private void setMethodFalse(String method
, Exception e
) {
166 log
.println("Exception while executing '" + method
+ "'");
167 e
.printStackTrace(log
);
168 tRes
.tested(method
, false);
171 protected void after() {
173 disposeEnvironment();