1// this script serves as an example of how to launch a Basic Dialog 2// from a script 3import com.sun.star.uno.UnoRuntime; 4import com.sun.star.script.provider.XScriptContext; 5import com.sun.star.lang.XMultiComponentFactory; 6import com.sun.star.lang.EventObject; 7import com.sun.star.uno.Type; 8import com.sun.star.uno.AnyConverter; 9import com.sun.star.text.XTextDocument; 10import com.sun.star.beans.PropertyValue; 11import com.sun.star.script.XLibraryContainer; 12import com.sun.star.awt.*; 13import com.sun.star.util.*; 14 15boolean tryLoadingLibrary( xmcf, context, name ) 16{ 17 try 18 { 19 obj = xmcf.createInstanceWithContext( 20 "com.sun.star.script.Application" + name + "LibraryContainer", 21 context.getComponentContext()); 22 23 xLibraryContainer = (XLibraryContainer) 24 UnoRuntime.queryInterface(XLibraryContainer.class, obj); 25 26 System.err.println("Got XLibraryContainer"); 27 28 serviceObj = context.getComponentContext().getValueByName( 29 "/singletons/com.sun.star.util.theMacroExpander"); 30 31 xme = (XMacroExpander) AnyConverter.toObject( 32 new Type(XMacroExpander.class), serviceObj); 33 34 bootstrapName = "bootstraprc"; 35 if (System.getProperty("os.name").startsWith("Windows")) 36 { 37 bootstrapName = "bootstrap.ini"; 38 } 39 40 libURL = xme.expandMacros( 41 "${$BRAND_BASE_DIR/program/" + bootstrapName + "::BaseInstallation}" + 42 "/share/basic/ScriptBindingLibrary/" + 43 name.toLowerCase() + ".xlb/"); 44 45 System.err.println("libURL is: " + libURL); 46 47 xLibraryContainer.createLibraryLink( 48 "ScriptBindingLibrary", libURL, false); 49 50 System.err.println("liblink created"); 51 52 } 53 catch (com.sun.star.uno.Exception e) 54 { 55 System.err.println("Got an exception loading lib: " + e.getMessage()); 56 return false; 57 } 58 return true; 59} 60 61// get the XMultiComponentFactory from the XSCRIPTCONTEXT 62XMultiComponentFactory xmcf = 63 XSCRIPTCONTEXT.getComponentContext().getServiceManager(); 64 65Object[] args = new Object[1]; 66args[0] = XSCRIPTCONTEXT.getDocument(); 67 68Object obj; 69try { 70 // try to create an instance of the DialogProvider 71 obj = xmcf.createInstanceWithArgumentsAndContext( 72 "com.sun.star.awt.DialogProvider", args, 73 XSCRIPTCONTEXT.getComponentContext()); 74 /* 75 obj = xmcf.createInstanceWithContext( 76 "com.sun.star.awt.DialogProvider", 77 XSCRIPTCONTEXT.getComponentContext()); 78 */ 79} 80catch (com.sun.star.uno.Exception e) { 81 System.err.println("Error getting DialogProvider object"); 82 return 0; 83} 84 85// get the XDialogProvider interface from the object created above 86XDialogProvider xDialogProvider = (XDialogProvider) 87 UnoRuntime.queryInterface(XDialogProvider.class, obj); 88 89System.err.println("Got DialogProvider, now get dialog"); 90 91try { 92 // try to create the Highlight dialog (found in the ScriptBindingLibrary) 93 findDialog = xDialogProvider.createDialog("vnd.sun.star.script:" + 94 "ScriptBindingLibrary.Highlight?location=application"); 95 if( findDialog == null ) 96 { 97 if (tryLoadingLibrary(xmcf, XSCRIPTCONTEXT, "Dialog") == false || 98 tryLoadingLibrary(xmcf, XSCRIPTCONTEXT, "Script") == false) 99 { 100 System.err.println("Error loading ScriptBindingLibrary"); 101 return 0; 102 } 103 else 104 { 105 // try to create the Highlight dialog (found in the ScriptBindingLibrary) 106 findDialog = xDialogProvider.createDialog("vnd.sun.star.script:" + 107 "ScriptBindingLibrary.Highlight?location=application"); 108 } 109 } 110} 111catch (java.lang.Exception e) { 112 System.err.println("Got exception on first creating dialog: " + 113 e.getMessage()); 114} 115 116// execute the dialog in a new thread (so that this script can finish) 117Thread t = new Thread() { 118 public void run() { 119 findDialog.execute(); 120 } 121}; 122t.start(); 123 124return 0; 125