1*76b6b121SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*76b6b121SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*76b6b121SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*76b6b121SAndrew Rist * distributed with this work for additional information 6*76b6b121SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*76b6b121SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*76b6b121SAndrew Rist * "License"); you may not use this file except in compliance 9*76b6b121SAndrew Rist * with the License. You may obtain a copy of the License at 10*76b6b121SAndrew Rist * 11*76b6b121SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*76b6b121SAndrew Rist * 13*76b6b121SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*76b6b121SAndrew Rist * software distributed under the License is distributed on an 15*76b6b121SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*76b6b121SAndrew Rist * KIND, either express or implied. See the License for the 17*76b6b121SAndrew Rist * specific language governing permissions and limitations 18*76b6b121SAndrew Rist * under the License. 19*76b6b121SAndrew Rist * 20*76b6b121SAndrew Rist *************************************************************/ 21*76b6b121SAndrew Rist 22*76b6b121SAndrew Rist 23cdf0e10cSrcweir package complex.accelerators; 24cdf0e10cSrcweir 25cdf0e10cSrcweir // imports 26cdf0e10cSrcweir import com.sun.star.awt.KeyEvent; 27cdf0e10cSrcweir import com.sun.star.beans.PropertyValue; 28cdf0e10cSrcweir import com.sun.star.beans.XPropertySet; 29cdf0e10cSrcweir import com.sun.star.container.XNameAccess; 30cdf0e10cSrcweir import com.sun.star.container.XNameContainer; 31cdf0e10cSrcweir import com.sun.star.embed.XStorage; 32cdf0e10cSrcweir import com.sun.star.embed.XTransactedObject; 33cdf0e10cSrcweir import com.sun.star.lang.XInitialization; 34cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 35cdf0e10cSrcweir import com.sun.star.lang.XSingleServiceFactory; 36cdf0e10cSrcweir import com.sun.star.ui.XAcceleratorConfiguration; 37cdf0e10cSrcweir import com.sun.star.ui.XUIConfigurationManager; 38cdf0e10cSrcweir import com.sun.star.ui.XUIConfigurationPersistence; 39cdf0e10cSrcweir import com.sun.star.ui.XUIConfigurationStorage; 40cdf0e10cSrcweir import com.sun.star.uno.AnyConverter; 41cdf0e10cSrcweir import com.sun.star.uno.XInterface; 42cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 43cdf0e10cSrcweir import com.sun.star.util.XChangesBatch; 44cdf0e10cSrcweir 45cdf0e10cSrcweir // import complex.accelerators.KeyMapping; 46cdf0e10cSrcweir 47cdf0e10cSrcweir 48cdf0e10cSrcweir // ---------- junit imports ----------------- 49cdf0e10cSrcweir import org.junit.After; 50cdf0e10cSrcweir import org.junit.AfterClass; 51cdf0e10cSrcweir import org.junit.Before; 52cdf0e10cSrcweir import org.junit.BeforeClass; 53cdf0e10cSrcweir import org.junit.Test; 54cdf0e10cSrcweir import org.openoffice.test.FileHelper; 55cdf0e10cSrcweir import org.openoffice.test.OfficeConnection; 56cdf0e10cSrcweir import static org.junit.Assert.*; 57cdf0e10cSrcweir // ------------------------------------------ 58cdf0e10cSrcweir //----------------------------------------------- 59cdf0e10cSrcweir 60cdf0e10cSrcweir /** @short todo document me 61cdf0e10cSrcweir */ 62cdf0e10cSrcweir public class AcceleratorsConfigurationTest 63cdf0e10cSrcweir { 64cdf0e10cSrcweir 65cdf0e10cSrcweir /** points to the global uno service manager. */ 66cdf0e10cSrcweir private XMultiServiceFactory m_xSmgr = null; 67cdf0e10cSrcweir /** the accelerator configuration for testing. */ 68cdf0e10cSrcweir private XAcceleratorConfiguration m_xGlobalAccelCfg = null; 69cdf0e10cSrcweir private XAcceleratorConfiguration m_xModuleAccelCfg = null; 70cdf0e10cSrcweir private XAcceleratorConfiguration m_xDocumentAccelCfg = null; 71cdf0e10cSrcweir /** XCS/XCU based accelerator configuration. */ 72cdf0e10cSrcweir private XNameAccess m_xConfig = null; 73cdf0e10cSrcweir private XNameAccess m_xPrimaryKeys = null; 74cdf0e10cSrcweir private XNameAccess m_xSecondaryKeys = null; 75cdf0e10cSrcweir 76cdf0e10cSrcweir //------------------------------------------- 77cdf0e10cSrcweir // test environment 78cdf0e10cSrcweir //----------------------------------------------- 79cdf0e10cSrcweir /** @short todo document me 80cdf0e10cSrcweir */ 81cdf0e10cSrcweir // public String[] getTestMethodNames() 82cdf0e10cSrcweir // { 83cdf0e10cSrcweir // return new String[] 84cdf0e10cSrcweir // { 85cdf0e10cSrcweir // "checkGlobalAccelCfg", 86cdf0e10cSrcweir // "checkModuleAccelCfg", 87cdf0e10cSrcweir // "checkDocumentAccelCfg" 88cdf0e10cSrcweir // }; 89cdf0e10cSrcweir // } 90cdf0e10cSrcweir //----------------------------------------------- 91cdf0e10cSrcweir /** @short Create the environment for following tests. 92cdf0e10cSrcweir */ 93cdf0e10cSrcweir @Before before()94cdf0e10cSrcweir public void before() 95cdf0e10cSrcweir throws java.lang.Exception 96cdf0e10cSrcweir { 97cdf0e10cSrcweir // get uno service manager from global test environment 98cdf0e10cSrcweir m_xSmgr = getMSF(); 99cdf0e10cSrcweir 100cdf0e10cSrcweir m_xGlobalAccelCfg = UnoRuntime.queryInterface(XAcceleratorConfiguration.class, m_xSmgr.createInstance("com.sun.star.ui.GlobalAcceleratorConfiguration")); 101cdf0e10cSrcweir m_xModuleAccelCfg = UnoRuntime.queryInterface(XAcceleratorConfiguration.class, m_xSmgr.createInstance("com.sun.star.ui.ModuleAcceleratorConfiguration")); 102cdf0e10cSrcweir m_xDocumentAccelCfg = UnoRuntime.queryInterface(XAcceleratorConfiguration.class, m_xSmgr.createInstance("com.sun.star.ui.DocumentAcceleratorConfiguration")); 103cdf0e10cSrcweir 104cdf0e10cSrcweir String sConfigPath = "org.openoffice.Office.Accelerators"; 105cdf0e10cSrcweir boolean bReadOnly = false; 106cdf0e10cSrcweir XNameAccess m_xConfig2 = openConfig(m_xSmgr, sConfigPath, bReadOnly); 107cdf0e10cSrcweir if (m_xConfig2 != null) 108cdf0e10cSrcweir { 109cdf0e10cSrcweir m_xPrimaryKeys = UnoRuntime.queryInterface(XNameAccess.class, m_xConfig2.getByName("PrimaryKeys")); 110cdf0e10cSrcweir m_xSecondaryKeys = UnoRuntime.queryInterface(XNameAccess.class, m_xConfig2.getByName("SecondaryKeys")); 111cdf0e10cSrcweir } 112cdf0e10cSrcweir } 113cdf0e10cSrcweir 114cdf0e10cSrcweir //------------------------------------------- 115cdf0e10cSrcweir /** @short close the environment. 116cdf0e10cSrcweir */ 117cdf0e10cSrcweir @After after()118cdf0e10cSrcweir public void after() 119cdf0e10cSrcweir throws java.lang.Exception 120cdf0e10cSrcweir { 121cdf0e10cSrcweir m_xConfig = null; 122cdf0e10cSrcweir m_xGlobalAccelCfg = null; 123cdf0e10cSrcweir m_xModuleAccelCfg = null; 124cdf0e10cSrcweir m_xDocumentAccelCfg = null; 125cdf0e10cSrcweir m_xSmgr = null; 126cdf0e10cSrcweir } 127cdf0e10cSrcweir 128cdf0e10cSrcweir //------------------------------------------- 129cdf0e10cSrcweir /** @todo document me. 130cdf0e10cSrcweir */ 131cdf0e10cSrcweir @Test checkGlobalAccelCfg()132cdf0e10cSrcweir public void checkGlobalAccelCfg() 133cdf0e10cSrcweir throws java.lang.Exception 134cdf0e10cSrcweir { 135cdf0e10cSrcweir System.out.println("\n---- check Global accelerator configuration: ----"); 136cdf0e10cSrcweir 137cdf0e10cSrcweir String[] sKeys; 138cdf0e10cSrcweir XNameAccess xPrimaryAccess = UnoRuntime.queryInterface(XNameAccess.class, m_xPrimaryKeys.getByName("Global")); 139cdf0e10cSrcweir XNameAccess xSecondaryAccess = UnoRuntime.queryInterface(XNameAccess.class, m_xSecondaryKeys.getByName("Global")); 140cdf0e10cSrcweir 141cdf0e10cSrcweir sKeys = new String[] 142cdf0e10cSrcweir { 143cdf0e10cSrcweir "A_MOD1" 144cdf0e10cSrcweir }; 145cdf0e10cSrcweir impl_checkGetKeyCommands(m_xGlobalAccelCfg, xPrimaryAccess, sKeys); 146cdf0e10cSrcweir 147cdf0e10cSrcweir sKeys = new String[] 148cdf0e10cSrcweir { 149cdf0e10cSrcweir "PASTE", "X_SHIFT" 150cdf0e10cSrcweir }; 151cdf0e10cSrcweir String[] sCommands = new String[] 152cdf0e10cSrcweir { 153cdf0e10cSrcweir ".uno:test", ".uno:test" 154cdf0e10cSrcweir }; 155cdf0e10cSrcweir impl_checkSetKeyCommands(m_xGlobalAccelCfg, xPrimaryAccess, xSecondaryAccess, sKeys, sCommands); 156cdf0e10cSrcweir 157cdf0e10cSrcweir sKeys = new String[] 158cdf0e10cSrcweir { 159cdf0e10cSrcweir "C_MOD1", "CUT" 160cdf0e10cSrcweir }; 161cdf0e10cSrcweir impl_checkRemoveKeyCommands(m_xGlobalAccelCfg, xPrimaryAccess, xSecondaryAccess, sKeys); 162cdf0e10cSrcweir 163cdf0e10cSrcweir String[] sCommandList = new String[] 164cdf0e10cSrcweir { 165cdf0e10cSrcweir ".uno:Paste", ".uno:CloseWin" 166cdf0e10cSrcweir }; 167cdf0e10cSrcweir impl_checkGetPreferredKeyEventsForCommandList(m_xGlobalAccelCfg, xPrimaryAccess, sCommandList); 168cdf0e10cSrcweir } 169cdf0e10cSrcweir 170cdf0e10cSrcweir //------------------------------------------- 171cdf0e10cSrcweir /** @todo document me. 172cdf0e10cSrcweir */ 173cdf0e10cSrcweir @Test checkModuleAccelCfg()174cdf0e10cSrcweir public void checkModuleAccelCfg() 175cdf0e10cSrcweir throws java.lang.Exception 176cdf0e10cSrcweir { 177cdf0e10cSrcweir String[] sModules = new String[] 178cdf0e10cSrcweir { 179cdf0e10cSrcweir "com.sun.star.frame.StartModule", 180cdf0e10cSrcweir "com.sun.star.drawing.DrawingDocument", 181cdf0e10cSrcweir "com.sun.star.presentation.PresentationDocument", 182cdf0e10cSrcweir "com.sun.star.sheet.SpreadsheetDocument", 183cdf0e10cSrcweir "com.sun.star.text.TextDocument", 184cdf0e10cSrcweir // add other modules here 185cdf0e10cSrcweir }; 186cdf0e10cSrcweir 187cdf0e10cSrcweir for (int i = 0; i < sModules.length; ++i) 188cdf0e10cSrcweir { 189cdf0e10cSrcweir System.out.println("\n---- check accelerator configuration depending module: " + sModules[i] + " ----"); 190cdf0e10cSrcweir 191cdf0e10cSrcweir PropertyValue[] aProp = new PropertyValue[2]; 192cdf0e10cSrcweir aProp[0] = new PropertyValue(); 193cdf0e10cSrcweir aProp[0].Name = "ModuleIdentifier"; 194cdf0e10cSrcweir aProp[0].Value = sModules[i]; 195cdf0e10cSrcweir aProp[1] = new PropertyValue(); 196cdf0e10cSrcweir aProp[1].Name = "Locale"; 197cdf0e10cSrcweir aProp[1].Value = "en-US"; 198cdf0e10cSrcweir 199cdf0e10cSrcweir XInitialization xInit = UnoRuntime.queryInterface(XInitialization.class, m_xModuleAccelCfg); 200cdf0e10cSrcweir xInit.initialize(aProp); // to fill cache 201cdf0e10cSrcweir 202cdf0e10cSrcweir XNameAccess xPrimaryModules = UnoRuntime.queryInterface(XNameAccess.class, m_xPrimaryKeys.getByName("Modules")); 203cdf0e10cSrcweir XNameAccess xSecondaryModules = UnoRuntime.queryInterface(XNameAccess.class, m_xSecondaryKeys.getByName("Modules")); 204cdf0e10cSrcweir 205cdf0e10cSrcweir String[] sKeys; 206cdf0e10cSrcweir XNameAccess xPrimaryAccess = UnoRuntime.queryInterface(XNameAccess.class, xPrimaryModules.getByName(sModules[i])); 207cdf0e10cSrcweir XNameAccess xSecondaryAccess = UnoRuntime.queryInterface(XNameAccess.class, xSecondaryModules.getByName(sModules[i])); 208cdf0e10cSrcweir 209cdf0e10cSrcweir //-------------------------------------------- 210cdf0e10cSrcweir if (sModules[i].equals("com.sun.star.presentation.PresentationDocument")) 211cdf0e10cSrcweir { 212cdf0e10cSrcweir sKeys = new String[] 213cdf0e10cSrcweir { 214cdf0e10cSrcweir "A_SHIFT_MOD1_MOD2" 215cdf0e10cSrcweir }; 216cdf0e10cSrcweir } 217cdf0e10cSrcweir else if (sModules[i].equals("com.sun.star.sheet.SpreadsheetDocument")) 218cdf0e10cSrcweir { 219cdf0e10cSrcweir sKeys = new String[] 220cdf0e10cSrcweir { 221cdf0e10cSrcweir "B_MOD1" 222cdf0e10cSrcweir }; 223cdf0e10cSrcweir } 224cdf0e10cSrcweir else if (sModules[i].equals("com.sun.star.text.TextDocument")) 225cdf0e10cSrcweir { 226cdf0e10cSrcweir sKeys = new String[] 227cdf0e10cSrcweir { 228cdf0e10cSrcweir "F11_MOD1" 229cdf0e10cSrcweir }; 230cdf0e10cSrcweir } 231cdf0e10cSrcweir else 232cdf0e10cSrcweir { 233cdf0e10cSrcweir sKeys = new String[] 234cdf0e10cSrcweir { 235cdf0e10cSrcweir "A_MOD1" 236cdf0e10cSrcweir }; 237cdf0e10cSrcweir } 238cdf0e10cSrcweir impl_checkGetKeyCommands(m_xModuleAccelCfg, xPrimaryAccess, sKeys); 239cdf0e10cSrcweir 240cdf0e10cSrcweir //-------------------------------------------- 241cdf0e10cSrcweir String[] sCommands; 242cdf0e10cSrcweir if (sModules[i].equals("com.sun.star.presentation.PresentationDocument")) 243cdf0e10cSrcweir { 244cdf0e10cSrcweir sKeys = new String[] 245cdf0e10cSrcweir { 246cdf0e10cSrcweir "A_SHIFT_MOD1_MOD2" 247cdf0e10cSrcweir }; 248cdf0e10cSrcweir sCommands = new String[] 249cdf0e10cSrcweir { 250cdf0e10cSrcweir ".uno:test" 251cdf0e10cSrcweir }; 252cdf0e10cSrcweir } 253cdf0e10cSrcweir else if (sModules[i].equals("com.sun.star.sheet.SpreadsheetDocument")) 254cdf0e10cSrcweir { 255cdf0e10cSrcweir sKeys = new String[] 256cdf0e10cSrcweir { 257cdf0e10cSrcweir "B_MOD1" 258cdf0e10cSrcweir }; 259cdf0e10cSrcweir sCommands = new String[] 260cdf0e10cSrcweir { 261cdf0e10cSrcweir ".uno:test" 262cdf0e10cSrcweir }; 263cdf0e10cSrcweir } 264cdf0e10cSrcweir else if (sModules[i].equals("com.sun.star.text.TextDocument")) 265cdf0e10cSrcweir { 266cdf0e10cSrcweir sKeys = new String[] 267cdf0e10cSrcweir { 268cdf0e10cSrcweir "F11_MOD1" 269cdf0e10cSrcweir }; 270cdf0e10cSrcweir sCommands = new String[] 271cdf0e10cSrcweir { 272cdf0e10cSrcweir ".uno:test" 273cdf0e10cSrcweir }; 274cdf0e10cSrcweir } 275cdf0e10cSrcweir else 276cdf0e10cSrcweir { 277cdf0e10cSrcweir sKeys = new String[] 278cdf0e10cSrcweir { 279cdf0e10cSrcweir "PASTE" 280cdf0e10cSrcweir }; 281cdf0e10cSrcweir sCommands = new String[] 282cdf0e10cSrcweir { 283cdf0e10cSrcweir ".uno:test" 284cdf0e10cSrcweir }; 285cdf0e10cSrcweir } 286cdf0e10cSrcweir impl_checkSetKeyCommands(m_xModuleAccelCfg, xPrimaryAccess, xSecondaryAccess, sKeys, sCommands); 287cdf0e10cSrcweir 288cdf0e10cSrcweir //-------------------------------------------- 289cdf0e10cSrcweir if (sModules[i].equals("com.sun.star.presentation.PresentationDocument")) 290cdf0e10cSrcweir { 291cdf0e10cSrcweir sKeys = new String[] 292cdf0e10cSrcweir { 293cdf0e10cSrcweir "A_SHIFT_MOD1_MOD2" 294cdf0e10cSrcweir }; 295cdf0e10cSrcweir } 296cdf0e10cSrcweir else if (sModules[i].equals("com.sun.star.sheet.SpreadsheetDocument")) 297cdf0e10cSrcweir { 298cdf0e10cSrcweir sKeys = new String[] 299cdf0e10cSrcweir { 300cdf0e10cSrcweir "F5_SHIFT_MOD1" 301cdf0e10cSrcweir }; 302cdf0e10cSrcweir } 303cdf0e10cSrcweir else if (sModules[i].equals("com.sun.star.text.TextDocument")) 304cdf0e10cSrcweir { 305cdf0e10cSrcweir sKeys = new String[] 306cdf0e10cSrcweir { 307cdf0e10cSrcweir "BACKSPACE_MOD2" 308cdf0e10cSrcweir }; 309cdf0e10cSrcweir } 310cdf0e10cSrcweir else 311cdf0e10cSrcweir { 312cdf0e10cSrcweir sKeys = new String[] 313cdf0e10cSrcweir { 314cdf0e10cSrcweir "C_MOD1" 315cdf0e10cSrcweir }; 316cdf0e10cSrcweir } 317cdf0e10cSrcweir impl_checkRemoveKeyCommands(m_xModuleAccelCfg, xPrimaryAccess, xSecondaryAccess, sKeys); 318cdf0e10cSrcweir 319cdf0e10cSrcweir //-------------------------------------------- 320cdf0e10cSrcweir String[] sCommandList; 321cdf0e10cSrcweir if (sModules[i].equals("com.sun.star.presentation.PresentationDocument")) 322cdf0e10cSrcweir { 323cdf0e10cSrcweir sCommandList = new String[] 324cdf0e10cSrcweir { 325cdf0e10cSrcweir ".uno:Presentation" 326cdf0e10cSrcweir }; 327cdf0e10cSrcweir } 328cdf0e10cSrcweir else if (sModules[i].equals("com.sun.star.sheet.SpreadsheetDocument")) 329cdf0e10cSrcweir { 330cdf0e10cSrcweir sCommandList = new String[] 331cdf0e10cSrcweir { 332cdf0e10cSrcweir ".uno:InsertCell" 333cdf0e10cSrcweir }; 334cdf0e10cSrcweir } 335cdf0e10cSrcweir else if (sModules[i].equals("com.sun.star.text.TextDocument")) 336cdf0e10cSrcweir { 337cdf0e10cSrcweir sCommandList = new String[] 338cdf0e10cSrcweir { 339cdf0e10cSrcweir ".uno:SelectionModeBlock" 340cdf0e10cSrcweir }; 341cdf0e10cSrcweir } 342cdf0e10cSrcweir else 343cdf0e10cSrcweir { 344cdf0e10cSrcweir sCommandList = new String[] 345cdf0e10cSrcweir { 346cdf0e10cSrcweir ".uno:Cut" 347cdf0e10cSrcweir }; 348cdf0e10cSrcweir } 349cdf0e10cSrcweir impl_checkGetPreferredKeyEventsForCommandList(m_xModuleAccelCfg, xPrimaryAccess, sCommandList); 350cdf0e10cSrcweir } 351cdf0e10cSrcweir } 352cdf0e10cSrcweir 353cdf0e10cSrcweir //------------------------------------------- 354cdf0e10cSrcweir /** @todo document me. 355cdf0e10cSrcweir */ 356cdf0e10cSrcweir @Test checkDocumentAccelCfg()357cdf0e10cSrcweir public void checkDocumentAccelCfg() 358cdf0e10cSrcweir throws java.lang.Exception 359cdf0e10cSrcweir { 360cdf0e10cSrcweir System.out.println("\n---- check Document accelerator configuration: ----"); 361cdf0e10cSrcweir 362cdf0e10cSrcweir String sDocCfgName; 363cdf0e10cSrcweir 364cdf0e10cSrcweir String tempDirURL = util.utils.getOfficeTemp/*Dir*/(getMSF()); 365cdf0e10cSrcweir sDocCfgName = FileHelper.appendPath(tempDirURL, "test.cfg"); 366cdf0e10cSrcweir // sDocCfgName = "file:///c:/test.cfg"; 367cdf0e10cSrcweir SaveDocumentAcceleratorConfiguration(sDocCfgName); 368cdf0e10cSrcweir 369cdf0e10cSrcweir // sDocCfgName = "file:///c:/test.cfg"; 370cdf0e10cSrcweir LoadDocumentAcceleratorConfiguration(sDocCfgName); 371cdf0e10cSrcweir } 372cdf0e10cSrcweir 373cdf0e10cSrcweir //------------------------------------------- 374cdf0e10cSrcweir /** @todo document me. 375cdf0e10cSrcweir */ impl_checkGetKeyCommands(XAcceleratorConfiguration xAccelCfg, XNameAccess xAccess, String[] sKeys)376cdf0e10cSrcweir private void impl_checkGetKeyCommands(XAcceleratorConfiguration xAccelCfg, XNameAccess xAccess, String[] sKeys) 377cdf0e10cSrcweir throws java.lang.Exception 378cdf0e10cSrcweir { 379cdf0e10cSrcweir System.out.println("check getKeyCommands..."); 380cdf0e10cSrcweir 381cdf0e10cSrcweir for (int i = 0; i < sKeys.length; ++i) 382cdf0e10cSrcweir { 383cdf0e10cSrcweir if (xAccess.hasByName(sKeys[i]) && getCommandFromConfiguration(xAccess, sKeys[i]).length() > 0) 384cdf0e10cSrcweir { 385cdf0e10cSrcweir System.out.println("** get command by " + sKeys[i] + " **"); 386cdf0e10cSrcweir 387cdf0e10cSrcweir String sCmdFromCache = new String(); // get a value using XAcceleratorConfiguration API 388cdf0e10cSrcweir String sCmdFromConfiguration = new String(); // get a value using configuration API 389cdf0e10cSrcweir 390cdf0e10cSrcweir // GET shortcuts/commands using XAcceleratorConfiguration API 391cdf0e10cSrcweir sCmdFromCache = xAccelCfg.getCommandByKeyEvent(convertShortcut2AWTKey(sKeys[i])); 392cdf0e10cSrcweir System.out.println(sKeys[i] + "-->" + sCmdFromCache + ", by XAcceleratorConfiguration API"); 393cdf0e10cSrcweir 394cdf0e10cSrcweir // GET shortcuts/commands using configuration API 395cdf0e10cSrcweir sCmdFromConfiguration = getCommandFromConfiguration(xAccess, sKeys[i]); 396cdf0e10cSrcweir System.out.println(sKeys[i] + "-->" + sCmdFromConfiguration + ", by configuration API"); 397cdf0e10cSrcweir 398cdf0e10cSrcweir assertTrue("values are different by XAcceleratorConfiguration API and configuration API!", sCmdFromCache.equals(sCmdFromConfiguration)); 399cdf0e10cSrcweir 400cdf0e10cSrcweir String sLocale = "es"; 401cdf0e10cSrcweir setOfficeLocale(sLocale); 402cdf0e10cSrcweir sCmdFromConfiguration = getCommandFromConfiguration(xAccess, sKeys[i]); 403cdf0e10cSrcweir System.out.println(sKeys[i] + "-->" + sCmdFromConfiguration + ", by configuration API" + " for locale:" + getOfficeLocale()); 404cdf0e10cSrcweir 405cdf0e10cSrcweir sLocale = "en-US"; 406cdf0e10cSrcweir setOfficeLocale(sLocale); //reset to default locale 407cdf0e10cSrcweir } 408cdf0e10cSrcweir else 409cdf0e10cSrcweir { 410cdf0e10cSrcweir System.out.println(sKeys[i] + " doesn't exist!"); 411cdf0e10cSrcweir } 412cdf0e10cSrcweir } 413cdf0e10cSrcweir } 414cdf0e10cSrcweir 415cdf0e10cSrcweir //------------------------------------------- 416cdf0e10cSrcweir /** @todo document me. 417cdf0e10cSrcweir */ impl_checkSetKeyCommands(XAcceleratorConfiguration xAccelCfg, XNameAccess xPrimaryAccess, XNameAccess xSecondaryAccess, String[] sKeys, String[] sCommands)418cdf0e10cSrcweir private void impl_checkSetKeyCommands(XAcceleratorConfiguration xAccelCfg, XNameAccess xPrimaryAccess, XNameAccess xSecondaryAccess, String[] sKeys, String[] sCommands) 419cdf0e10cSrcweir throws java.lang.Exception 420cdf0e10cSrcweir { 421cdf0e10cSrcweir System.out.println("check setKeyCommands..."); 422cdf0e10cSrcweir 423cdf0e10cSrcweir for (int i = 0; i < sKeys.length; ++i) 424cdf0e10cSrcweir { 425cdf0e10cSrcweir if (!xPrimaryAccess.hasByName(sKeys[i]) && !xSecondaryAccess.hasByName(sKeys[i])) 426cdf0e10cSrcweir { 427cdf0e10cSrcweir xAccelCfg.setKeyEvent(convertShortcut2AWTKey(sKeys[i]), sCommands[i]); 428cdf0e10cSrcweir xAccelCfg.store(); 429cdf0e10cSrcweir if (xPrimaryAccess.hasByName(sKeys[i])) 430cdf0e10cSrcweir { 431cdf0e10cSrcweir System.out.println("add " + sKeys[i] + " successfully!"); 432cdf0e10cSrcweir } 433cdf0e10cSrcweir else 434cdf0e10cSrcweir { 435cdf0e10cSrcweir System.out.println("add " + sKeys[i] + " failed!"); 436cdf0e10cSrcweir } 437cdf0e10cSrcweir } 438cdf0e10cSrcweir else if (xPrimaryAccess.hasByName(sKeys[i])) 439cdf0e10cSrcweir { 440cdf0e10cSrcweir String sOriginalCommand = getCommandFromConfiguration(xPrimaryAccess, sKeys[i]); 441cdf0e10cSrcweir if (!sCommands[i].equals(sOriginalCommand)) 442cdf0e10cSrcweir { 443cdf0e10cSrcweir xAccelCfg.setKeyEvent(convertShortcut2AWTKey(sKeys[i]), sCommands[i]); 444cdf0e10cSrcweir xAccelCfg.store(); 445cdf0e10cSrcweir 446cdf0e10cSrcweir String sChangedCommand = getCommandFromConfiguration(xPrimaryAccess, sKeys[i]); 447cdf0e10cSrcweir if (sCommands[i].equals(sChangedCommand)) 448cdf0e10cSrcweir { 449cdf0e10cSrcweir System.out.println("change " + sKeys[i] + " successfully!"); 450cdf0e10cSrcweir } 451cdf0e10cSrcweir else 452cdf0e10cSrcweir { 453cdf0e10cSrcweir System.out.println("change " + sKeys[i] + " failed!"); 454cdf0e10cSrcweir } 455cdf0e10cSrcweir } 456cdf0e10cSrcweir else 457cdf0e10cSrcweir { 458cdf0e10cSrcweir System.out.println(sKeys[i] + " already exist!"); 459cdf0e10cSrcweir } 460cdf0e10cSrcweir } 461cdf0e10cSrcweir else if (xSecondaryAccess.hasByName(sKeys[i])) 462cdf0e10cSrcweir { 463cdf0e10cSrcweir String sOriginalCommand = getCommandFromConfiguration(xSecondaryAccess, sKeys[i]); 464cdf0e10cSrcweir if (!sCommands[i].equals(sOriginalCommand)) 465cdf0e10cSrcweir { 466cdf0e10cSrcweir xAccelCfg.setKeyEvent(convertShortcut2AWTKey(sKeys[i]), sCommands[i]); 467cdf0e10cSrcweir xAccelCfg.store(); 468cdf0e10cSrcweir 469cdf0e10cSrcweir String sChangedCommand = getCommandFromConfiguration(xPrimaryAccess, sKeys[i]); 470cdf0e10cSrcweir if (sCommands[i].equals(sChangedCommand)) 471cdf0e10cSrcweir { 472cdf0e10cSrcweir System.out.println("change " + sKeys[i] + " successfully!"); 473cdf0e10cSrcweir } 474cdf0e10cSrcweir else 475cdf0e10cSrcweir { 476cdf0e10cSrcweir System.out.println("change " + sKeys[i] + " failed!"); 477cdf0e10cSrcweir } 478cdf0e10cSrcweir } 479cdf0e10cSrcweir else 480cdf0e10cSrcweir { 481cdf0e10cSrcweir System.out.println(sKeys[i] + " already exist!"); 482cdf0e10cSrcweir } 483cdf0e10cSrcweir } 484cdf0e10cSrcweir } 485cdf0e10cSrcweir } 486cdf0e10cSrcweir 487cdf0e10cSrcweir //------------------------------------------- 488cdf0e10cSrcweir /** @todo document me. 489cdf0e10cSrcweir */ impl_checkRemoveKeyCommands(XAcceleratorConfiguration xAccelCfg, XNameAccess xPrimaryAccess, XNameAccess xSecondaryAccess, String[] sKeys)490cdf0e10cSrcweir private void impl_checkRemoveKeyCommands(XAcceleratorConfiguration xAccelCfg, XNameAccess xPrimaryAccess, XNameAccess xSecondaryAccess, String[] sKeys) 491cdf0e10cSrcweir throws java.lang.Exception 492cdf0e10cSrcweir { 493cdf0e10cSrcweir System.out.println("check removeKeyCommands..."); 494cdf0e10cSrcweir 495cdf0e10cSrcweir for (int i = 0; i < sKeys.length; i++) 496cdf0e10cSrcweir { 497cdf0e10cSrcweir if (!xPrimaryAccess.hasByName(sKeys[i]) && !xSecondaryAccess.hasByName(sKeys[i])) 498cdf0e10cSrcweir { 499cdf0e10cSrcweir System.out.println(sKeys[i] + " doesn't exist!"); 500cdf0e10cSrcweir } 501cdf0e10cSrcweir else if (xPrimaryAccess.hasByName(sKeys[i])) 502cdf0e10cSrcweir { 503cdf0e10cSrcweir xAccelCfg.removeKeyEvent(convertShortcut2AWTKey(sKeys[i])); 504cdf0e10cSrcweir xAccelCfg.store(); 505cdf0e10cSrcweir if (!xPrimaryAccess.hasByName(sKeys[i])) 506cdf0e10cSrcweir { 507cdf0e10cSrcweir System.out.println("Remove " + sKeys[i] + " successfully!"); 508cdf0e10cSrcweir } 509cdf0e10cSrcweir else 510cdf0e10cSrcweir { 511cdf0e10cSrcweir System.out.println("Remove " + sKeys[i] + " failed!"); 512cdf0e10cSrcweir } 513cdf0e10cSrcweir } 514cdf0e10cSrcweir else if (xSecondaryAccess.hasByName(sKeys[i])) 515cdf0e10cSrcweir { 516cdf0e10cSrcweir xAccelCfg.removeKeyEvent(convertShortcut2AWTKey(sKeys[i])); 517cdf0e10cSrcweir xAccelCfg.store(); 518cdf0e10cSrcweir if (!xSecondaryAccess.hasByName(sKeys[i])) 519cdf0e10cSrcweir { 520cdf0e10cSrcweir System.out.println("Remove " + sKeys[i] + " successfully!"); 521cdf0e10cSrcweir } 522cdf0e10cSrcweir else 523cdf0e10cSrcweir { 524cdf0e10cSrcweir System.out.println("Remove " + sKeys[i] + " failed!"); 525cdf0e10cSrcweir } 526cdf0e10cSrcweir } 527cdf0e10cSrcweir } 528cdf0e10cSrcweir } 529cdf0e10cSrcweir 530cdf0e10cSrcweir //------------------------------------------- 531cdf0e10cSrcweir /** @todo document me. 532cdf0e10cSrcweir */ impl_checkGetPreferredKeyEventsForCommandList(XAcceleratorConfiguration xAccelCfg, XNameAccess xPrimaryAccess, String[] sCommandList)533cdf0e10cSrcweir private void impl_checkGetPreferredKeyEventsForCommandList(XAcceleratorConfiguration xAccelCfg, XNameAccess xPrimaryAccess, String[] sCommandList) 534cdf0e10cSrcweir throws java.lang.Exception 535cdf0e10cSrcweir { 536cdf0e10cSrcweir System.out.println("check getPreferredKeyEventsForCommandList..."); 537cdf0e10cSrcweir 538cdf0e10cSrcweir Object[] oKeyEvents = xAccelCfg.getPreferredKeyEventsForCommandList(sCommandList); 539cdf0e10cSrcweir for (int i = 0; i < oKeyEvents.length; i++) 540cdf0e10cSrcweir { 541cdf0e10cSrcweir System.out.println("get preferred key for command " + sCommandList[i] + ":"); 542cdf0e10cSrcweir 543cdf0e10cSrcweir KeyEvent aKeyEvent = (KeyEvent) AnyConverter.toObject(KeyEvent.class, oKeyEvents[i]); 544cdf0e10cSrcweir String sKeyEvent = convertAWTKey2Shortcut(aKeyEvent); 545cdf0e10cSrcweir System.out.println(sKeyEvent); 546cdf0e10cSrcweir 547cdf0e10cSrcweir String sCmdFromConfiguration = getCommandFromConfiguration(xPrimaryAccess, sKeyEvent); 548cdf0e10cSrcweir System.out.println(sCmdFromConfiguration); 549cdf0e10cSrcweir if (sCommandList[i].equals(sCmdFromConfiguration)) 550cdf0e10cSrcweir { 551cdf0e10cSrcweir System.out.println("get preferred key correctly!"); 552cdf0e10cSrcweir } 553cdf0e10cSrcweir else 554cdf0e10cSrcweir { 555cdf0e10cSrcweir System.out.println("get preferred key failed!"); 556cdf0e10cSrcweir } 557cdf0e10cSrcweir } 558cdf0e10cSrcweir } 559cdf0e10cSrcweir 560cdf0e10cSrcweir //------------------------------------------- 561cdf0e10cSrcweir /** @todo document me. 562cdf0e10cSrcweir */ getCommandFromConfiguration(XNameAccess xAccess, String sKey)563cdf0e10cSrcweir private String getCommandFromConfiguration(XNameAccess xAccess, String sKey) 564cdf0e10cSrcweir throws java.lang.Exception 565cdf0e10cSrcweir { 566cdf0e10cSrcweir String sCommand = new String(); 567cdf0e10cSrcweir 568cdf0e10cSrcweir if (xAccess.hasByName(sKey)) 569cdf0e10cSrcweir { 570cdf0e10cSrcweir XNameAccess xKey = UnoRuntime.queryInterface(XNameAccess.class, xAccess.getByName(sKey)); 571cdf0e10cSrcweir XNameAccess xCommand = UnoRuntime.queryInterface(XNameAccess.class, xKey.getByName("Command")); 572cdf0e10cSrcweir 573cdf0e10cSrcweir String sLocale = getOfficeLocale(); 574cdf0e10cSrcweir if (xCommand.hasByName(sLocale)) 575cdf0e10cSrcweir { 576cdf0e10cSrcweir sCommand = UnoRuntime.queryInterface(String.class, xCommand.getByName(sLocale)); 577cdf0e10cSrcweir } 578cdf0e10cSrcweir } 579cdf0e10cSrcweir 580cdf0e10cSrcweir return sCommand; 581cdf0e10cSrcweir } 582cdf0e10cSrcweir 583cdf0e10cSrcweir //------------------------------------------- 584cdf0e10cSrcweir /** @todo document me. 585cdf0e10cSrcweir */ insertKeyToConfiguration(XNameAccess xAccess, String sKey, String sCommand)586cdf0e10cSrcweir private void insertKeyToConfiguration(XNameAccess xAccess, String sKey, String sCommand) 587cdf0e10cSrcweir throws java.lang.Exception 588cdf0e10cSrcweir { 589cdf0e10cSrcweir XNameContainer xContainer = UnoRuntime.queryInterface(XNameContainer.class, xAccess); 590cdf0e10cSrcweir if (!xContainer.hasByName(sKey)) 591cdf0e10cSrcweir { 592cdf0e10cSrcweir XSingleServiceFactory xFac = UnoRuntime.queryInterface(XSingleServiceFactory.class, xContainer); 593cdf0e10cSrcweir XInterface xInst = UnoRuntime.queryInterface(XInterface.class, xFac.createInstance()); 594cdf0e10cSrcweir xContainer.insertByName(sKey, xInst); 595cdf0e10cSrcweir } 596cdf0e10cSrcweir 597cdf0e10cSrcweir XNameAccess xKey = UnoRuntime.queryInterface(XNameAccess.class, xContainer.getByName(sKey)); 598cdf0e10cSrcweir XNameContainer xCommand = UnoRuntime.queryInterface(XNameContainer.class, xKey.getByName("Command")); 599cdf0e10cSrcweir String sLocale = getOfficeLocale(); 600cdf0e10cSrcweir if (xCommand.hasByName(sLocale)) 601cdf0e10cSrcweir { 602cdf0e10cSrcweir xCommand.insertByName(sLocale, sCommand); 603cdf0e10cSrcweir } 604cdf0e10cSrcweir else 605cdf0e10cSrcweir { 606cdf0e10cSrcweir xCommand.replaceByName(sLocale, sCommand); 607cdf0e10cSrcweir } 608cdf0e10cSrcweir } 609cdf0e10cSrcweir 610cdf0e10cSrcweir //------------------------------------------- 611cdf0e10cSrcweir /** @todo document me. 612cdf0e10cSrcweir */ removeKeyFromConfiguration(XNameAccess xAccess, String sKey)613cdf0e10cSrcweir private void removeKeyFromConfiguration(XNameAccess xAccess, String sKey) 614cdf0e10cSrcweir throws java.lang.Exception 615cdf0e10cSrcweir { 616cdf0e10cSrcweir XNameContainer xContainer = UnoRuntime.queryInterface(XNameContainer.class, xAccess); 617cdf0e10cSrcweir if (xContainer.hasByName(sKey)) 618cdf0e10cSrcweir { 619cdf0e10cSrcweir xContainer.removeByName(sKey); 620cdf0e10cSrcweir } 621cdf0e10cSrcweir } 622cdf0e10cSrcweir 623cdf0e10cSrcweir //------------------------------------------- 624cdf0e10cSrcweir /** @todo document me. 625cdf0e10cSrcweir */ LoadDocumentAcceleratorConfiguration(String sDocCfgName)626cdf0e10cSrcweir private void LoadDocumentAcceleratorConfiguration(String sDocCfgName) 627cdf0e10cSrcweir throws java.lang.Exception 628cdf0e10cSrcweir { 629cdf0e10cSrcweir XSingleServiceFactory xStorageFactory = UnoRuntime.queryInterface(XSingleServiceFactory.class, m_xSmgr.createInstance("com.sun.star.embed.StorageFactory")); 630cdf0e10cSrcweir 631cdf0e10cSrcweir Object aArgs[] = new Object[2]; 632cdf0e10cSrcweir aArgs[0] = sDocCfgName; 633cdf0e10cSrcweir aArgs[1] = new Integer(com.sun.star.embed.ElementModes.READ); 634cdf0e10cSrcweir XStorage xRootStorage = UnoRuntime.queryInterface(XStorage.class, xStorageFactory.createInstanceWithArguments(aArgs)); 635cdf0e10cSrcweir 636cdf0e10cSrcweir XStorage xUIConfig = xRootStorage.openStorageElement("Configurations2", com.sun.star.embed.ElementModes.READ); 637cdf0e10cSrcweir 638cdf0e10cSrcweir PropertyValue aProp = new PropertyValue(); 639cdf0e10cSrcweir aProp.Name = "DocumentRoot"; 640cdf0e10cSrcweir aProp.Value = xUIConfig; 641cdf0e10cSrcweir Object[] lArgs = new Object[1]; 642cdf0e10cSrcweir lArgs[0] = aProp; 643cdf0e10cSrcweir 644cdf0e10cSrcweir XInitialization xInit = UnoRuntime.queryInterface(XInitialization.class, m_xDocumentAccelCfg); 645cdf0e10cSrcweir xInit.initialize(lArgs); 646cdf0e10cSrcweir 647cdf0e10cSrcweir // TODO: throws css::container::NoSuchElementException 648cdf0e10cSrcweir try 649cdf0e10cSrcweir { 650cdf0e10cSrcweir String test = m_xDocumentAccelCfg.getCommandByKeyEvent(convertShortcut2AWTKey("F2")); 651cdf0e10cSrcweir System.out.println(test); 652cdf0e10cSrcweir } 653cdf0e10cSrcweir catch(com.sun.star.container.NoSuchElementException e) 654cdf0e10cSrcweir { 655cdf0e10cSrcweir System.out.println("NoSuchElementException caught: " + e.getMessage()); 656cdf0e10cSrcweir } 657cdf0e10cSrcweir } 658cdf0e10cSrcweir 659cdf0e10cSrcweir //------------------------------------------- 660cdf0e10cSrcweir /** @todo document me. 661cdf0e10cSrcweir */ SaveDocumentAcceleratorConfiguration(String sDocCfgName)662cdf0e10cSrcweir private void SaveDocumentAcceleratorConfiguration(String sDocCfgName) 663cdf0e10cSrcweir throws java.lang.Exception 664cdf0e10cSrcweir { 665cdf0e10cSrcweir XSingleServiceFactory xStorageFactory = UnoRuntime.queryInterface(XSingleServiceFactory.class, m_xSmgr.createInstance("com.sun.star.embed.StorageFactory")); 666cdf0e10cSrcweir 667cdf0e10cSrcweir Object aArgs[] = new Object[2]; 668cdf0e10cSrcweir aArgs[0] = sDocCfgName; 669cdf0e10cSrcweir aArgs[1] = new Integer(com.sun.star.embed.ElementModes.WRITE); 670cdf0e10cSrcweir XStorage xRootStorage = UnoRuntime.queryInterface(XStorage.class, xStorageFactory.createInstanceWithArguments(aArgs)); 671cdf0e10cSrcweir 672cdf0e10cSrcweir XStorage xUIConfig = xRootStorage.openStorageElement("Configurations2", com.sun.star.embed.ElementModes.WRITE); 673cdf0e10cSrcweir 674cdf0e10cSrcweir XUIConfigurationManager xCfgMgr = UnoRuntime.queryInterface(XUIConfigurationManager.class, m_xSmgr.createInstance("com.sun.star.ui.UIConfigurationManager")); 675cdf0e10cSrcweir 676cdf0e10cSrcweir XUIConfigurationStorage xUICfgStore = UnoRuntime.queryInterface(XUIConfigurationStorage.class, xCfgMgr); 677cdf0e10cSrcweir xUICfgStore.setStorage(xUIConfig); 678cdf0e10cSrcweir 679cdf0e10cSrcweir XPropertySet xUIConfigProps = UnoRuntime.queryInterface(XPropertySet.class, xUIConfig); 680cdf0e10cSrcweir xUIConfigProps.setPropertyValue("MediaType", "application/vnd.sun.xml.ui.configuration"); 681cdf0e10cSrcweir 682cdf0e10cSrcweir if (xCfgMgr != null) 683cdf0e10cSrcweir { 684cdf0e10cSrcweir XAcceleratorConfiguration xTargetAccMgr = UnoRuntime.queryInterface(XAcceleratorConfiguration.class, xCfgMgr.getShortCutManager()); 685cdf0e10cSrcweir XUIConfigurationPersistence xCommit1 = UnoRuntime.queryInterface(XUIConfigurationPersistence.class, xTargetAccMgr); 686cdf0e10cSrcweir XUIConfigurationPersistence xCommit2 = UnoRuntime.queryInterface(XUIConfigurationPersistence.class, xCfgMgr); 687cdf0e10cSrcweir xCommit1.store(); 688cdf0e10cSrcweir xCommit2.store(); 689cdf0e10cSrcweir 690cdf0e10cSrcweir XTransactedObject xCommit3 = UnoRuntime.queryInterface(XTransactedObject.class, xRootStorage); 691cdf0e10cSrcweir xCommit3.commit(); 692cdf0e10cSrcweir } 693cdf0e10cSrcweir } 694cdf0e10cSrcweir 695cdf0e10cSrcweir //------------------------------------------- 696cdf0e10cSrcweir /** @todo document me. 697cdf0e10cSrcweir */ convertShortcut2AWTKey(String sShortcut)698cdf0e10cSrcweir private com.sun.star.awt.KeyEvent convertShortcut2AWTKey(String sShortcut) 699cdf0e10cSrcweir throws java.lang.Exception 700cdf0e10cSrcweir { 701cdf0e10cSrcweir com.sun.star.awt.KeyEvent aKeyEvent = new com.sun.star.awt.KeyEvent(); 702cdf0e10cSrcweir KeyMapping aKeyMapping = new KeyMapping(); 703cdf0e10cSrcweir String[] sShortcutSplits = sShortcut.split("_"); 704cdf0e10cSrcweir 705cdf0e10cSrcweir aKeyEvent.KeyCode = aKeyMapping.mapIdentifier2Code(sShortcutSplits[0]); 706cdf0e10cSrcweir for (int i = 1; i < sShortcutSplits.length; i++) 707cdf0e10cSrcweir { 708cdf0e10cSrcweir if (sShortcutSplits[i].equals("SHIFT")) 709cdf0e10cSrcweir { 710cdf0e10cSrcweir aKeyEvent.Modifiers |= com.sun.star.awt.KeyModifier.SHIFT; 711cdf0e10cSrcweir } 712cdf0e10cSrcweir else if (sShortcutSplits[i].equals("MOD1")) 713cdf0e10cSrcweir { 714cdf0e10cSrcweir aKeyEvent.Modifiers |= com.sun.star.awt.KeyModifier.MOD1; 715cdf0e10cSrcweir } 716cdf0e10cSrcweir else if (sShortcutSplits[i].equals("MOD2")) 717cdf0e10cSrcweir { 718cdf0e10cSrcweir aKeyEvent.Modifiers |= com.sun.star.awt.KeyModifier.MOD2; 719cdf0e10cSrcweir } 720cdf0e10cSrcweir } 721cdf0e10cSrcweir 722cdf0e10cSrcweir return aKeyEvent; 723cdf0e10cSrcweir } 724cdf0e10cSrcweir 725cdf0e10cSrcweir //------------------------------------------- 726cdf0e10cSrcweir /** @todo document me. 727cdf0e10cSrcweir */ convertAWTKey2Shortcut(com.sun.star.awt.KeyEvent aKeyEvent)728cdf0e10cSrcweir private String convertAWTKey2Shortcut(com.sun.star.awt.KeyEvent aKeyEvent) 729cdf0e10cSrcweir throws java.lang.Exception 730cdf0e10cSrcweir { 731cdf0e10cSrcweir String sShortcut; 732cdf0e10cSrcweir 733cdf0e10cSrcweir KeyMapping aKeyMapping = new KeyMapping(); 734cdf0e10cSrcweir sShortcut = aKeyMapping.mapCode2Identifier(aKeyEvent.KeyCode); 735cdf0e10cSrcweir 736cdf0e10cSrcweir if ((aKeyEvent.Modifiers & com.sun.star.awt.KeyModifier.SHIFT) == com.sun.star.awt.KeyModifier.SHIFT) 737cdf0e10cSrcweir { 738cdf0e10cSrcweir sShortcut += "_SHIFT"; 739cdf0e10cSrcweir } 740cdf0e10cSrcweir if ((aKeyEvent.Modifiers & com.sun.star.awt.KeyModifier.MOD1) == com.sun.star.awt.KeyModifier.MOD1) 741cdf0e10cSrcweir { 742cdf0e10cSrcweir sShortcut += "_MOD1"; 743cdf0e10cSrcweir } 744cdf0e10cSrcweir if ((aKeyEvent.Modifiers & com.sun.star.awt.KeyModifier.MOD2) == com.sun.star.awt.KeyModifier.MOD2) 745cdf0e10cSrcweir { 746cdf0e10cSrcweir sShortcut += "_MOD2"; 747cdf0e10cSrcweir } 748cdf0e10cSrcweir 749cdf0e10cSrcweir return sShortcut; 750cdf0e10cSrcweir } 751cdf0e10cSrcweir 752cdf0e10cSrcweir //------------------------------------------- 753cdf0e10cSrcweir /** @todo document me. 754cdf0e10cSrcweir */ getOfficeLocale()755cdf0e10cSrcweir private String getOfficeLocale() 756cdf0e10cSrcweir throws java.lang.Exception 757cdf0e10cSrcweir { 758cdf0e10cSrcweir String sLocale = new String(); 759cdf0e10cSrcweir 760cdf0e10cSrcweir String sConfigPath = "org.openoffice.Setup"; 761cdf0e10cSrcweir boolean bReadOnly = true; 762cdf0e10cSrcweir XNameAccess xRootConfig = openConfig(m_xSmgr, sConfigPath, bReadOnly); 763cdf0e10cSrcweir 764cdf0e10cSrcweir if (xRootConfig != null) 765cdf0e10cSrcweir { 766cdf0e10cSrcweir XNameAccess xLocale = UnoRuntime.queryInterface(XNameAccess.class, xRootConfig.getByName("L10N")); 767cdf0e10cSrcweir XPropertySet xSet = UnoRuntime.queryInterface(XPropertySet.class, xLocale); 768cdf0e10cSrcweir sLocale = (String) xSet.getPropertyValue("ooLocale"); 769cdf0e10cSrcweir } 770cdf0e10cSrcweir 771cdf0e10cSrcweir return sLocale; 772cdf0e10cSrcweir } 773cdf0e10cSrcweir 774cdf0e10cSrcweir //------------------------------------------- 775cdf0e10cSrcweir /** @todo document me. 776cdf0e10cSrcweir */ setOfficeLocale(String sLocale)777cdf0e10cSrcweir private void setOfficeLocale(String sLocale) 778cdf0e10cSrcweir throws java.lang.Exception 779cdf0e10cSrcweir { 780cdf0e10cSrcweir String sConfigPath = "org.openoffice.Setup"; 781cdf0e10cSrcweir boolean bReadOnly = false; 782cdf0e10cSrcweir XNameAccess xRootConfig = openConfig(m_xSmgr, sConfigPath, bReadOnly); 783cdf0e10cSrcweir 784cdf0e10cSrcweir if (xRootConfig != null) 785cdf0e10cSrcweir { 786cdf0e10cSrcweir XNameAccess xLocale = UnoRuntime.queryInterface(XNameAccess.class, xRootConfig.getByName("L10N")); 787cdf0e10cSrcweir XPropertySet xSet = UnoRuntime.queryInterface(XPropertySet.class, xLocale); 788cdf0e10cSrcweir xSet.setPropertyValue("ooLocale", sLocale); 789cdf0e10cSrcweir XChangesBatch xBatch = UnoRuntime.queryInterface(XChangesBatch.class, xRootConfig); 790cdf0e10cSrcweir xBatch.commitChanges(); 791cdf0e10cSrcweir } 792cdf0e10cSrcweir } 793cdf0e10cSrcweir 794cdf0e10cSrcweir //------------------------------------------- 795cdf0e10cSrcweir /** @todo document me. 796cdf0e10cSrcweir */ openConfig(XMultiServiceFactory xSMGR, String sConfigPath, boolean bReadOnly)797cdf0e10cSrcweir private XNameAccess openConfig(XMultiServiceFactory xSMGR, 798cdf0e10cSrcweir String sConfigPath, 799cdf0e10cSrcweir boolean bReadOnly) 800cdf0e10cSrcweir throws java.lang.Exception 801cdf0e10cSrcweir { 802cdf0e10cSrcweir XMultiServiceFactory xConfigRoot = UnoRuntime.queryInterface(XMultiServiceFactory.class, xSMGR.createInstance("com.sun.star.configuration.ConfigurationProvider")); 803cdf0e10cSrcweir 804cdf0e10cSrcweir PropertyValue[] lParams = new PropertyValue[2]; 805cdf0e10cSrcweir lParams[0] = new PropertyValue(); 806cdf0e10cSrcweir lParams[0].Name = "nodepath"; 807cdf0e10cSrcweir lParams[0].Value = sConfigPath; 808cdf0e10cSrcweir 809cdf0e10cSrcweir lParams[1] = new PropertyValue(); 810cdf0e10cSrcweir lParams[1].Name = "locale"; 811cdf0e10cSrcweir lParams[1].Value = "*"; 812cdf0e10cSrcweir 813cdf0e10cSrcweir Object aConfig; 814cdf0e10cSrcweir if (bReadOnly) 815cdf0e10cSrcweir { 816cdf0e10cSrcweir aConfig = xConfigRoot.createInstanceWithArguments("com.sun.star.configuration.ConfigurationAccess", lParams); 817cdf0e10cSrcweir } 818cdf0e10cSrcweir else 819cdf0e10cSrcweir { 820cdf0e10cSrcweir aConfig = xConfigRoot.createInstanceWithArguments("com.sun.star.configuration.ConfigurationUpdateAccess", lParams); 821cdf0e10cSrcweir } 822cdf0e10cSrcweir 823cdf0e10cSrcweir XNameAccess xConfig = UnoRuntime.queryInterface(XNameAccess.class, aConfig); 824cdf0e10cSrcweir 825cdf0e10cSrcweir if (xConfig == null) 826cdf0e10cSrcweir { 827cdf0e10cSrcweir throw new com.sun.star.uno.Exception("Could not open configuration \"" + sConfigPath + "\""); 828cdf0e10cSrcweir } 829cdf0e10cSrcweir 830cdf0e10cSrcweir return xConfig; 831cdf0e10cSrcweir } 832cdf0e10cSrcweir getMSF()833cdf0e10cSrcweir private XMultiServiceFactory getMSF() 834cdf0e10cSrcweir { 835cdf0e10cSrcweir final XMultiServiceFactory xMSF1 = UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager()); 836cdf0e10cSrcweir return xMSF1; 837cdf0e10cSrcweir } 838cdf0e10cSrcweir 839cdf0e10cSrcweir // setup and close connections 840cdf0e10cSrcweir @BeforeClass setUpConnection()841cdf0e10cSrcweir public static void setUpConnection() throws Exception 842cdf0e10cSrcweir { 843cdf0e10cSrcweir System.out.println("setUpConnection()"); 844cdf0e10cSrcweir connection.setUp(); 845cdf0e10cSrcweir } 846cdf0e10cSrcweir 847cdf0e10cSrcweir @AfterClass tearDownConnection()848cdf0e10cSrcweir public static void tearDownConnection() 849cdf0e10cSrcweir throws InterruptedException, com.sun.star.uno.Exception 850cdf0e10cSrcweir { 851cdf0e10cSrcweir System.out.println("tearDownConnection()"); 852cdf0e10cSrcweir connection.tearDown(); 853cdf0e10cSrcweir } 854cdf0e10cSrcweir private static final OfficeConnection connection = new OfficeConnection(); 855cdf0e10cSrcweir } 856