merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _fwk / ModuleUIConfigurationManager.java
blob47663ea64909c9face441b2864d693459a9e499b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ModuleUIConfigurationManager.java,v $
10 * $Revision: 1.8 $
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 ************************************************************************/
31 package mod._fwk;
33 import com.sun.star.beans.PropertyValue;
34 import com.sun.star.container.XIndexAccess;
35 import com.sun.star.container.XIndexContainer;
36 import com.sun.star.container.XNameAccess;
37 import com.sun.star.embed.ElementModes;
38 import com.sun.star.embed.XStorage;
39 import com.sun.star.embed.XTransactedObject;
40 import com.sun.star.lang.XMultiServiceFactory;
41 import com.sun.star.lang.XSingleServiceFactory;
42 import com.sun.star.uno.UnoRuntime;
43 import com.sun.star.uno.XInterface;
44 import com.sun.star.ui.XModuleUIConfigurationManagerSupplier;
45 import ifc.ui._XUIConfiguration;
46 import java.io.PrintWriter;
47 import com.sun.star.lang.EventObject;
48 import com.sun.star.text.XTextDocument;
49 import com.sun.star.util.XCloseable;
50 import com.sun.star.ui.ConfigurationEvent;
51 import com.sun.star.ui.XUIConfigurationManager;
52 import ifc.ui._XUIConfigurationManager;
53 import lib.StatusException;
54 import lib.TestCase;
55 import lib.TestEnvironment;
56 import lib.TestParameters;
57 import util.WriterTools;
58 import util.utils;
60 /**
62 public class ModuleUIConfigurationManager extends TestCase {
63 XInterface oObj = null;
64 XMultiServiceFactory xMSF = null;
65 XTextDocument xTextDoc = null;
66 XStorage xStore = null;
68 /**
69 * Cleanup: close the created document
70 * @param tParam The test parameters.
71 * @param The log writer.
72 * @return The test environment.
74 protected void cleanup(TestParameters tParam, PrintWriter log) {
75 log.println(" disposing xTextDoc ");
77 try {
78 XCloseable closer = (XCloseable) UnoRuntime.queryInterface(
79 XCloseable.class, xTextDoc);
80 closer.close(true);
81 } catch (com.sun.star.util.CloseVetoException e) {
82 log.println("couldn't close document");
83 } catch (com.sun.star.lang.DisposedException e) {
84 log.println("couldn't close document");
86 log.println(" disposing storage");
87 xStore.dispose();
90 /**
91 * Create environment.
93 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
94 TestEnvironment tEnv = null;
96 try {
97 xMSF = (XMultiServiceFactory)tParam.getMSF();
99 log.println("Creating instance...");
100 xTextDoc = WriterTools.createTextDoc(xMSF);
102 Object o = (XInterface)xMSF.createInstance("com.sun.star.ui.ModuleUIConfigurationManagerSupplier");
103 XModuleUIConfigurationManagerSupplier xMUICMS = (XModuleUIConfigurationManagerSupplier)
104 UnoRuntime.queryInterface(XModuleUIConfigurationManagerSupplier.class, o);
106 util.dbg.printInterfaces(xMUICMS);
107 oObj = xMUICMS.getUIConfigurationManager("com.sun.star.text.TextDocument");
109 log.println("TestObject: " + utils.getImplName(oObj));
110 tEnv = new TestEnvironment(oObj);
112 XNameAccess xMM = (XNameAccess)UnoRuntime.queryInterface(XNameAccess.class, xMSF.createInstance("com.sun.star.comp.framework.ModuleManager"));
113 String[] names = xMM.getElementNames();
115 o = xMSF.createInstance("com.sun.star.embed.StorageFactory");
116 XSingleServiceFactory xStorageService = (XSingleServiceFactory)
117 UnoRuntime.queryInterface(XSingleServiceFactory.class, o);
118 Object[]props = new Object[2];
120 String aFile = util.utils.getOfficeTempDir(xMSF) + "dummyFile.dat";
121 log.println("storage file : '"+ aFile + "'");
123 props[0] = aFile;
124 props[1] = new Integer(ElementModes.READWRITE);
125 xStore = (XStorage)UnoRuntime.queryInterface(XStorage.class, xStorageService.createInstanceWithArguments(props));
127 PropertyValue[] initProps = new PropertyValue[4];
128 PropertyValue propVal = new PropertyValue();
129 propVal.Name = "DefaultConfigStorage";
130 propVal.Value = xStore;
131 initProps[0] = propVal;
132 propVal = new PropertyValue();
133 propVal.Name = "UserConfigStorage";
134 propVal.Value = xStore;
135 initProps[1] = propVal;
136 propVal = new PropertyValue();
137 propVal.Name = "ModuleIdentifier";
138 propVal.Value = "swriter";
139 initProps[2] = propVal;
140 propVal = new PropertyValue();
141 propVal.Name = "UserRootCommit";
142 propVal.Value = (XTransactedObject)UnoRuntime.queryInterface(XTransactedObject.class, xStore);
143 initProps[3] = propVal;
146 tEnv.addObjRelation("XInitialization.args", initProps);
148 // the short cut manager service name
149 // 2do: correct the service name when it's no longer in
150 tEnv.addObjRelation("XConfigurationManager.ShortCutManager",
151 "com.sun.star.ui.ModuleAcceleratorConfiguration");
153 // the resourceURL
154 tEnv.addObjRelation("XModuleUIConfigurationManager.ResourceURL",
155 "private:resource/menubar/menubar");
156 tEnv.addObjRelation("XUIConfiguration.XUIConfigurationListenerImpl",
157 new ConfigurationListener(log,
158 (XUIConfigurationManager)UnoRuntime.queryInterface(
159 XUIConfigurationManager.class, oObj), xMSF));
160 tEnv.addObjRelation("XModuleUIConfigurationManagerSupplier.ConfigManagerImplementationName",
161 "com.sun.star.comp.framework.ModuleUIConfigurationManager");
163 catch(com.sun.star.uno.Exception e) {
164 e.printStackTrace(log);
165 throw new StatusException("Cannot create test object", e);
167 return tEnv;
171 * An implementation of the _XUIConfiguration.XUIConfigurationListenerImpl
172 * interface to trigger the event for a listener call.
173 * @see ifc.ui._XUIConfiguration
175 public static class ConfigurationListener implements _XUIConfiguration.XUIConfigurationListenerImpl {
176 private boolean triggered = false;
177 private PrintWriter log = null;
178 private XUIConfigurationManager xUIManager = null;
179 private XMultiServiceFactory xMSF = null;
181 public ConfigurationListener(PrintWriter _log, XUIConfigurationManager xUIManager, XMultiServiceFactory xMSF) {
182 log = _log;
183 this.xUIManager = xUIManager;
184 this.xMSF = xMSF;
186 public void reset(){
187 triggered = false;
189 public void fireEvent() {
190 try {
191 XIndexAccess xMenuBarSettings = xUIManager.getSettings(
192 "private:resource/menubar/menubar", true);
194 PropertyValue[]prop = _XUIConfigurationManager.createMenuBarEntry(
195 "Trigger Event", xMenuBarSettings, xMSF, log);
196 _XUIConfigurationManager.createMenuBarItem("Click for Macro",
197 (XIndexContainer)UnoRuntime.queryInterface(
198 XIndexContainer.class, prop[3].Value), log);
199 XIndexContainer x = (XIndexContainer)UnoRuntime.queryInterface(XIndexContainer.class, xMenuBarSettings);
200 x.insertByIndex(x.getCount(), prop);
201 xUIManager.replaceSettings("private:resource/menubar/menubar", xMenuBarSettings);
202 xUIManager.reset();
204 catch(com.sun.star.container.NoSuchElementException e) {
205 log.println("_XUIConfiguration.XUIConfigurationListenerImpl: Exception.");
206 e.printStackTrace(log);
208 catch(com.sun.star.lang.IllegalArgumentException e) {
209 log.println("_XUIConfiguration.XUIConfigurationListenerImpl: Exception.");
210 e.printStackTrace(log);
212 catch(com.sun.star.lang.IllegalAccessException e) {
213 log.println("_XUIConfiguration.XUIConfigurationListenerImpl: Exception.");
214 e.printStackTrace(log);
216 catch(com.sun.star.lang.IndexOutOfBoundsException e) {
217 log.println("_XUIConfiguration.XUIConfigurationListenerImpl: Exception.");
218 e.printStackTrace(log);
220 catch(com.sun.star.lang.WrappedTargetException e) {
221 log.println("_XUIConfiguration.XUIConfigurationListenerImpl: Exception.");
222 e.printStackTrace(log);
225 public boolean actionWasTriggered(){
226 return triggered;
228 public void disposing(EventObject e) {
229 log.println("_XUIConfiguration.XUIConfigurationListenerImpl.disposing the listener.");
231 public void elementInserted(ConfigurationEvent configEvent) {
232 triggered = true;
233 log.println("_XUIConfiguration.XUIConfigurationListenerImpl.elementInserted.");
235 public void elementRemoved(ConfigurationEvent configEvent) {
236 triggered = true;
237 log.println("_XUIConfiguration.XUIConfigurationListenerImpl.elementRemoved.");
239 public void elementReplaced(ConfigurationEvent configEvent) {
240 triggered = true;
241 log.println("_XUIConfiguration.XUIConfigurationListenerImpl.elementReplaced.");