2 * This file is part of the LibreOffice project.
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/.
8 * This file incorporates work covered by the following license notice:
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 .
18 // this script serves as an example of how to launch a Basic Dialog
20 import com.sun.star.uno.UnoRuntime;
21 import com.sun.star.script.provider.XScriptContext;
22 import com.sun.star.lang.XMultiComponentFactory;
23 import com.sun.star.lang.EventObject;
24 import com.sun.star.uno.Type;
25 import com.sun.star.uno.AnyConverter;
26 import com.sun.star.text.XTextDocument;
27 import com.sun.star.beans.PropertyValue;
28 import com.sun.star.script.XLibraryContainer;
29 import com.sun.star.awt.*;
30 import com.sun.star.util.*;
32 boolean tryLoadingLibrary( xmcf, context, name )
36 obj = xmcf.createInstanceWithContext(
37 "com.sun.star.script.Application" + name + "LibraryContainer",
38 context.getComponentContext());
40 xLibraryContainer = (XLibraryContainer)
41 UnoRuntime.queryInterface(XLibraryContainer.class, obj);
43 System.err.println("Got XLibraryContainer");
45 serviceObj = context.getComponentContext().getValueByName(
46 "/singletons/com.sun.star.util.theMacroExpander");
48 xme = (XMacroExpander) AnyConverter.toObject(
49 new Type(XMacroExpander.class), serviceObj);
51 bootstrapName = "bootstraprc";
52 if (System.getProperty("os.name").startsWith("Windows"))
54 bootstrapName = "bootstrap.ini";
57 libURL = xme.expandMacros(
58 "$BRAND_BASE_DIR/$BRAND_SHARE_SUBDIR/basic/ScriptBindingLibrary/" +
59 name.toLowerCase() + ".xlb/");
61 System.err.println("libURL is: " + libURL);
63 xLibraryContainer.createLibraryLink(
64 "ScriptBindingLibrary", libURL, false);
66 System.err.println("liblink created");
69 catch (com.sun.star.uno.Exception e)
71 System.err.println("Got an exception loading lib: " + e.getMessage());
77 // get the XMultiComponentFactory from the XSCRIPTCONTEXT
78 XMultiComponentFactory xmcf =
79 XSCRIPTCONTEXT.getComponentContext().getServiceManager();
81 Object[] args = new Object[1];
82 args[0] = XSCRIPTCONTEXT.getDocument();
86 // try to create an instance of the DialogProvider
87 obj = xmcf.createInstanceWithArgumentsAndContext(
88 "com.sun.star.awt.DialogProvider", args,
89 XSCRIPTCONTEXT.getComponentContext());
91 obj = xmcf.createInstanceWithContext(
92 "com.sun.star.awt.DialogProvider",
93 XSCRIPTCONTEXT.getComponentContext());
96 catch (com.sun.star.uno.Exception e) {
97 System.err.println("Error getting DialogProvider object");
101 // get the XDialogProvider interface from the object created above
102 XDialogProvider xDialogProvider = (XDialogProvider)
103 UnoRuntime.queryInterface(XDialogProvider.class, obj);
105 System.err.println("Got DialogProvider, now get dialog");
108 // try to create the Highlight dialog (found in the ScriptBindingLibrary)
109 findDialog = xDialogProvider.createDialog("vnd.sun.star.script:" +
110 "ScriptBindingLibrary.Highlight?location=application");
111 if( findDialog == null )
113 if (tryLoadingLibrary(xmcf, XSCRIPTCONTEXT, "Dialog") == false ||
114 tryLoadingLibrary(xmcf, XSCRIPTCONTEXT, "Script") == false)
116 System.err.println("Error loading ScriptBindingLibrary");
121 // try to create the Highlight dialog (found in the ScriptBindingLibrary)
122 findDialog = xDialogProvider.createDialog("vnd.sun.star.script:" +
123 "ScriptBindingLibrary.Highlight?location=application");
127 catch (java.lang.Exception e) {
128 System.err.println("Got exception on first creating dialog: " +
132 // execute the dialog in a new thread (so that this script can finish)
133 Thread t = new Thread() {
135 findDialog.execute();