merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _fwk / UIConfigurationManager.java
blobf593fec0a8855bd6504af61d4340052c82e90ae1
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: UIConfigurationManager.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.embed.ElementModes;
37 import com.sun.star.embed.XStorage;
38 import com.sun.star.lang.XMultiServiceFactory;
39 import com.sun.star.lang.XSingleServiceFactory;
40 import com.sun.star.uno.UnoRuntime;
41 import com.sun.star.uno.XInterface;
42 import ifc.ui._XUIConfiguration;
43 import java.io.PrintWriter;
44 import com.sun.star.lang.EventObject;
45 import com.sun.star.ui.ConfigurationEvent;
46 import com.sun.star.ui.UIElementType;
47 import com.sun.star.ui.XUIConfigurationManager;
48 import com.sun.star.ui.XUIConfigurationStorage;
49 import ifc.ui._XUIConfigurationManager;
50 import lib.TestCase;
51 import lib.TestEnvironment;
52 import lib.TestParameters;
53 import util.utils;
55 /**
57 public class UIConfigurationManager extends TestCase {
58 XUIConfigurationManager xManager = null;
61 /**
62 * Create test environment:
63 * <ul>
64 * <li>create a text doc</li>
65 * <li>get the model from the text doc</li>
66 * <li>query model for XUIConfigurationManagerSupplier interface</li>
67 * <li>get the manager from the supplier</li>
68 * </ul>
69 * @param tParam The test parameters.
70 * @param The log writer.
71 * @return The test environment.
73 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
74 TestEnvironment tEnv = null;
75 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF();
77 log.println("Creating instance...");
79 try {
80 xManager = (XUIConfigurationManager)UnoRuntime.queryInterface(
81 XUIConfigurationManager.class, xMSF.createInstance(
82 "com.sun.star.comp.framework.UIConfigurationManager"));
84 catch(com.sun.star.uno.Exception e) {
86 // just to make sure, it's the right one.
87 log.println("TestObject: " + utils.getImplName(xManager));
88 tEnv = new TestEnvironment(xManager);
90 // create a configuration storage
91 try {
92 String sourceDeleteCfg = util.utils.getFullTestURL("delete.cfg");
93 String deleteCfg = util.utils.getFullURL(util.utils.getOfficeTemp(xMSF) + "delete.cfg");
94 util.utils.copyFile(xMSF, sourceDeleteCfg, deleteCfg);
95 XStorage xSubStorage = null;
96 Object o = (XInterface)xMSF.createInstance("com.sun.star.embed.StorageFactory");
97 XSingleServiceFactory xSSF = (XSingleServiceFactory)UnoRuntime.queryInterface(
98 XSingleServiceFactory.class, o);
99 Object[] props = new Object[2];
100 props[0] = deleteCfg;
101 props[1] = new Integer(ElementModes.READWRITE);
102 XStorage xRootStorage = (XStorage)UnoRuntime.queryInterface(XStorage.class, xSSF.createInstanceWithArguments(props));
103 xSubStorage = xRootStorage.openStorageElement("Configurations2", ElementModes.READWRITE);
105 XUIConfigurationStorage xConfigStorage =(XUIConfigurationStorage)UnoRuntime.queryInterface(XUIConfigurationStorage.class, xManager);
106 xConfigStorage.setStorage(xSubStorage);
107 tEnv.addObjRelation("XUIConfigurationStorage.Storage", xSubStorage);
109 catch(com.sun.star.uno.Exception e) {
110 log.println("Could not create storage: " + e.toString());
112 util.dbg.printInterfaces(xManager);
114 tEnv.addObjRelation("XUIConfiguration.XUIConfigurationListenerImpl",
115 new ConfigurationListener(log, xManager, xMSF));
117 // the short cut manager service name
118 // 2do: correct the service name when it's no longer in
119 tEnv.addObjRelation("XConfigurationManager.ShortCutManager",
120 "com.sun.star.ui.DocumentAcceleratorConfiguration");
121 return tEnv;
125 * An implementation of the _XUIConfiguration.XUIConfigurationListenerImpl
126 * interface to trigger the event for a listener call.
127 * @see ifc.ui._XUIConfiguration
129 public static class ConfigurationListener implements _XUIConfiguration.XUIConfigurationListenerImpl {
130 private boolean triggered = false;
131 private PrintWriter log = null;
132 private XUIConfigurationManager xUIManager = null;
133 private XMultiServiceFactory xMSF = null;
134 private static int iUniqueCounter;
136 public ConfigurationListener(PrintWriter _log, XUIConfigurationManager xUIManager, XMultiServiceFactory xMSF) {
137 log = _log;
138 this.xUIManager = xUIManager;
139 this.xMSF = xMSF;
140 iUniqueCounter = 0;
142 public void reset(){
143 triggered = false;
145 public void fireEvent() {
146 try {
147 if (iUniqueCounter == 0) {
148 iUniqueCounter++;
149 PropertyValue[][]props = xUIManager.getUIElementsInfo(UIElementType.UNKNOWN);
150 XIndexAccess xMenuBarSettings = xUIManager.getSettings(
151 "private:resource/menubar/menubar", true);
153 PropertyValue[]prop = _XUIConfigurationManager.createMenuBarEntry(
154 "Trigger Event", xMenuBarSettings, xMSF, log);
155 _XUIConfigurationManager.createMenuBarItem("Click for Macro",
156 (XIndexContainer)UnoRuntime.queryInterface(
157 XIndexContainer.class, prop[3].Value), log);
158 XIndexContainer x = (XIndexContainer)UnoRuntime.queryInterface(XIndexContainer.class, xMenuBarSettings);
159 x.insertByIndex(x.getCount(), prop);
160 xUIManager.replaceSettings("private:resource/menubar/menubar", xMenuBarSettings);
161 xUIManager.reset();
164 catch(com.sun.star.container.NoSuchElementException e) {
165 log.println("_XUIConfiguration.XUIConfigurationListenerImpl: Exception.");
166 e.printStackTrace(log);
168 catch(com.sun.star.lang.IllegalArgumentException e) {
169 log.println("_XUIConfiguration.XUIConfigurationListenerImpl: Exception.");
170 e.printStackTrace(log);
172 catch(com.sun.star.lang.IllegalAccessException e) {
173 log.println("_XUIConfiguration.XUIConfigurationListenerImpl: Exception.");
174 e.printStackTrace(log);
176 catch(com.sun.star.lang.IndexOutOfBoundsException e) {
177 log.println("_XUIConfiguration.XUIConfigurationListenerImpl: Exception.");
178 e.printStackTrace(log);
180 catch(com.sun.star.lang.WrappedTargetException e) {
181 log.println("_XUIConfiguration.XUIConfigurationListenerImpl: Exception.");
182 e.printStackTrace(log);
185 public boolean actionWasTriggered(){
186 return triggered;
188 public void disposing(EventObject e) {
189 triggered = true;
190 log.println("_XUIConfiguration.XUIConfigurationListenerImpl.disposing the listener.");
192 public void elementInserted(ConfigurationEvent configEvent) {
193 triggered = true;
194 log.println("_XUIConfiguration.XUIConfigurationListenerImpl.elementInserted.");
196 public void elementRemoved(ConfigurationEvent configEvent) {
197 triggered = true;
198 log.println("_XUIConfiguration.XUIConfigurationListenerImpl.elementRemoved.");
200 public void elementReplaced(ConfigurationEvent configEvent) {
201 triggered = true;
202 log.println("_XUIConfiguration.XUIConfigurationListenerImpl.elementReplaced.");