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
.beans
.PropertyValue
;
21 import com
.sun
.star
.beans
.XPropertySet
;
22 import com
.sun
.star
.container
.XIndexAccess
;
23 import com
.sun
.star
.container
.XIndexContainer
;
24 import com
.sun
.star
.lang
.XMultiServiceFactory
;
25 import com
.sun
.star
.lang
.XServiceInfo
;
26 import com
.sun
.star
.lang
.XSingleComponentFactory
;
27 import com
.sun
.star
.uno
.UnoRuntime
;
28 import com
.sun
.star
.uno
.XComponentContext
;
29 import com
.sun
.star
.ui
.UIElementType
;
30 import com
.sun
.star
.ui
.XImageManager
;
31 import com
.sun
.star
.ui
.XUIConfigurationManager
;
32 import java
.io
.PrintWriter
;
33 import lib
.MultiMethodTest
;
35 public class _XUIConfigurationManager
extends MultiMethodTest
{
37 public XUIConfigurationManager oObj
;
38 private static final String msResourceUrl
= "private:resource/menubar/menubar";
39 private static final String msMyResourceUrl
= "private:resource/menubar/mymenubar";
40 private XIndexContainer mxSettings
= null;
41 private XIndexAccess mxMenuBarSettings
= null;
42 private XMultiServiceFactory mxMSF
= null;
43 private String sShortCutManagerServiceName
= null;
47 * Some stuff before the tests:
48 * extract the multi service factory.
51 protected void before() {
52 mxMSF
= tParam
.getMSF();
53 sShortCutManagerServiceName
= (String
)tEnv
.getObjRelation("XConfigurationManager.ShortCutManager");
58 * reset all changes: do at the end.
60 public void _reset() {
61 requiredMethod("removeSettings()");
63 tRes
.tested("reset()", true);
66 public void _getUIElementsInfo() {
67 boolean result
= true;
69 PropertyValue
[][]props
= oObj
.getUIElementsInfo(UIElementType
.UNKNOWN
);
70 for (int i
=0; i
<props
.length
; i
++)
71 for(int j
=0; j
<props
[i
].length
; j
++)
72 log
.println("Prop["+i
+"]["+j
+"]: " + props
[i
][j
].Name
+ " " + props
[i
][j
].Value
.toString());
74 catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
76 e
.printStackTrace(log
);
78 tRes
.tested("getUIElementsInfo()", result
);
81 public void _createSettings() {
82 mxSettings
= oObj
.createSettings();
83 util
.dbg
.printInterfaces(mxSettings
);
84 tRes
.tested("createSettings()", mxSettings
!= null);
87 public void _hasSettings() {
88 boolean result
= false;
90 result
= oObj
.hasSettings(msResourceUrl
);
92 catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
96 tRes
.tested("hasSettings()", result
);
99 public void _getSettings() {
100 requiredMethod("hasSettings()");
101 boolean result
= true;
103 mxMenuBarSettings
= oObj
.getSettings(msResourceUrl
, true);
104 for (int i
=0; i
<mxMenuBarSettings
.getCount(); i
++) {
105 Object
[] o
= (Object
[])mxMenuBarSettings
.getByIndex(i
);
106 log
.println("+++++++++ i = " + i
);
107 for (int j
=0; j
<o
.length
; j
++) {
108 PropertyValue prop
= (PropertyValue
)o
[j
];
109 log
.println("Property" + j
+ ": " + prop
.Name
+ " " + prop
.Value
.toString());
113 catch(com
.sun
.star
.container
.NoSuchElementException e
) {
115 e
.printStackTrace(log
);
117 catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
119 e
.printStackTrace(log
);
121 catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
123 e
.printStackTrace(log
);
125 catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
127 e
.printStackTrace(log
);
129 tRes
.tested("getSettings()", result
);
132 public void _replaceSettings() {
133 requiredMethod("getSettings()");
134 boolean result
= true;
135 PropertyValue
[] prop
= createMenuBarEntry("My Entry", mxMenuBarSettings
, mxMSF
, log
);
137 tRes
.tested("replaceSettings()", false);
141 createMenuBarItem("Click for Macro", UnoRuntime
.queryInterface(
142 XIndexContainer
.class, prop
[3].Value
), log
);
144 XIndexContainer x
= UnoRuntime
.queryInterface(XIndexContainer
.class, mxMenuBarSettings
);
146 x
.insertByIndex(x
.getCount(), prop
);
148 catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
150 e
.printStackTrace(log
);
152 catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
154 e
.printStackTrace(log
);
156 catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
158 e
.printStackTrace(log
);
162 oObj
.replaceSettings(msResourceUrl
, mxMenuBarSettings
);
164 catch(com
.sun
.star
.container
.NoSuchElementException e
) {
166 e
.printStackTrace(log
);
168 catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
170 e
.printStackTrace(log
);
172 catch(com
.sun
.star
.lang
.IllegalAccessException e
) {
174 e
.printStackTrace(log
);
177 tRes
.tested("replaceSettings()", result
);
180 public void _removeSettings() {
181 requiredMethod("insertSettings()");
182 boolean result
= true;
184 oObj
.removeSettings(msMyResourceUrl
);
186 catch(com
.sun
.star
.container
.NoSuchElementException e
) {
188 e
.printStackTrace(log
);
190 catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
192 e
.printStackTrace(log
);
194 catch(com
.sun
.star
.lang
.IllegalAccessException e
) {
195 e
.printStackTrace(log
);
198 tRes
.tested("removeSettings()", result
);
201 public void _insertSettings() {
202 requiredMethod("createSettings()");
203 requiredMethod("replaceSettings()");
204 boolean result
= true;
205 util
.dbg
.printInterfaces(mxSettings
);
206 PropertyValue
[] prop
= createMenuBarEntry("A new entry", mxSettings
, mxMSF
, log
);
208 tRes
.tested("replaceSettings()", false);
212 createMenuBarItem("A new sub entry", UnoRuntime
.queryInterface(
213 XIndexContainer
.class, prop
[3].Value
), log
);
215 XIndexContainer x
= UnoRuntime
.queryInterface(XIndexContainer
.class,mxSettings
);
217 int count
= x
.getCount();
218 x
.insertByIndex(count
, prop
);
220 catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
222 e
.printStackTrace(log
);
224 catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
226 e
.printStackTrace(log
);
228 catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
230 e
.printStackTrace(log
);
234 oObj
.insertSettings(msMyResourceUrl
, mxSettings
);
236 catch(com
.sun
.star
.container
.ElementExistException e
) {
237 e
.printStackTrace(log
);
240 catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
241 e
.printStackTrace(log
);
244 catch(com
.sun
.star
.lang
.IllegalAccessException e
) {
245 e
.printStackTrace(log
);
248 tRes
.tested("insertSettings()", result
);
253 * See complex.imageManager.CheckImageManager for a more extensive test of
254 * this implementation.
256 public void _getImageManager() {
257 Object o
= oObj
.getImageManager();
258 log
.println("###### ImageManager ");
259 XImageManager xImageManager
= UnoRuntime
.queryInterface(XImageManager
.class, o
);
260 tRes
.tested("getImageManager()", xImageManager
!= null);
265 * get a shortcut manager
267 public void _getShortCutManager() {
268 Object o
= oObj
.getShortCutManager();
269 XServiceInfo xSI
= UnoRuntime
.queryInterface(XServiceInfo
.class,o
);
270 String
[] serviceNames
= xSI
.getSupportedServiceNames();
271 boolean bSupportedServiceFound
= false;
272 for (int i
=0; i
<serviceNames
.length
; i
++) {
273 log
.println("SuppService: " + serviceNames
[i
]);
274 if (serviceNames
[i
].equals(sShortCutManagerServiceName
)) {
275 bSupportedServiceFound
= true;
278 tRes
.tested("getShortCutManager()", bSupportedServiceFound
);
281 public void _getEventsManager() {
282 Object o
= oObj
.getEventsManager();
283 tRes
.tested("getEventsManager()", o
== null);
287 * Create a menu bar entry for adding to the menu bar of the Office.
288 * @param sLabelName The name of the new entry.
289 * @param xMenuBarSettings The existing menu bar settings, used for creating the new entry.
290 * @return An array of properties of the new entry.
292 public static PropertyValue
[] createMenuBarEntry(String sLabelName
, XIndexAccess xMenuBarSettings
, XMultiServiceFactory xMSF
, PrintWriter log
) {
293 PropertyValue
[] prop
= new PropertyValue
[4];
294 prop
[0] = new PropertyValue();
295 prop
[0].Name
= "CommandURL";
296 prop
[0].Value
= "vnd.openoffice.org:MyMenu";
297 prop
[1] = new PropertyValue();
298 prop
[1].Name
= "Label";
299 prop
[1].Value
= sLabelName
;
300 prop
[2] = new PropertyValue();
301 prop
[2].Name
= "Type";
302 prop
[2].Value
= Short
.valueOf((short)0);
303 prop
[3] = new PropertyValue();
304 prop
[3].Name
= "ItemDescriptorContainer";
306 XSingleComponentFactory xFactory
= UnoRuntime
.queryInterface(
307 XSingleComponentFactory
.class, xMenuBarSettings
);
309 XPropertySet xProp
= UnoRuntime
.queryInterface(XPropertySet
.class, xMSF
);
310 XComponentContext xContext
= UnoRuntime
.queryInterface(
311 XComponentContext
.class, xProp
.getPropertyValue("DefaultContext"));
312 prop
[3].Value
= xFactory
.createInstanceWithContext(xContext
);
314 catch(com
.sun
.star
.uno
.Exception e
) {
315 log
.println("Could not create an instance for ItemDescriptorContainer property.");
316 e
.printStackTrace(log
);
323 * Create a sub entry to the menu bar.
324 * @param sLabelName The name of the entry in the UI.
325 * @param xDescriptionContainer The parent entry in the menu bar where
326 * this entry is added.
328 public static void createMenuBarItem(String sLabelName
, XIndexContainer xDescriptionContainer
, PrintWriter log
) {
329 PropertyValue
[]aMenuItem
= new PropertyValue
[3];
330 // create a menu item
331 aMenuItem
[0] = new PropertyValue();
332 aMenuItem
[0].Name
= "CommandURL";
333 aMenuItem
[0].Value
= "macro:///Standard.Module1.Test()";
334 aMenuItem
[1] = new PropertyValue();
335 aMenuItem
[1].Name
= "Label";
336 aMenuItem
[1].Value
= sLabelName
;
337 aMenuItem
[2] = new PropertyValue();
338 aMenuItem
[2].Name
= "Type";
339 aMenuItem
[2].Value
= Short
.valueOf((short)0);
342 xDescriptionContainer
.insertByIndex(0, aMenuItem
);
344 catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
345 e
.printStackTrace(log
);
347 catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
348 e
.printStackTrace(log
);
350 catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
351 e
.printStackTrace(log
);