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
.embed
.ElementModes
;
26 import com
.sun
.star
.embed
.XStorage
;
27 import com
.sun
.star
.embed
.XTransactedObject
;
28 import com
.sun
.star
.lang
.XMultiServiceFactory
;
29 import com
.sun
.star
.lang
.XSingleServiceFactory
;
30 import com
.sun
.star
.uno
.UnoRuntime
;
31 import com
.sun
.star
.uno
.XInterface
;
32 import com
.sun
.star
.ui
.XModuleUIConfigurationManagerSupplier
;
33 import ifc
.ui
._XUIConfiguration
;
34 import java
.io
.PrintWriter
;
35 import com
.sun
.star
.lang
.EventObject
;
36 import com
.sun
.star
.text
.XTextDocument
;
37 import com
.sun
.star
.util
.XCloseable
;
38 import com
.sun
.star
.ui
.ConfigurationEvent
;
39 import com
.sun
.star
.ui
.XUIConfigurationManager
;
40 import ifc
.ui
._XUIConfigurationManager
;
41 import lib
.StatusException
;
43 import lib
.TestEnvironment
;
44 import lib
.TestParameters
;
45 import util
.WriterTools
;
50 public class ModuleUIConfigurationManager
extends TestCase
{
51 XInterface oObj
= null;
52 XMultiServiceFactory xMSF
= null;
53 XTextDocument xTextDoc
= null;
54 XStorage xStore
= null;
57 * Cleanup: close the created document
58 * @param tParam The test parameters.
59 * @param log The log writer.
61 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
62 log
.println(" disposing xTextDoc ");
63 if (xTextDoc
!= null) {
65 XCloseable closer
= UnoRuntime
.queryInterface(
66 XCloseable
.class, xTextDoc
);
68 } catch (com
.sun
.star
.util
.CloseVetoException e
) {
69 log
.println("couldn't close document");
70 } catch (com
.sun
.star
.lang
.DisposedException e
) {
71 log
.println("couldn't close document");
74 log
.println(" disposing storage");
83 protected TestEnvironment
createTestEnvironment(TestParameters tParam
, PrintWriter log
) {
84 TestEnvironment tEnv
= null;
87 xMSF
= (XMultiServiceFactory
)tParam
.getMSF();
89 log
.println("Creating instance...");
90 xTextDoc
= WriterTools
.createTextDoc(xMSF
);
92 Object o
= xMSF
.createInstance("com.sun.star.ui.ModuleUIConfigurationManagerSupplier");
93 XModuleUIConfigurationManagerSupplier xMUICMS
= UnoRuntime
.queryInterface(XModuleUIConfigurationManagerSupplier
.class, o
);
95 util
.dbg
.printInterfaces(xMUICMS
);
96 oObj
= xMUICMS
.getUIConfigurationManager("com.sun.star.text.TextDocument");
98 log
.println("TestObject: " + utils
.getImplName(oObj
));
99 tEnv
= new TestEnvironment(oObj
);
101 XNameAccess xMM
= UnoRuntime
.queryInterface(XNameAccess
.class, xMSF
.createInstance("com.sun.star.comp.framework.ModuleManager"));
102 xMM
.getElementNames();
104 o
= xMSF
.createInstance("com.sun.star.embed.StorageFactory");
105 XSingleServiceFactory xStorageService
= UnoRuntime
.queryInterface(XSingleServiceFactory
.class, o
);
106 Object
[]props
= new Object
[2];
108 String aFile
= util
.utils
.getOfficeTempDir(xMSF
) + "dummyFile.dat";
109 log
.println("storage file : '"+ aFile
+ "'");
112 props
[1] = new Integer(ElementModes
.READWRITE
);
113 xStore
= UnoRuntime
.queryInterface(XStorage
.class, xStorageService
.createInstanceWithArguments(props
));
115 PropertyValue
[] initProps
= new PropertyValue
[4];
116 PropertyValue propVal
= new PropertyValue();
117 propVal
.Name
= "DefaultConfigStorage";
118 propVal
.Value
= xStore
;
119 initProps
[0] = propVal
;
120 propVal
= new PropertyValue();
121 propVal
.Name
= "UserConfigStorage";
122 propVal
.Value
= xStore
;
123 initProps
[1] = propVal
;
124 propVal
= new PropertyValue();
125 propVal
.Name
= "ModuleIdentifier";
126 propVal
.Value
= "swriter";
127 initProps
[2] = propVal
;
128 propVal
= new PropertyValue();
129 propVal
.Name
= "UserRootCommit";
130 propVal
.Value
= UnoRuntime
.queryInterface(XTransactedObject
.class, xStore
);
131 initProps
[3] = propVal
;
134 tEnv
.addObjRelation("XInitialization.args", initProps
);
136 // the short cut manager service name
137 // 2do: correct the service name when it's no longer in
138 tEnv
.addObjRelation("XConfigurationManager.ShortCutManager",
139 "com.sun.star.ui.ModuleAcceleratorConfiguration");
142 tEnv
.addObjRelation("XModuleUIConfigurationManager.ResourceURL",
143 "private:resource/menubar/menubar");
144 tEnv
.addObjRelation("XUIConfiguration.XUIConfigurationListenerImpl",
145 new ConfigurationListener(log
,
146 UnoRuntime
.queryInterface(
147 XUIConfigurationManager
.class, oObj
), xMSF
));
148 tEnv
.addObjRelation("XModuleUIConfigurationManagerSupplier.ConfigManagerImplementationName",
149 "com.sun.star.comp.framework.ModuleUIConfigurationManager");
151 catch(com
.sun
.star
.uno
.Exception e
) {
152 e
.printStackTrace(log
);
153 throw new StatusException("Cannot create test object", e
);
159 * An implementation of the _XUIConfiguration.XUIConfigurationListenerImpl
160 * interface to trigger the event for a listener call.
161 * @see ifc.ui._XUIConfiguration
163 public static class ConfigurationListener
implements _XUIConfiguration
.XUIConfigurationListenerImpl
{
164 private boolean triggered
= false;
165 private PrintWriter log
= null;
166 private XUIConfigurationManager xUIManager
= null;
167 private XMultiServiceFactory xMSF
= null;
169 public ConfigurationListener(PrintWriter _log
, XUIConfigurationManager xUIManager
, XMultiServiceFactory xMSF
) {
171 this.xUIManager
= xUIManager
;
177 public void fireEvent() {
179 XIndexAccess xMenuBarSettings
= xUIManager
.getSettings(
180 "private:resource/menubar/menubar", true);
182 PropertyValue
[]prop
= _XUIConfigurationManager
.createMenuBarEntry(
183 "Trigger Event", xMenuBarSettings
, xMSF
, log
);
184 _XUIConfigurationManager
.createMenuBarItem("Click for Macro",
185 UnoRuntime
.queryInterface(
186 XIndexContainer
.class, prop
[3].Value
), log
);
187 XIndexContainer x
= UnoRuntime
.queryInterface(XIndexContainer
.class, xMenuBarSettings
);
188 x
.insertByIndex(x
.getCount(), prop
);
189 xUIManager
.replaceSettings("private:resource/menubar/menubar", xMenuBarSettings
);
192 catch(com
.sun
.star
.container
.NoSuchElementException e
) {
193 log
.println("_XUIConfiguration.XUIConfigurationListenerImpl: Exception.");
194 e
.printStackTrace(log
);
196 catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
197 log
.println("_XUIConfiguration.XUIConfigurationListenerImpl: Exception.");
198 e
.printStackTrace(log
);
200 catch(com
.sun
.star
.lang
.IllegalAccessException e
) {
201 log
.println("_XUIConfiguration.XUIConfigurationListenerImpl: Exception.");
202 e
.printStackTrace(log
);
204 catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
205 log
.println("_XUIConfiguration.XUIConfigurationListenerImpl: Exception.");
206 e
.printStackTrace(log
);
208 catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
209 log
.println("_XUIConfiguration.XUIConfigurationListenerImpl: Exception.");
210 e
.printStackTrace(log
);
213 public boolean actionWasTriggered(){
216 public void disposing(EventObject e
) {
217 log
.println("_XUIConfiguration.XUIConfigurationListenerImpl.disposing the listener.");
219 public void elementInserted(ConfigurationEvent configEvent
) {
221 log
.println("_XUIConfiguration.XUIConfigurationListenerImpl.elementInserted.");
223 public void elementRemoved(ConfigurationEvent configEvent
) {
225 log
.println("_XUIConfiguration.XUIConfigurationListenerImpl.elementRemoved.");
227 public void elementReplaced(ConfigurationEvent configEvent
) {
229 log
.println("_XUIConfiguration.XUIConfigurationListenerImpl.elementReplaced.");