1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
29 import com
.sun
.star
.beans
.PropertyValue
;
30 import com
.sun
.star
.beans
.XPropertySet
;
31 import com
.sun
.star
.container
.XIndexAccess
;
32 import com
.sun
.star
.container
.XIndexContainer
;
33 import com
.sun
.star
.lang
.XMultiServiceFactory
;
34 import com
.sun
.star
.lang
.XServiceInfo
;
35 import com
.sun
.star
.lang
.XSingleComponentFactory
;
36 import com
.sun
.star
.uno
.UnoRuntime
;
37 import com
.sun
.star
.uno
.XComponentContext
;
38 import com
.sun
.star
.ui
.UIElementType
;
39 import com
.sun
.star
.ui
.XImageManager
;
40 import com
.sun
.star
.ui
.XUIConfigurationManager
;
41 import java
.io
.PrintWriter
;
42 import lib
.MultiMethodTest
;
44 public class _XUIConfigurationManager
extends MultiMethodTest
{
46 public XUIConfigurationManager oObj
;
47 private String msResourceUrl
= "private:resource/menubar/menubar";
48 private String msMyResourceUrl
= "private:resource/menubar/mymenubar";
49 private XIndexContainer mxSettings
= null;
50 private XIndexAccess mxMenuBarSettings
= null;
51 private XMultiServiceFactory mxMSF
= null;
52 private String sShortCutManagerServiceName
= null;
56 * Some stuff before the tests:
57 * extract the multi service factory.
59 protected void before() {
60 mxMSF
= (XMultiServiceFactory
)tParam
.getMSF();
61 sShortCutManagerServiceName
= (String
)tEnv
.getObjRelation("XConfigurationManager.ShortCutManager");
66 * reset all changes: do at the end.
68 public void _reset() {
69 requiredMethod("removeSettings()");
71 tRes
.tested("reset()", true);
74 public void _getUIElementsInfo() {
75 boolean result
= true;
77 PropertyValue
[][]props
= oObj
.getUIElementsInfo(UIElementType
.UNKNOWN
);
78 for (int i
=0; i
<props
.length
; i
++)
79 for(int j
=0; j
<props
[i
].length
; j
++)
80 log
.println("Prop["+i
+"]["+j
+"]: " + props
[i
][j
].Name
+ " " + props
[i
][j
].Value
.toString());
82 catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
84 e
.printStackTrace(log
);
86 tRes
.tested("getUIElementsInfo()", result
);
89 public void _createSettings() {
90 mxSettings
= oObj
.createSettings();
91 util
.dbg
.printInterfaces(mxSettings
);
92 tRes
.tested("createSettings()", mxSettings
!= null);
95 public void _hasSettings() {
96 boolean result
= false;
98 result
= oObj
.hasSettings(msResourceUrl
);
100 catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
104 tRes
.tested("hasSettings()", result
);
107 public void _getSettings() {
108 requiredMethod("hasSettings()");
109 boolean result
= true;
111 mxMenuBarSettings
= oObj
.getSettings(msResourceUrl
, true);
112 result
= mxMenuBarSettings
!= null;
113 for (int i
=0; i
<mxMenuBarSettings
.getCount(); i
++) {
114 Object
[] o
= (Object
[])mxMenuBarSettings
.getByIndex(i
);
115 log
.println("+++++++++ i = " + i
);
116 for (int j
=0; j
<o
.length
; j
++) {
117 PropertyValue prop
= (PropertyValue
)o
[j
];
118 log
.println("Property" + j
+ ": " + prop
.Name
+ " " + prop
.Value
.toString());
122 catch(com
.sun
.star
.container
.NoSuchElementException e
) {
124 e
.printStackTrace(log
);
126 catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
128 e
.printStackTrace(log
);
130 catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
132 e
.printStackTrace(log
);
134 catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
136 e
.printStackTrace(log
);
138 tRes
.tested("getSettings()", result
);
141 public void _replaceSettings() {
142 requiredMethod("getSettings()");
143 boolean result
= true;
144 PropertyValue
[] prop
= createMenuBarEntry("My Entry", mxMenuBarSettings
, mxMSF
, log
);
146 tRes
.tested("replaceSettings()", false);
150 createMenuBarItem("Click for Macro", (XIndexContainer
)UnoRuntime
.queryInterface(
151 XIndexContainer
.class, prop
[3].Value
), log
);
153 XIndexContainer x
= (XIndexContainer
)UnoRuntime
.queryInterface(XIndexContainer
.class, mxMenuBarSettings
);
155 x
.insertByIndex(x
.getCount(), prop
);
157 catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
159 e
.printStackTrace(log
);
161 catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
163 e
.printStackTrace(log
);
165 catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
167 e
.printStackTrace(log
);
171 oObj
.replaceSettings(msResourceUrl
, mxMenuBarSettings
);
173 catch(com
.sun
.star
.container
.NoSuchElementException e
) {
175 e
.printStackTrace(log
);
177 catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
179 e
.printStackTrace(log
);
181 catch(com
.sun
.star
.lang
.IllegalAccessException e
) {
183 e
.printStackTrace(log
);
186 tRes
.tested("replaceSettings()", result
);
189 public void _removeSettings() {
190 requiredMethod("insertSettings()");
191 boolean result
= true;
193 oObj
.removeSettings(msMyResourceUrl
);
195 catch(com
.sun
.star
.container
.NoSuchElementException e
) {
197 e
.printStackTrace(log
);
199 catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
201 e
.printStackTrace(log
);
203 catch(com
.sun
.star
.lang
.IllegalAccessException e
) {
204 e
.printStackTrace(log
);
207 tRes
.tested("removeSettings()", result
);
210 public void _insertSettings() {
211 requiredMethod("createSettings()");
212 requiredMethod("replaceSettings()");
213 boolean result
= true;
214 util
.dbg
.printInterfaces(mxSettings
);
215 PropertyValue
[] prop
= createMenuBarEntry("A new entry", mxSettings
, mxMSF
, log
);
217 tRes
.tested("replaceSettings()", false);
221 createMenuBarItem("A new sub entry", (XIndexContainer
)UnoRuntime
.queryInterface(
222 XIndexContainer
.class, prop
[3].Value
), log
);
224 XIndexContainer x
= (XIndexContainer
)UnoRuntime
.queryInterface(XIndexContainer
.class,mxSettings
);
226 int count
= x
.getCount();
227 x
.insertByIndex(count
, prop
);
229 catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
231 e
.printStackTrace(log
);
233 catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
235 e
.printStackTrace(log
);
237 catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
239 e
.printStackTrace(log
);
243 oObj
.insertSettings(msMyResourceUrl
, mxSettings
);
245 catch(com
.sun
.star
.container
.ElementExistException e
) {
246 e
.printStackTrace(log
);
249 catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
250 e
.printStackTrace(log
);
253 catch(com
.sun
.star
.lang
.IllegalAccessException e
) {
254 e
.printStackTrace(log
);
257 tRes
.tested("insertSettings()", result
);
262 * See complex.imageManager.CheckImageManager for a more extensive test of
263 * this implementation.
265 public void _getImageManager() {
266 Object o
= oObj
.getImageManager();
267 log
.println("###### ImageManager ");
268 XImageManager xImageManager
= (XImageManager
)UnoRuntime
.queryInterface(XImageManager
.class, o
);
269 tRes
.tested("getImageManager()", xImageManager
!= null);
274 * get a shortcut manager
276 public void _getShortCutManager() {
277 Object o
= oObj
.getShortCutManager();
278 XServiceInfo xSI
= (XServiceInfo
)UnoRuntime
.queryInterface(XServiceInfo
.class,o
);
279 String
[] serviceNames
= xSI
.getSupportedServiceNames();
280 boolean bSupportedServiceFound
= false;
281 for (int i
=0; i
<serviceNames
.length
; i
++) {
282 log
.println("SuppService: " + serviceNames
[i
]);
283 if (serviceNames
[i
].equals(sShortCutManagerServiceName
)) {
284 bSupportedServiceFound
= true;
287 tRes
.tested("getShortCutManager()", bSupportedServiceFound
);
290 public void _getEventsManager() {
291 Object o
= oObj
.getEventsManager();
292 tRes
.tested("getEventsManager()", o
== null);
296 * Create a menu bar entry for adding to the menu bar of the Office.
297 * @param sLabelName The name of the new entry.
298 * @param xMenuBarSettings The existing menu bar settings, used for creating the new entry.
299 * @return An array of properties of the new entry.
301 public static PropertyValue
[] createMenuBarEntry(String sLabelName
, XIndexAccess xMenuBarSettings
, XMultiServiceFactory xMSF
, PrintWriter log
) {
302 PropertyValue
[] prop
= new PropertyValue
[4];
303 prop
[0] = new PropertyValue();
304 prop
[0].Name
= "CommandURL";
305 prop
[0].Value
= "vnd.openoffice.org:MyMenu";
306 prop
[1] = new PropertyValue();
307 prop
[1].Name
= "Label";
308 prop
[1].Value
= sLabelName
;
309 prop
[2] = new PropertyValue();
310 prop
[2].Name
= "Type";
311 prop
[2].Value
= new Short((short)0);
312 prop
[3] = new PropertyValue();
313 prop
[3].Name
= "ItemDescriptorContainer";
315 XSingleComponentFactory xFactory
= (XSingleComponentFactory
)UnoRuntime
.queryInterface(
316 XSingleComponentFactory
.class, xMenuBarSettings
);
318 XPropertySet xProp
= (XPropertySet
)UnoRuntime
.queryInterface(XPropertySet
.class, xMSF
);
319 XComponentContext xContext
= (XComponentContext
)UnoRuntime
.queryInterface(
320 XComponentContext
.class, xProp
.getPropertyValue("DefaultContext"));
321 prop
[3].Value
= xFactory
.createInstanceWithContext(xContext
);
323 catch(com
.sun
.star
.uno
.Exception e
) {
324 log
.println("Could not create an instance for ItemDescriptorContainer property.");
325 e
.printStackTrace(log
);
332 * Create a sub entry to the menu bar.
333 * @param sLabelName The name of the entry in the UI.
334 * @param xDescriptionContainer The parent entry in the menu bar where
335 * this entry is added.
337 public static void createMenuBarItem(String sLabelName
, XIndexContainer xDescriptionContainer
, PrintWriter log
) {
338 PropertyValue
[]aMenuItem
= new PropertyValue
[3];
339 // create a menu item
340 aMenuItem
[0] = new PropertyValue();
341 aMenuItem
[0].Name
= "CommandURL";
342 aMenuItem
[0].Value
= "macro:///Standard.Module1.Test()";
343 aMenuItem
[1] = new PropertyValue();
344 aMenuItem
[1].Name
= "Label";
345 aMenuItem
[1].Value
= sLabelName
;
346 aMenuItem
[2] = new PropertyValue();
347 aMenuItem
[2].Name
= "Type";
348 aMenuItem
[2].Value
= new Short((short)0);
351 xDescriptionContainer
.insertByIndex(0, aMenuItem
);
353 catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
354 e
.printStackTrace(log
);
356 catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
357 e
.printStackTrace(log
);
359 catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
360 e
.printStackTrace(log
);