1 // this script serves as an example of how to launch a Basic Dialog
3 import com.sun.star.uno.UnoRuntime;
4 import com.sun.star.script.provider.XScriptContext;
5 import com.sun.star.lang.XMultiComponentFactory;
6 import com.sun.star.lang.EventObject;
7 import com.sun.star.uno.Type;
8 import com.sun.star.uno.AnyConverter;
9 import com.sun.star.text.XTextDocument;
10 import com.sun.star.beans.PropertyValue;
11 import com.sun.star.script.XLibraryContainer;
12 import com.sun.star.awt.*;
13 import com.sun.star.util.*;
15 boolean tryLoadingLibrary( xmcf, context, name )
19 obj = xmcf.createInstanceWithContext(
20 "com.sun.star.script.Application" + name + "LibraryContainer",
21 context.getComponentContext());
23 xLibraryContainer = (XLibraryContainer)
24 UnoRuntime.queryInterface(XLibraryContainer.class, obj);
26 System.err.println("Got XLibraryContainer");
28 serviceObj = context.getComponentContext().getValueByName(
29 "/singletons/com.sun.star.util.theMacroExpander");
31 xme = (XMacroExpander) AnyConverter.toObject(
32 new Type(XMacroExpander.class), serviceObj);
34 bootstrapName = "bootstraprc";
35 if (System.getProperty("os.name").startsWith("Windows"))
37 bootstrapName = "bootstrap.ini";
40 libURL = xme.expandMacros(
41 "${$BRAND_BASE_DIR/program/" + bootstrapName + "::BaseInstallation}" +
42 "/share/basic/ScriptBindingLibrary/" +
43 name.toLowerCase() + ".xlb/");
45 System.err.println("libURL is: " + libURL);
47 xLibraryContainer.createLibraryLink(
48 "ScriptBindingLibrary", libURL, false);
50 System.err.println("liblink created");
53 catch (com.sun.star.uno.Exception e)
55 System.err.println("Got an exception loading lib: " + e.getMessage());
61 // get the XMultiComponentFactory from the XSCRIPTCONTEXT
62 XMultiComponentFactory xmcf =
63 XSCRIPTCONTEXT.getComponentContext().getServiceManager();
65 Object[] args = new Object[1];
66 args[0] = XSCRIPTCONTEXT.getDocument();
70 // try to create an instance of the DialogProvider
71 obj = xmcf.createInstanceWithArgumentsAndContext(
72 "com.sun.star.awt.DialogProvider", args,
73 XSCRIPTCONTEXT.getComponentContext());
75 obj = xmcf.createInstanceWithContext(
76 "com.sun.star.awt.DialogProvider",
77 XSCRIPTCONTEXT.getComponentContext());
80 catch (com.sun.star.uno.Exception e) {
81 System.err.println("Error getting DialogProvider object");
85 // get the XDialogProvider interface from the object created above
86 XDialogProvider xDialogProvider = (XDialogProvider)
87 UnoRuntime.queryInterface(XDialogProvider.class, obj);
89 System.err.println("Got DialogProvider, now get dialog");
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 )
97 if (tryLoadingLibrary(xmcf, XSCRIPTCONTEXT, "Dialog") == false ||
98 tryLoadingLibrary(xmcf, XSCRIPTCONTEXT, "Script") == false)
100 System.err.println("Error loading ScriptBindingLibrary");
105 // try to create the Highlight dialog (found in the ScriptBindingLibrary)
106 findDialog = xDialogProvider.createDialog("vnd.sun.star.script:" +
107 "ScriptBindingLibrary.Highlight?location=application");
111 catch (java.lang.Exception e) {
112 System.err.println("Got exception on first creating dialog: " +
116 // execute the dialog in a new thread (so that this script can finish)
117 Thread t = new Thread() {
119 findDialog.execute();