ShowDialog.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * This file is part of the LibreOffice project.
  3. *
  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/.
  7. *
  8. * This file incorporates work covered by the following license notice:
  9. *
  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 .
  17. */
  18. importClass(Packages.com.sun.star.uno.UnoRuntime);
  19. importClass(Packages.com.sun.star.lang.XMultiComponentFactory);
  20. importClass(Packages.com.sun.star.awt.XDialogProvider);
  21. importClass(Packages.com.sun.star.awt.XDialog);
  22. importClass(Packages.com.sun.star.uno.Exception);
  23. importClass(Packages.com.sun.star.script.provider.XScriptContext);
  24. importClass(java.lang.Thread);
  25. importClass(java.lang.System);
  26. function tryLoadingLibrary( xmcf, context, name )
  27. {
  28. try
  29. {
  30. obj = xmcf.createInstanceWithContext(
  31. "com.sun.star.script.Application" + name + "LibraryContainer",
  32. context.getComponentContext());
  33. xLibraryContainer = UnoRuntime.queryInterface(XLibraryContainer, obj);
  34. System.err.println("Got XLibraryContainer");
  35. serviceObj = context.getComponentContext().getValueByName(
  36. "/singletons/com.sun.star.util.theMacroExpander");
  37. xme = AnyConverter.toObject(new Type(XMacroExpander), serviceObj);
  38. bootstrapName = "bootstraprc";
  39. if (System.getProperty("os.name").startsWith("Windows"))
  40. {
  41. bootstrapName = "bootstrap.ini";
  42. }
  43. libURL = xme.expandMacros(
  44. "$BRAND_BASE_DIR/$BRAND_SHARE_SUBDIR/basic/ScriptBindingLibrary/" +
  45. name.toLowerCase() + ".xlb/");
  46. System.err.println("libURL is: " + libURL);
  47. xLibraryContainer.createLibraryLink(
  48. "ScriptBindingLibrary", libURL, false);
  49. System.err.println("liblink created");
  50. }
  51. catch (e)
  52. {
  53. System.err.println("Got an exception loading lib: " + e.getMessage());
  54. return false;
  55. }
  56. return true;
  57. }
  58. function getDialogProvider()
  59. {
  60. // UNO awt components of the Highlight dialog
  61. //get the XMultiServiceFactory
  62. xmcf = XSCRIPTCONTEXT.getComponentContext().getServiceManager();
  63. args = new Array;
  64. //get the XDocument from the context
  65. args[0] = XSCRIPTCONTEXT.getDocument();
  66. //try to create the DialogProvider
  67. try {
  68. obj = xmcf.createInstanceWithArgumentsAndContext(
  69. "com.sun.star.awt.DialogProvider", args,
  70. XSCRIPTCONTEXT.getComponentContext());
  71. }
  72. catch (e) {
  73. System.err.println("Error getting DialogProvider object");
  74. return null;
  75. }
  76. return UnoRuntime.queryInterface(XDialogProvider, obj);
  77. }
  78. //get the DialogProvider
  79. xDialogProvider = getDialogProvider();
  80. if (xDialogProvider != null)
  81. {
  82. //try to create the Highlight dialog (found in the ScriptBinding library)
  83. try
  84. {
  85. findDialog = xDialogProvider.createDialog("vnd.sun.star.script:" +
  86. "ScriptBindingLibrary.Highlight?location=application");
  87. if( findDialog == null )
  88. {
  89. if (tryLoadingLibrary(xmcf, XSCRIPTCONTEXT, "Dialog") == false ||
  90. tryLoadingLibrary(xmcf, XSCRIPTCONTEXT, "Script") == false)
  91. {
  92. System.err.println("Error loading ScriptBindingLibrary");
  93. }
  94. else
  95. {
  96. // try to create the Highlight dialog (found in the
  97. // ScriptBindingLibrary)
  98. findDialog = xDialogProvider.createDialog("vnd.sun.star.script:" +
  99. "ScriptBindingLibrary.Highlight?location=application");
  100. }
  101. }
  102. //launch the dialog
  103. if ( findDialog != null )
  104. {
  105. findDialog.execute();
  106. }
  107. }
  108. catch (e) {
  109. System.err.println("Got exception on first creating dialog: " +
  110. e.getMessage());
  111. }
  112. }