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