1*ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*ef39d40dSAndrew Rist * distributed with this work for additional information 6*ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9*ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10*ef39d40dSAndrew Rist * 11*ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*ef39d40dSAndrew Rist * 13*ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15*ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17*ef39d40dSAndrew Rist * specific language governing permissions and limitations 18*ef39d40dSAndrew Rist * under the License. 19*ef39d40dSAndrew Rist * 20*ef39d40dSAndrew Rist *************************************************************/ 21*ef39d40dSAndrew Rist 22*ef39d40dSAndrew Rist 23cdf0e10cSrcweir package ifc.ui; 24cdf0e10cSrcweir 25cdf0e10cSrcweir import com.sun.star.beans.PropertyValue; 26cdf0e10cSrcweir import com.sun.star.beans.XPropertySet; 27cdf0e10cSrcweir import com.sun.star.container.XIndexAccess; 28cdf0e10cSrcweir import com.sun.star.container.XIndexContainer; 29cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 30cdf0e10cSrcweir import com.sun.star.lang.XServiceInfo; 31cdf0e10cSrcweir import com.sun.star.lang.XSingleComponentFactory; 32cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 33cdf0e10cSrcweir import com.sun.star.uno.XComponentContext; 34cdf0e10cSrcweir import com.sun.star.ui.UIElementType; 35cdf0e10cSrcweir import com.sun.star.ui.XImageManager; 36cdf0e10cSrcweir import com.sun.star.ui.XUIConfigurationManager; 37cdf0e10cSrcweir import java.io.PrintWriter; 38cdf0e10cSrcweir import lib.MultiMethodTest; 39cdf0e10cSrcweir 40cdf0e10cSrcweir public class _XUIConfigurationManager extends MultiMethodTest { 41cdf0e10cSrcweir 42cdf0e10cSrcweir public XUIConfigurationManager oObj; 43cdf0e10cSrcweir private String msResourceUrl = "private:resource/menubar/menubar"; 44cdf0e10cSrcweir private String msMyResourceUrl = "private:resource/menubar/mymenubar"; 45cdf0e10cSrcweir private XIndexContainer mxSettings = null; 46cdf0e10cSrcweir private XIndexAccess mxMenuBarSettings = null; 47cdf0e10cSrcweir private XMultiServiceFactory mxMSF = null; 48cdf0e10cSrcweir private String sShortCutManagerServiceName = null; 49cdf0e10cSrcweir 50cdf0e10cSrcweir 51cdf0e10cSrcweir /** 52cdf0e10cSrcweir * Some stuff before the tests: 53cdf0e10cSrcweir * extract the multi service factory. 54cdf0e10cSrcweir */ before()55cdf0e10cSrcweir protected void before() { 56cdf0e10cSrcweir mxMSF = (XMultiServiceFactory)tParam.getMSF(); 57cdf0e10cSrcweir sShortCutManagerServiceName = (String)tEnv.getObjRelation("XConfigurationManager.ShortCutManager"); 58cdf0e10cSrcweir 59cdf0e10cSrcweir } 60cdf0e10cSrcweir 61cdf0e10cSrcweir /** 62cdf0e10cSrcweir * reset all changes: do at the end. 63cdf0e10cSrcweir */ _reset()64cdf0e10cSrcweir public void _reset() { 65cdf0e10cSrcweir requiredMethod("removeSettings()"); 66cdf0e10cSrcweir oObj.reset(); 67cdf0e10cSrcweir tRes.tested("reset()", true); 68cdf0e10cSrcweir } 69cdf0e10cSrcweir _getUIElementsInfo()70cdf0e10cSrcweir public void _getUIElementsInfo() { 71cdf0e10cSrcweir boolean result = true; 72cdf0e10cSrcweir try { 73cdf0e10cSrcweir PropertyValue[][]props = oObj.getUIElementsInfo(UIElementType.UNKNOWN); 74cdf0e10cSrcweir for (int i=0; i<props.length; i++) 75cdf0e10cSrcweir for(int j=0; j<props[i].length; j++) 76cdf0e10cSrcweir log.println("Prop["+i+"]["+j+"]: " + props[i][j].Name + " " + props[i][j].Value.toString()); 77cdf0e10cSrcweir } 78cdf0e10cSrcweir catch(com.sun.star.lang.IllegalArgumentException e) { 79cdf0e10cSrcweir result = false; 80cdf0e10cSrcweir e.printStackTrace(log); 81cdf0e10cSrcweir } 82cdf0e10cSrcweir tRes.tested("getUIElementsInfo()", result); 83cdf0e10cSrcweir } 84cdf0e10cSrcweir _createSettings()85cdf0e10cSrcweir public void _createSettings() { 86cdf0e10cSrcweir mxSettings = oObj.createSettings(); 87cdf0e10cSrcweir util.dbg.printInterfaces(mxSettings); 88cdf0e10cSrcweir tRes.tested("createSettings()", mxSettings != null); 89cdf0e10cSrcweir } 90cdf0e10cSrcweir _hasSettings()91cdf0e10cSrcweir public void _hasSettings() { 92cdf0e10cSrcweir boolean result = false; 93cdf0e10cSrcweir try { 94cdf0e10cSrcweir result = oObj.hasSettings(msResourceUrl); 95cdf0e10cSrcweir } 96cdf0e10cSrcweir catch(com.sun.star.lang.IllegalArgumentException e) { 97cdf0e10cSrcweir log.println(e); 98cdf0e10cSrcweir result = false; 99cdf0e10cSrcweir } 100cdf0e10cSrcweir tRes.tested("hasSettings()", result); 101cdf0e10cSrcweir } 102cdf0e10cSrcweir _getSettings()103cdf0e10cSrcweir public void _getSettings() { 104cdf0e10cSrcweir requiredMethod("hasSettings()"); 105cdf0e10cSrcweir boolean result = true; 106cdf0e10cSrcweir try { 107cdf0e10cSrcweir mxMenuBarSettings = oObj.getSettings(msResourceUrl, true); 108cdf0e10cSrcweir result = mxMenuBarSettings != null; 109cdf0e10cSrcweir for (int i=0; i<mxMenuBarSettings.getCount(); i++) { 110cdf0e10cSrcweir Object[] o = (Object[])mxMenuBarSettings.getByIndex(i); 111cdf0e10cSrcweir log.println("+++++++++ i = " + i); 112cdf0e10cSrcweir for (int j=0; j<o.length; j++) { 113cdf0e10cSrcweir PropertyValue prop = (PropertyValue)o[j]; 114cdf0e10cSrcweir log.println("Property" + j + ": " + prop.Name + " " + prop.Value.toString()); 115cdf0e10cSrcweir } 116cdf0e10cSrcweir } 117cdf0e10cSrcweir } 118cdf0e10cSrcweir catch(com.sun.star.container.NoSuchElementException e) { 119cdf0e10cSrcweir result = false; 120cdf0e10cSrcweir e.printStackTrace(log); 121cdf0e10cSrcweir } 122cdf0e10cSrcweir catch(com.sun.star.lang.IllegalArgumentException e) { 123cdf0e10cSrcweir result = false; 124cdf0e10cSrcweir e.printStackTrace(log); 125cdf0e10cSrcweir } 126cdf0e10cSrcweir catch(com.sun.star.lang.IndexOutOfBoundsException e) { 127cdf0e10cSrcweir result = false; 128cdf0e10cSrcweir e.printStackTrace(log); 129cdf0e10cSrcweir } 130cdf0e10cSrcweir catch(com.sun.star.lang.WrappedTargetException e) { 131cdf0e10cSrcweir result = false; 132cdf0e10cSrcweir e.printStackTrace(log); 133cdf0e10cSrcweir } 134cdf0e10cSrcweir tRes.tested("getSettings()", result); 135cdf0e10cSrcweir } 136cdf0e10cSrcweir _replaceSettings()137cdf0e10cSrcweir public void _replaceSettings() { 138cdf0e10cSrcweir requiredMethod("getSettings()"); 139cdf0e10cSrcweir boolean result = true; 140cdf0e10cSrcweir PropertyValue[] prop = createMenuBarEntry("My Entry", mxMenuBarSettings, mxMSF, log); 141cdf0e10cSrcweir if (prop == null) { 142cdf0e10cSrcweir tRes.tested("replaceSettings()", false); 143cdf0e10cSrcweir return; 144cdf0e10cSrcweir } 145cdf0e10cSrcweir 146cdf0e10cSrcweir createMenuBarItem("Click for Macro", (XIndexContainer)UnoRuntime.queryInterface( 147cdf0e10cSrcweir XIndexContainer.class, prop[3].Value), log); 148cdf0e10cSrcweir 149cdf0e10cSrcweir XIndexContainer x = (XIndexContainer)UnoRuntime.queryInterface(XIndexContainer.class, mxMenuBarSettings); 150cdf0e10cSrcweir try { 151cdf0e10cSrcweir x.insertByIndex(x.getCount(), prop); 152cdf0e10cSrcweir } 153cdf0e10cSrcweir catch(com.sun.star.lang.IllegalArgumentException e) { 154cdf0e10cSrcweir result = false; 155cdf0e10cSrcweir e.printStackTrace(log); 156cdf0e10cSrcweir } 157cdf0e10cSrcweir catch(com.sun.star.lang.IndexOutOfBoundsException e) { 158cdf0e10cSrcweir result = false; 159cdf0e10cSrcweir e.printStackTrace(log); 160cdf0e10cSrcweir } 161cdf0e10cSrcweir catch(com.sun.star.lang.WrappedTargetException e) { 162cdf0e10cSrcweir result = false; 163cdf0e10cSrcweir e.printStackTrace(log); 164cdf0e10cSrcweir } 165cdf0e10cSrcweir 166cdf0e10cSrcweir try { 167cdf0e10cSrcweir oObj.replaceSettings(msResourceUrl, mxMenuBarSettings); 168cdf0e10cSrcweir } 169cdf0e10cSrcweir catch(com.sun.star.container.NoSuchElementException e) { 170cdf0e10cSrcweir result = false; 171cdf0e10cSrcweir e.printStackTrace(log); 172cdf0e10cSrcweir } 173cdf0e10cSrcweir catch(com.sun.star.lang.IllegalArgumentException e) { 174cdf0e10cSrcweir result = false; 175cdf0e10cSrcweir e.printStackTrace(log); 176cdf0e10cSrcweir } 177cdf0e10cSrcweir catch(com.sun.star.lang.IllegalAccessException e) { 178cdf0e10cSrcweir result = false; 179cdf0e10cSrcweir e.printStackTrace(log); 180cdf0e10cSrcweir } 181cdf0e10cSrcweir _getSettings(); 182cdf0e10cSrcweir tRes.tested("replaceSettings()", result); 183cdf0e10cSrcweir } 184cdf0e10cSrcweir _removeSettings()185cdf0e10cSrcweir public void _removeSettings() { 186cdf0e10cSrcweir requiredMethod("insertSettings()"); 187cdf0e10cSrcweir boolean result = true; 188cdf0e10cSrcweir try { 189cdf0e10cSrcweir oObj.removeSettings(msMyResourceUrl); 190cdf0e10cSrcweir } 191cdf0e10cSrcweir catch(com.sun.star.container.NoSuchElementException e) { 192cdf0e10cSrcweir result = false; 193cdf0e10cSrcweir e.printStackTrace(log); 194cdf0e10cSrcweir } 195cdf0e10cSrcweir catch(com.sun.star.lang.IllegalArgumentException e) { 196cdf0e10cSrcweir result = false; 197cdf0e10cSrcweir e.printStackTrace(log); 198cdf0e10cSrcweir } 199cdf0e10cSrcweir catch(com.sun.star.lang.IllegalAccessException e) { 200cdf0e10cSrcweir e.printStackTrace(log); 201cdf0e10cSrcweir result = false; 202cdf0e10cSrcweir } 203cdf0e10cSrcweir tRes.tested("removeSettings()", result); 204cdf0e10cSrcweir } 205cdf0e10cSrcweir _insertSettings()206cdf0e10cSrcweir public void _insertSettings() { 207cdf0e10cSrcweir requiredMethod("createSettings()"); 208cdf0e10cSrcweir requiredMethod("replaceSettings()"); 209cdf0e10cSrcweir boolean result = true; 210cdf0e10cSrcweir util.dbg.printInterfaces(mxSettings); 211cdf0e10cSrcweir PropertyValue[] prop = createMenuBarEntry("A new entry", mxSettings, mxMSF, log); 212cdf0e10cSrcweir if (prop == null) { 213cdf0e10cSrcweir tRes.tested("replaceSettings()", false); 214cdf0e10cSrcweir return; 215cdf0e10cSrcweir } 216cdf0e10cSrcweir 217cdf0e10cSrcweir createMenuBarItem("A new sub entry", (XIndexContainer)UnoRuntime.queryInterface( 218cdf0e10cSrcweir XIndexContainer.class, prop[3].Value), log); 219cdf0e10cSrcweir 220cdf0e10cSrcweir XIndexContainer x = (XIndexContainer)UnoRuntime.queryInterface(XIndexContainer.class,mxSettings); 221cdf0e10cSrcweir try { 222cdf0e10cSrcweir int count = x.getCount(); 223cdf0e10cSrcweir x.insertByIndex(count, prop); 224cdf0e10cSrcweir } 225cdf0e10cSrcweir catch(com.sun.star.lang.IllegalArgumentException e) { 226cdf0e10cSrcweir result = false; 227cdf0e10cSrcweir e.printStackTrace(log); 228cdf0e10cSrcweir } 229cdf0e10cSrcweir catch(com.sun.star.lang.IndexOutOfBoundsException e) { 230cdf0e10cSrcweir result = false; 231cdf0e10cSrcweir e.printStackTrace(log); 232cdf0e10cSrcweir } 233cdf0e10cSrcweir catch(com.sun.star.lang.WrappedTargetException e) { 234cdf0e10cSrcweir result = false; 235cdf0e10cSrcweir e.printStackTrace(log); 236cdf0e10cSrcweir } 237cdf0e10cSrcweir 238cdf0e10cSrcweir try { 239cdf0e10cSrcweir oObj.insertSettings(msMyResourceUrl, mxSettings); 240cdf0e10cSrcweir } 241cdf0e10cSrcweir catch(com.sun.star.container.ElementExistException e) { 242cdf0e10cSrcweir e.printStackTrace(log); 243cdf0e10cSrcweir result = false; 244cdf0e10cSrcweir } 245cdf0e10cSrcweir catch(com.sun.star.lang.IllegalArgumentException e) { 246cdf0e10cSrcweir e.printStackTrace(log); 247cdf0e10cSrcweir result = false; 248cdf0e10cSrcweir } 249cdf0e10cSrcweir catch(com.sun.star.lang.IllegalAccessException e) { 250cdf0e10cSrcweir e.printStackTrace(log); 251cdf0e10cSrcweir result = false; 252cdf0e10cSrcweir } 253cdf0e10cSrcweir tRes.tested("insertSettings()", result); 254cdf0e10cSrcweir } 255cdf0e10cSrcweir 256cdf0e10cSrcweir /** 257cdf0e10cSrcweir * Only a short test. 258cdf0e10cSrcweir * See complex.imageManager.CheckImageManager for a more extensive test of 259cdf0e10cSrcweir * this implementation. 260cdf0e10cSrcweir */ _getImageManager()261cdf0e10cSrcweir public void _getImageManager() { 262cdf0e10cSrcweir Object o = oObj.getImageManager(); 263cdf0e10cSrcweir log.println("###### ImageManager "); 264cdf0e10cSrcweir XImageManager xImageManager = (XImageManager)UnoRuntime.queryInterface(XImageManager.class, o); 265cdf0e10cSrcweir tRes.tested("getImageManager()", xImageManager != null); 266cdf0e10cSrcweir } 267cdf0e10cSrcweir 268cdf0e10cSrcweir 269cdf0e10cSrcweir /** 270cdf0e10cSrcweir * get a shortcut manager 271cdf0e10cSrcweir */ _getShortCutManager()272cdf0e10cSrcweir public void _getShortCutManager() { 273cdf0e10cSrcweir Object o = oObj.getShortCutManager(); 274cdf0e10cSrcweir XServiceInfo xSI = (XServiceInfo)UnoRuntime.queryInterface(XServiceInfo.class,o); 275cdf0e10cSrcweir String[] serviceNames = xSI.getSupportedServiceNames(); 276cdf0e10cSrcweir boolean bSupportedServiceFound = false; 277cdf0e10cSrcweir for (int i=0; i<serviceNames.length; i++) { 278cdf0e10cSrcweir log.println("SuppService: " + serviceNames[i]); 279cdf0e10cSrcweir if (serviceNames[i].equals(sShortCutManagerServiceName)) { 280cdf0e10cSrcweir bSupportedServiceFound = true; 281cdf0e10cSrcweir } 282cdf0e10cSrcweir } 283cdf0e10cSrcweir tRes.tested("getShortCutManager()", bSupportedServiceFound); 284cdf0e10cSrcweir } 285cdf0e10cSrcweir _getEventsManager()286cdf0e10cSrcweir public void _getEventsManager() { 287cdf0e10cSrcweir Object o = oObj.getEventsManager(); 288cdf0e10cSrcweir tRes.tested("getEventsManager()", o == null); 289cdf0e10cSrcweir } 290cdf0e10cSrcweir 291cdf0e10cSrcweir /** 292cdf0e10cSrcweir * Create a menu bar entry for adding to the menu bar of the Office. 293cdf0e10cSrcweir * @param sLabelName The name of the new entry. 294cdf0e10cSrcweir * @param xMenuBarSettings The existing menu bar settings, used for creating the new entry. 295cdf0e10cSrcweir * @return An array of properties of the new entry. 296cdf0e10cSrcweir */ createMenuBarEntry(String sLabelName, XIndexAccess xMenuBarSettings, XMultiServiceFactory xMSF, PrintWriter log)297cdf0e10cSrcweir public static PropertyValue[] createMenuBarEntry(String sLabelName, XIndexAccess xMenuBarSettings, XMultiServiceFactory xMSF, PrintWriter log) { 298cdf0e10cSrcweir PropertyValue[] prop = new PropertyValue[4]; 299cdf0e10cSrcweir prop[0] = new PropertyValue(); 300cdf0e10cSrcweir prop[0].Name = "CommandURL"; 301cdf0e10cSrcweir prop[0].Value = "vnd.openoffice.org:MyMenu"; 302cdf0e10cSrcweir prop[1] = new PropertyValue(); 303cdf0e10cSrcweir prop[1].Name = "Label"; 304cdf0e10cSrcweir prop[1].Value = sLabelName; 305cdf0e10cSrcweir prop[2] = new PropertyValue(); 306cdf0e10cSrcweir prop[2].Name = "Type"; 307cdf0e10cSrcweir prop[2].Value = new Short((short)0); 308cdf0e10cSrcweir prop[3] = new PropertyValue(); 309cdf0e10cSrcweir prop[3].Name = "ItemDescriptorContainer"; 310cdf0e10cSrcweir 311cdf0e10cSrcweir XSingleComponentFactory xFactory = (XSingleComponentFactory)UnoRuntime.queryInterface( 312cdf0e10cSrcweir XSingleComponentFactory.class, xMenuBarSettings); 313cdf0e10cSrcweir try { 314cdf0e10cSrcweir XPropertySet xProp = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xMSF); 315cdf0e10cSrcweir XComponentContext xContext = (XComponentContext)UnoRuntime.queryInterface( 316cdf0e10cSrcweir XComponentContext.class, xProp.getPropertyValue("DefaultContext")); 317cdf0e10cSrcweir prop[3].Value = xFactory.createInstanceWithContext(xContext); 318cdf0e10cSrcweir } 319cdf0e10cSrcweir catch(com.sun.star.uno.Exception e) { 320cdf0e10cSrcweir log.println("Could not create an instance for ItemDescriptorContainer property."); 321cdf0e10cSrcweir e.printStackTrace(log); 322cdf0e10cSrcweir return null; 323cdf0e10cSrcweir } 324cdf0e10cSrcweir return prop; 325cdf0e10cSrcweir } 326cdf0e10cSrcweir 327cdf0e10cSrcweir /** 328cdf0e10cSrcweir * Create a sub entry to the menu bar. 329cdf0e10cSrcweir * @param sLabelName The name of the entry in the UI. 330cdf0e10cSrcweir * @param xDescriptionContainer The parent entry in the menu bar where 331cdf0e10cSrcweir * this entry is added. 332cdf0e10cSrcweir */ createMenuBarItem(String sLabelName, XIndexContainer xDescriptionContainer, PrintWriter log)333cdf0e10cSrcweir public static void createMenuBarItem(String sLabelName, XIndexContainer xDescriptionContainer, PrintWriter log) { 334cdf0e10cSrcweir PropertyValue[]aMenuItem = new PropertyValue[3]; 335cdf0e10cSrcweir // create a menu item 336cdf0e10cSrcweir aMenuItem[0] = new PropertyValue(); 337cdf0e10cSrcweir aMenuItem[0].Name = "CommandURL"; 338cdf0e10cSrcweir aMenuItem[0].Value = "macro:///Standard.Module1.Test()"; 339cdf0e10cSrcweir aMenuItem[1] = new PropertyValue(); 340cdf0e10cSrcweir aMenuItem[1].Name = "Label"; 341cdf0e10cSrcweir aMenuItem[1].Value = sLabelName; 342cdf0e10cSrcweir aMenuItem[2] = new PropertyValue(); 343cdf0e10cSrcweir aMenuItem[2].Name = "Type"; 344cdf0e10cSrcweir aMenuItem[2].Value = new Short((short)0); 345cdf0e10cSrcweir 346cdf0e10cSrcweir try { 347cdf0e10cSrcweir xDescriptionContainer.insertByIndex(0, aMenuItem); 348cdf0e10cSrcweir } 349cdf0e10cSrcweir catch(com.sun.star.lang.IllegalArgumentException e) { 350cdf0e10cSrcweir e.printStackTrace(log); 351cdf0e10cSrcweir } 352cdf0e10cSrcweir catch(com.sun.star.lang.IndexOutOfBoundsException e) { 353cdf0e10cSrcweir e.printStackTrace(log); 354cdf0e10cSrcweir } 355cdf0e10cSrcweir catch(com.sun.star.lang.WrappedTargetException e) { 356cdf0e10cSrcweir e.printStackTrace(log); 357cdf0e10cSrcweir } 358cdf0e10cSrcweir } 359cdf0e10cSrcweir } 360