bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _fwk / UIConfigurationManager.java
blob51f3b2a77d143eb66fd4031817ffff7fc8b4d981
1 /*
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 .
19 package mod._fwk;
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.embed.ElementModes;
25 import com.sun.star.embed.XStorage;
26 import com.sun.star.lang.XMultiServiceFactory;
27 import com.sun.star.lang.XSingleServiceFactory;
28 import com.sun.star.uno.UnoRuntime;
29 import ifc.ui._XUIConfiguration;
30 import java.io.PrintWriter;
31 import com.sun.star.lang.EventObject;
32 import com.sun.star.ui.ConfigurationEvent;
33 import com.sun.star.ui.UIElementType;
34 import com.sun.star.ui.XUIConfigurationManager;
35 import com.sun.star.ui.XUIConfigurationStorage;
36 import ifc.ui._XUIConfigurationManager;
37 import lib.TestCase;
38 import lib.TestEnvironment;
39 import lib.TestParameters;
40 import util.utils;
42 /**
44 public class UIConfigurationManager extends TestCase {
45 XUIConfigurationManager xManager = null;
48 /**
49 * Create test environment:
50 * <ul>
51 * <li>create a text doc</li>
52 * <li>get the model from the text doc</li>
53 * <li>query model for XUIConfigurationManagerSupplier interface</li>
54 * <li>get the manager from the supplier</li>
55 * </ul>
56 * @param tParam The test parameters.
57 * @param log The log writer.
58 * @return The test environment.
60 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
61 TestEnvironment tEnv = null;
62 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF();
64 log.println("Creating instance...");
66 try {
67 xManager = UnoRuntime.queryInterface(
68 XUIConfigurationManager.class, xMSF.createInstance(
69 "com.sun.star.comp.framework.UIConfigurationManager"));
71 catch(com.sun.star.uno.Exception e) {
73 // just to make sure, it's the right one.
74 log.println("TestObject: " + utils.getImplName(xManager));
75 tEnv = new TestEnvironment(xManager);
77 // create a configuration storage
78 try {
79 String sourceDeleteCfg = util.utils.getFullTestURL("delete.cfg");
80 String deleteCfg = util.utils.getFullURL(util.utils.getOfficeTemp(xMSF) + "delete.cfg");
81 util.utils.copyFile(xMSF, sourceDeleteCfg, deleteCfg);
82 XStorage xSubStorage = null;
83 Object o = xMSF.createInstance("com.sun.star.embed.StorageFactory");
84 XSingleServiceFactory xSSF = UnoRuntime.queryInterface(
85 XSingleServiceFactory.class, o);
86 Object[] props = new Object[2];
87 props[0] = deleteCfg;
88 props[1] = new Integer(ElementModes.READWRITE);
89 XStorage xRootStorage = UnoRuntime.queryInterface(XStorage.class, xSSF.createInstanceWithArguments(props));
90 xSubStorage = xRootStorage.openStorageElement("Configurations2", ElementModes.READWRITE);
92 XUIConfigurationStorage xConfigStorage =UnoRuntime.queryInterface(XUIConfigurationStorage.class, xManager);
93 xConfigStorage.setStorage(xSubStorage);
94 tEnv.addObjRelation("XUIConfigurationStorage.Storage", xSubStorage);
96 catch(com.sun.star.uno.Exception e) {
97 log.println("Could not create storage: " + e.toString());
99 util.dbg.printInterfaces(xManager);
101 tEnv.addObjRelation("XUIConfiguration.XUIConfigurationListenerImpl",
102 new ConfigurationListener(log, xManager, xMSF));
104 // the short cut manager service name
105 // 2do: correct the service name when it's no longer in
106 tEnv.addObjRelation("XConfigurationManager.ShortCutManager",
107 "com.sun.star.ui.DocumentAcceleratorConfiguration");
108 return tEnv;
112 * An implementation of the _XUIConfiguration.XUIConfigurationListenerImpl
113 * interface to trigger the event for a listener call.
114 * @see ifc.ui._XUIConfiguration
116 public static class ConfigurationListener implements _XUIConfiguration.XUIConfigurationListenerImpl {
117 private boolean triggered = false;
118 private PrintWriter log = null;
119 private XUIConfigurationManager xUIManager = null;
120 private XMultiServiceFactory xMSF = null;
121 private static int iUniqueCounter;
123 public ConfigurationListener(PrintWriter _log, XUIConfigurationManager xUIManager, XMultiServiceFactory xMSF) {
124 log = _log;
125 this.xUIManager = xUIManager;
126 this.xMSF = xMSF;
127 iUniqueCounter = 0;
129 public void reset(){
130 triggered = false;
132 public void fireEvent() {
133 try {
134 if (iUniqueCounter == 0) {
135 iUniqueCounter++;
136 xUIManager.getUIElementsInfo(UIElementType.UNKNOWN);
137 XIndexAccess xMenuBarSettings = xUIManager.getSettings(
138 "private:resource/menubar/menubar", true);
140 PropertyValue[]prop = _XUIConfigurationManager.createMenuBarEntry(
141 "Trigger Event", xMenuBarSettings, xMSF, log);
142 _XUIConfigurationManager.createMenuBarItem("Click for Macro",
143 UnoRuntime.queryInterface(
144 XIndexContainer.class, prop[3].Value), log);
145 XIndexContainer x = UnoRuntime.queryInterface(XIndexContainer.class, xMenuBarSettings);
146 x.insertByIndex(x.getCount(), prop);
147 xUIManager.replaceSettings("private:resource/menubar/menubar", xMenuBarSettings);
148 xUIManager.reset();
151 catch(com.sun.star.container.NoSuchElementException e) {
152 log.println("_XUIConfiguration.XUIConfigurationListenerImpl: Exception.");
153 e.printStackTrace(log);
155 catch(com.sun.star.lang.IllegalArgumentException e) {
156 log.println("_XUIConfiguration.XUIConfigurationListenerImpl: Exception.");
157 e.printStackTrace(log);
159 catch(com.sun.star.lang.IllegalAccessException e) {
160 log.println("_XUIConfiguration.XUIConfigurationListenerImpl: Exception.");
161 e.printStackTrace(log);
163 catch(com.sun.star.lang.IndexOutOfBoundsException e) {
164 log.println("_XUIConfiguration.XUIConfigurationListenerImpl: Exception.");
165 e.printStackTrace(log);
167 catch(com.sun.star.lang.WrappedTargetException e) {
168 log.println("_XUIConfiguration.XUIConfigurationListenerImpl: Exception.");
169 e.printStackTrace(log);
172 public boolean actionWasTriggered(){
173 return triggered;
175 public void disposing(EventObject e) {
176 triggered = true;
177 log.println("_XUIConfiguration.XUIConfigurationListenerImpl.disposing the listener.");
179 public void elementInserted(ConfigurationEvent configEvent) {
180 triggered = true;
181 log.println("_XUIConfiguration.XUIConfigurationListenerImpl.elementInserted.");
183 public void elementRemoved(ConfigurationEvent configEvent) {
184 triggered = true;
185 log.println("_XUIConfiguration.XUIConfigurationListenerImpl.elementRemoved.");
187 public void elementReplaced(ConfigurationEvent configEvent) {
188 triggered = true;
189 log.println("_XUIConfiguration.XUIConfigurationListenerImpl.elementReplaced.");