1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XUIConfigurationManager.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 import com
.sun
.star
.beans
.PropertyValue
;
33 import com
.sun
.star
.beans
.XPropertySet
;
34 import com
.sun
.star
.container
.XIndexAccess
;
35 import com
.sun
.star
.container
.XIndexContainer
;
36 import com
.sun
.star
.lang
.XMultiServiceFactory
;
37 import com
.sun
.star
.lang
.XServiceInfo
;
38 import com
.sun
.star
.lang
.XSingleComponentFactory
;
39 import com
.sun
.star
.uno
.UnoRuntime
;
40 import com
.sun
.star
.uno
.XComponentContext
;
41 import com
.sun
.star
.ui
.UIElementType
;
42 import com
.sun
.star
.ui
.XImageManager
;
43 import com
.sun
.star
.ui
.XUIConfigurationManager
;
44 import java
.io
.PrintWriter
;
45 import lib
.MultiMethodTest
;
47 public class _XUIConfigurationManager
extends MultiMethodTest
{
49 public XUIConfigurationManager oObj
;
50 private String msResourceUrl
= "private:resource/menubar/menubar";
51 private String msMyResourceUrl
= "private:resource/menubar/mymenubar";
52 private XIndexContainer mxSettings
= null;
53 private XIndexAccess mxMenuBarSettings
= null;
54 private XMultiServiceFactory mxMSF
= null;
55 private String sShortCutManagerServiceName
= null;
59 * Some stuff before the tests:
60 * extract the multi service factory.
62 protected void before() {
63 mxMSF
= (XMultiServiceFactory
)tParam
.getMSF();
64 sShortCutManagerServiceName
= (String
)tEnv
.getObjRelation("XConfigurationManager.ShortCutManager");
69 * reset all changes: do at the end.
71 public void _reset() {
72 requiredMethod("removeSettings()");
74 tRes
.tested("reset()", true);
77 public void _getUIElementsInfo() {
78 boolean result
= true;
80 PropertyValue
[][]props
= oObj
.getUIElementsInfo(UIElementType
.UNKNOWN
);
81 for (int i
=0; i
<props
.length
; i
++)
82 for(int j
=0; j
<props
[i
].length
; j
++)
83 log
.println("Prop["+i
+"]["+j
+"]: " + props
[i
][j
].Name
+ " " + props
[i
][j
].Value
.toString());
85 catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
87 e
.printStackTrace(log
);
89 tRes
.tested("getUIElementsInfo()", result
);
92 public void _createSettings() {
93 mxSettings
= oObj
.createSettings();
94 util
.dbg
.printInterfaces(mxSettings
);
95 tRes
.tested("createSettings()", mxSettings
!= null);
98 public void _hasSettings() {
99 boolean result
= false;
101 result
= oObj
.hasSettings(msResourceUrl
);
103 catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
107 tRes
.tested("hasSettings()", result
);
110 public void _getSettings() {
111 requiredMethod("hasSettings()");
112 boolean result
= true;
114 mxMenuBarSettings
= oObj
.getSettings(msResourceUrl
, true);
115 result
= mxMenuBarSettings
!= null;
116 for (int i
=0; i
<mxMenuBarSettings
.getCount(); i
++) {
117 Object
[] o
= (Object
[])mxMenuBarSettings
.getByIndex(i
);
118 log
.println("+++++++++ i = " + i
);
119 for (int j
=0; j
<o
.length
; j
++) {
120 PropertyValue prop
= (PropertyValue
)o
[j
];
121 log
.println("Property" + j
+ ": " + prop
.Name
+ " " + prop
.Value
.toString());
125 catch(com
.sun
.star
.container
.NoSuchElementException e
) {
127 e
.printStackTrace(log
);
129 catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
131 e
.printStackTrace(log
);
133 catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
135 e
.printStackTrace(log
);
137 catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
139 e
.printStackTrace(log
);
141 tRes
.tested("getSettings()", result
);
144 public void _replaceSettings() {
145 requiredMethod("getSettings()");
146 boolean result
= true;
147 PropertyValue
[] prop
= createMenuBarEntry("My Entry", mxMenuBarSettings
, mxMSF
, log
);
149 tRes
.tested("replaceSettings()", false);
153 createMenuBarItem("Click for Macro", (XIndexContainer
)UnoRuntime
.queryInterface(
154 XIndexContainer
.class, prop
[3].Value
), log
);
156 XIndexContainer x
= (XIndexContainer
)UnoRuntime
.queryInterface(XIndexContainer
.class, mxMenuBarSettings
);
158 x
.insertByIndex(x
.getCount(), prop
);
160 catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
162 e
.printStackTrace(log
);
164 catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
166 e
.printStackTrace(log
);
168 catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
170 e
.printStackTrace(log
);
174 oObj
.replaceSettings(msResourceUrl
, mxMenuBarSettings
);
176 catch(com
.sun
.star
.container
.NoSuchElementException e
) {
178 e
.printStackTrace(log
);
180 catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
182 e
.printStackTrace(log
);
184 catch(com
.sun
.star
.lang
.IllegalAccessException e
) {
186 e
.printStackTrace(log
);
189 tRes
.tested("replaceSettings()", result
);
192 public void _removeSettings() {
193 requiredMethod("insertSettings()");
194 boolean result
= true;
196 oObj
.removeSettings(msMyResourceUrl
);
198 catch(com
.sun
.star
.container
.NoSuchElementException e
) {
200 e
.printStackTrace(log
);
202 catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
204 e
.printStackTrace(log
);
206 catch(com
.sun
.star
.lang
.IllegalAccessException e
) {
207 e
.printStackTrace(log
);
210 tRes
.tested("removeSettings()", result
);
213 public void _insertSettings() {
214 requiredMethod("createSettings()");
215 requiredMethod("replaceSettings()");
216 boolean result
= true;
217 util
.dbg
.printInterfaces(mxSettings
);
218 PropertyValue
[] prop
= createMenuBarEntry("A new entry", mxSettings
, mxMSF
, log
);
220 tRes
.tested("replaceSettings()", false);
224 createMenuBarItem("A new sub entry", (XIndexContainer
)UnoRuntime
.queryInterface(
225 XIndexContainer
.class, prop
[3].Value
), log
);
227 XIndexContainer x
= (XIndexContainer
)UnoRuntime
.queryInterface(XIndexContainer
.class,mxSettings
);
229 int count
= x
.getCount();
230 x
.insertByIndex(count
, prop
);
232 catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
234 e
.printStackTrace(log
);
236 catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
238 e
.printStackTrace(log
);
240 catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
242 e
.printStackTrace(log
);
246 oObj
.insertSettings(msMyResourceUrl
, mxSettings
);
248 catch(com
.sun
.star
.container
.ElementExistException e
) {
249 e
.printStackTrace(log
);
252 catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
253 e
.printStackTrace(log
);
256 catch(com
.sun
.star
.lang
.IllegalAccessException e
) {
257 e
.printStackTrace(log
);
260 tRes
.tested("insertSettings()", result
);
265 * See complex.imageManager.CheckImageManager for a more extensive test of
266 * this implementation.
268 public void _getImageManager() {
269 Object o
= oObj
.getImageManager();
270 log
.println("###### ImageManager ");
271 XImageManager xImageManager
= (XImageManager
)UnoRuntime
.queryInterface(XImageManager
.class, o
);
272 tRes
.tested("getImageManager()", xImageManager
!= null);
277 * get a shortcut manager
279 public void _getShortCutManager() {
280 Object o
= oObj
.getShortCutManager();
281 XServiceInfo xSI
= (XServiceInfo
)UnoRuntime
.queryInterface(XServiceInfo
.class,o
);
282 String
[] serviceNames
= xSI
.getSupportedServiceNames();
283 boolean bSupportedServiceFound
= false;
284 for (int i
=0; i
<serviceNames
.length
; i
++) {
285 log
.println("SuppService: " + serviceNames
[i
]);
286 if (serviceNames
[i
].equals(sShortCutManagerServiceName
)) {
287 bSupportedServiceFound
= true;
290 tRes
.tested("getShortCutManager()", bSupportedServiceFound
);
293 public void _getEventsManager() {
294 Object o
= oObj
.getEventsManager();
295 tRes
.tested("getEventsManager()", o
== null);
299 * Create a menu bar entry for adding to the menu bar of the Office.
300 * @param sLabelName The name of the new entry.
301 * @param xMenuBarSettings The existing menu bar settings, used for creating the new entry.
302 * @return An array of properties of the new entry.
304 public static PropertyValue
[] createMenuBarEntry(String sLabelName
, XIndexAccess xMenuBarSettings
, XMultiServiceFactory xMSF
, PrintWriter log
) {
305 PropertyValue
[] prop
= new PropertyValue
[4];
306 prop
[0] = new PropertyValue();
307 prop
[0].Name
= "CommandURL";
308 prop
[0].Value
= "vnd.openoffice.org:MyMenu";
309 prop
[1] = new PropertyValue();
310 prop
[1].Name
= "Label";
311 prop
[1].Value
= sLabelName
;
312 prop
[2] = new PropertyValue();
313 prop
[2].Name
= "Type";
314 prop
[2].Value
= new Short((short)0);
315 prop
[3] = new PropertyValue();
316 prop
[3].Name
= "ItemDescriptorContainer";
318 XSingleComponentFactory xFactory
= (XSingleComponentFactory
)UnoRuntime
.queryInterface(
319 XSingleComponentFactory
.class, xMenuBarSettings
);
321 XPropertySet xProp
= (XPropertySet
)UnoRuntime
.queryInterface(XPropertySet
.class, xMSF
);
322 XComponentContext xContext
= (XComponentContext
)UnoRuntime
.queryInterface(
323 XComponentContext
.class, xProp
.getPropertyValue("DefaultContext"));
324 prop
[3].Value
= xFactory
.createInstanceWithContext(xContext
);
326 catch(com
.sun
.star
.uno
.Exception e
) {
327 log
.println("Could not create an instance for ItemDescriptorContainer property.");
328 e
.printStackTrace(log
);
335 * Create a sub entry to the menu bar.
336 * @param sLabelName The name of the entry in the UI.
337 * @param xDescriptionContainer The parent entry in the menu bar where
338 * this entry is added.
340 public static void createMenuBarItem(String sLabelName
, XIndexContainer xDescriptionContainer
, PrintWriter log
) {
341 PropertyValue
[]aMenuItem
= new PropertyValue
[3];
342 // create a menu item
343 aMenuItem
[0] = new PropertyValue();
344 aMenuItem
[0].Name
= "CommandURL";
345 aMenuItem
[0].Value
= "macro:///Standard.Module1.Test()";
346 aMenuItem
[1] = new PropertyValue();
347 aMenuItem
[1].Name
= "Label";
348 aMenuItem
[1].Value
= sLabelName
;
349 aMenuItem
[2] = new PropertyValue();
350 aMenuItem
[2].Name
= "Type";
351 aMenuItem
[2].Value
= new Short((short)0);
354 xDescriptionContainer
.insertByIndex(0, aMenuItem
);
356 catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
357 e
.printStackTrace(log
);
359 catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
360 e
.printStackTrace(log
);
362 catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
363 e
.printStackTrace(log
);