tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _fwk / ModuleUIConfigurationManager.java
blobc4a826b49b6404ed3acc4449050f2982d1d2eb7f
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.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.TestCase;
38 import lib.TestEnvironment;
39 import lib.TestParameters;
40 import util.WriterTools;
41 import util.utils;
43 /**
45 public class ModuleUIConfigurationManager extends TestCase {
46 XInterface oObj = null;
47 XMultiServiceFactory xMSF = null;
48 XTextDocument xTextDoc = null;
50 /**
51 * Cleanup: close the created document
52 * @param tParam The test parameters.
53 * @param log The log writer.
55 @Override
56 protected void cleanup(TestParameters tParam, PrintWriter log) {
57 log.println(" disposing xTextDoc ");
58 if (xTextDoc != null) {
59 try {
60 XCloseable closer = UnoRuntime.queryInterface(
61 XCloseable.class, xTextDoc);
62 closer.close(true);
63 } catch (com.sun.star.util.CloseVetoException e) {
64 log.println("couldn't close document");
65 } catch (com.sun.star.lang.DisposedException e) {
66 log.println("couldn't close document");
69 log.println(" disposing storage");
72 /**
73 * Create environment.
75 @Override
76 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) throws Exception {
77 TestEnvironment tEnv = null;
79 xMSF = tParam.getMSF();
81 log.println("Creating instance...");
82 xTextDoc = WriterTools.createTextDoc(xMSF);
84 Object o = xMSF.createInstance("com.sun.star.ui.ModuleUIConfigurationManagerSupplier");
85 XModuleUIConfigurationManagerSupplier xMUICMS = UnoRuntime.queryInterface(XModuleUIConfigurationManagerSupplier.class, o);
87 util.dbg.printInterfaces(xMUICMS);
88 oObj = xMUICMS.getUIConfigurationManager("com.sun.star.text.TextDocument");
90 log.println("TestObject: " + utils.getImplName(oObj));
91 tEnv = new TestEnvironment(oObj);
93 XNameAccess xMM = UnoRuntime.queryInterface(XNameAccess.class, xMSF.createInstance("com.sun.star.comp.framework.ModuleManager"));
94 xMM.getElementNames();
96 // the short cut manager service name
97 // 2do: correct the service name when it's no longer in
98 tEnv.addObjRelation("XConfigurationManager.ShortCutManager",
99 "com.sun.star.ui.ModuleAcceleratorConfiguration");
101 // the resourceURL
102 tEnv.addObjRelation("XModuleUIConfigurationManager.ResourceURL",
103 "private:resource/menubar/menubar");
104 tEnv.addObjRelation("XUIConfiguration.XUIConfigurationListenerImpl",
105 new ConfigurationListener(log,
106 UnoRuntime.queryInterface(
107 XUIConfigurationManager.class, oObj), xMSF));
108 tEnv.addObjRelation("XModuleUIConfigurationManagerSupplier.ConfigManagerImplementationName",
109 "com.sun.star.comp.framework.ModuleUIConfigurationManager");
110 return tEnv;
114 * An implementation of the _XUIConfiguration.XUIConfigurationListenerImpl
115 * interface to trigger the event for a listener call.
116 * @see ifc.ui._XUIConfiguration
118 private static class ConfigurationListener implements _XUIConfiguration.XUIConfigurationListenerImpl {
119 private boolean triggered = false;
120 private final PrintWriter log;
121 private final XUIConfigurationManager xUIManager;
122 private final XMultiServiceFactory xMSF;
124 private ConfigurationListener(PrintWriter _log, XUIConfigurationManager xUIManager, XMultiServiceFactory xMSF) {
125 log = _log;
126 this.xUIManager = xUIManager;
127 this.xMSF = xMSF;
129 public void reset(){
130 triggered = false;
132 public void fireEvent() {
133 try {
134 XIndexAccess xMenuBarSettings = xUIManager.getSettings(
135 "private:resource/menubar/menubar", true);
137 PropertyValue[]prop = _XUIConfigurationManager.createMenuBarEntry(
138 "Trigger Event", xMenuBarSettings, xMSF, log);
139 _XUIConfigurationManager.createMenuBarItem("Click for Macro",
140 UnoRuntime.queryInterface(
141 XIndexContainer.class, prop[3].Value), log);
142 XIndexContainer x = UnoRuntime.queryInterface(XIndexContainer.class, xMenuBarSettings);
143 x.insertByIndex(x.getCount(), prop);
144 xUIManager.replaceSettings("private:resource/menubar/menubar", xMenuBarSettings);
145 xUIManager.reset();
147 catch(com.sun.star.container.NoSuchElementException e) {
148 log.println("_XUIConfiguration.XUIConfigurationListenerImpl: Exception.");
149 e.printStackTrace(log);
151 catch(com.sun.star.lang.IllegalArgumentException e) {
152 log.println("_XUIConfiguration.XUIConfigurationListenerImpl: Exception.");
153 e.printStackTrace(log);
155 catch(com.sun.star.lang.IllegalAccessException e) {
156 log.println("_XUIConfiguration.XUIConfigurationListenerImpl: Exception.");
157 e.printStackTrace(log);
159 catch(com.sun.star.lang.IndexOutOfBoundsException e) {
160 log.println("_XUIConfiguration.XUIConfigurationListenerImpl: Exception.");
161 e.printStackTrace(log);
163 catch(com.sun.star.lang.WrappedTargetException e) {
164 log.println("_XUIConfiguration.XUIConfigurationListenerImpl: Exception.");
165 e.printStackTrace(log);
168 public boolean actionWasTriggered(){
169 return triggered;
171 public void disposing(EventObject e) {
172 log.println("_XUIConfiguration.XUIConfigurationListenerImpl.disposing the listener.");
174 public void elementInserted(ConfigurationEvent configEvent) {
175 triggered = true;
176 log.println("_XUIConfiguration.XUIConfigurationListenerImpl.elementInserted.");
178 public void elementRemoved(ConfigurationEvent configEvent) {
179 triggered = true;
180 log.println("_XUIConfiguration.XUIConfigurationListenerImpl.elementRemoved.");
182 public void elementReplaced(ConfigurationEvent configEvent) {
183 triggered = true;
184 log.println("_XUIConfiguration.XUIConfigurationListenerImpl.elementReplaced.");