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
.PropertyValue
;
22 import com
.sun
.star
.container
.XIndexAccess
;
23 import com
.sun
.star
.container
.XIndexContainer
;
24 import com
.sun
.star
.container
.XNameAccess
;
25 import com
.sun
.star
.lang
.XMultiServiceFactory
;
26 import com
.sun
.star
.uno
.UnoRuntime
;
27 import com
.sun
.star
.uno
.XInterface
;
28 import com
.sun
.star
.ui
.XModuleUIConfigurationManagerSupplier
;
29 import ifc
.ui
._XUIConfiguration
;
30 import java
.io
.PrintWriter
;
31 import com
.sun
.star
.lang
.EventObject
;
32 import com
.sun
.star
.text
.XTextDocument
;
33 import com
.sun
.star
.util
.XCloseable
;
34 import com
.sun
.star
.ui
.ConfigurationEvent
;
35 import com
.sun
.star
.ui
.XUIConfigurationManager
;
36 import ifc
.ui
._XUIConfigurationManager
;
37 import lib
.StatusException
;
39 import lib
.TestEnvironment
;
40 import lib
.TestParameters
;
41 import util
.WriterTools
;
46 public class ModuleUIConfigurationManager
extends TestCase
{
47 XInterface oObj
= null;
48 XMultiServiceFactory xMSF
= null;
49 XTextDocument xTextDoc
= null;
52 * Cleanup: close the created document
53 * @param tParam The test parameters.
54 * @param log The log writer.
57 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
58 log
.println(" disposing xTextDoc ");
59 if (xTextDoc
!= null) {
61 XCloseable closer
= UnoRuntime
.queryInterface(
62 XCloseable
.class, xTextDoc
);
64 } catch (com
.sun
.star
.util
.CloseVetoException e
) {
65 log
.println("couldn't close document");
66 } catch (com
.sun
.star
.lang
.DisposedException e
) {
67 log
.println("couldn't close document");
70 log
.println(" disposing storage");
77 protected TestEnvironment
createTestEnvironment(TestParameters tParam
, PrintWriter log
) {
78 TestEnvironment tEnv
= null;
81 xMSF
= tParam
.getMSF();
83 log
.println("Creating instance...");
84 xTextDoc
= WriterTools
.createTextDoc(xMSF
);
86 Object o
= xMSF
.createInstance("com.sun.star.ui.ModuleUIConfigurationManagerSupplier");
87 XModuleUIConfigurationManagerSupplier xMUICMS
= UnoRuntime
.queryInterface(XModuleUIConfigurationManagerSupplier
.class, o
);
89 util
.dbg
.printInterfaces(xMUICMS
);
90 oObj
= xMUICMS
.getUIConfigurationManager("com.sun.star.text.TextDocument");
92 log
.println("TestObject: " + utils
.getImplName(oObj
));
93 tEnv
= new TestEnvironment(oObj
);
95 XNameAccess xMM
= UnoRuntime
.queryInterface(XNameAccess
.class, xMSF
.createInstance("com.sun.star.comp.framework.ModuleManager"));
96 xMM
.getElementNames();
98 // the short cut manager service name
99 // 2do: correct the service name when it's no longer in
100 tEnv
.addObjRelation("XConfigurationManager.ShortCutManager",
101 "com.sun.star.ui.ModuleAcceleratorConfiguration");
104 tEnv
.addObjRelation("XModuleUIConfigurationManager.ResourceURL",
105 "private:resource/menubar/menubar");
106 tEnv
.addObjRelation("XUIConfiguration.XUIConfigurationListenerImpl",
107 new ConfigurationListener(log
,
108 UnoRuntime
.queryInterface(
109 XUIConfigurationManager
.class, oObj
), xMSF
));
110 tEnv
.addObjRelation("XModuleUIConfigurationManagerSupplier.ConfigManagerImplementationName",
111 "com.sun.star.comp.framework.ModuleUIConfigurationManager");
113 catch(com
.sun
.star
.uno
.Exception e
) {
114 e
.printStackTrace(log
);
115 throw new StatusException("Cannot create test object", e
);
121 * An implementation of the _XUIConfiguration.XUIConfigurationListenerImpl
122 * interface to trigger the event for a listener call.
123 * @see ifc.ui._XUIConfiguration
125 private static class ConfigurationListener
implements _XUIConfiguration
.XUIConfigurationListenerImpl
{
126 private boolean triggered
= false;
127 private final PrintWriter log
;
128 private final XUIConfigurationManager xUIManager
;
129 private final XMultiServiceFactory xMSF
;
131 private ConfigurationListener(PrintWriter _log
, XUIConfigurationManager xUIManager
, XMultiServiceFactory xMSF
) {
133 this.xUIManager
= xUIManager
;
139 public void fireEvent() {
141 XIndexAccess xMenuBarSettings
= xUIManager
.getSettings(
142 "private:resource/menubar/menubar", true);
144 PropertyValue
[]prop
= _XUIConfigurationManager
.createMenuBarEntry(
145 "Trigger Event", xMenuBarSettings
, xMSF
, log
);
146 _XUIConfigurationManager
.createMenuBarItem("Click for Macro",
147 UnoRuntime
.queryInterface(
148 XIndexContainer
.class, prop
[3].Value
), log
);
149 XIndexContainer x
= UnoRuntime
.queryInterface(XIndexContainer
.class, xMenuBarSettings
);
150 x
.insertByIndex(x
.getCount(), prop
);
151 xUIManager
.replaceSettings("private:resource/menubar/menubar", xMenuBarSettings
);
154 catch(com
.sun
.star
.container
.NoSuchElementException e
) {
155 log
.println("_XUIConfiguration.XUIConfigurationListenerImpl: Exception.");
156 e
.printStackTrace(log
);
158 catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
159 log
.println("_XUIConfiguration.XUIConfigurationListenerImpl: Exception.");
160 e
.printStackTrace(log
);
162 catch(com
.sun
.star
.lang
.IllegalAccessException e
) {
163 log
.println("_XUIConfiguration.XUIConfigurationListenerImpl: Exception.");
164 e
.printStackTrace(log
);
166 catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
167 log
.println("_XUIConfiguration.XUIConfigurationListenerImpl: Exception.");
168 e
.printStackTrace(log
);
170 catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
171 log
.println("_XUIConfiguration.XUIConfigurationListenerImpl: Exception.");
172 e
.printStackTrace(log
);
175 public boolean actionWasTriggered(){
178 public void disposing(EventObject e
) {
179 log
.println("_XUIConfiguration.XUIConfigurationListenerImpl.disposing the listener.");
181 public void elementInserted(ConfigurationEvent configEvent
) {
183 log
.println("_XUIConfiguration.XUIConfigurationListenerImpl.elementInserted.");
185 public void elementRemoved(ConfigurationEvent configEvent
) {
187 log
.println("_XUIConfiguration.XUIConfigurationListenerImpl.elementRemoved.");
189 public void elementReplaced(ConfigurationEvent configEvent
) {
191 log
.println("_XUIConfiguration.XUIConfigurationListenerImpl.elementReplaced.");