I'm trying to write an extension for OpenOffice.
This extension would be written in java (compiled, I don't want people to see the code). It should do actions when I start openOffice writer, when I click on a button and when I print. I've already added the button but I can't find how to link it with the code of what it should do. I've read the wiki and the DevGuide but I don't find it very clear.
Could you please help me to start understanding how to create an extension (where should I put my code, how to link it with the GUI etc...)?
As an example, follow instructions at https://wiki.openoffice.org/wiki/OpenOffice_NetBeans_Integration#Configuration. Install the Apache OpenOffice API Plugin
by going to Tools -> Plugins
.
Click on the link that says OpenOffice.org Add-On Project Type
to get more instructions. If you haven't yet, download AOO 4.1.2 and the AOO 4.1.2 SDK. (The plugin did not work for me using LibreOffice, but the resulting extension did work in LibreOffice).
After the code is generated according to the instructions, then add this code to the dispatch
method of TestAddOn.java:
if ( aURL.Path.compareTo("HelloWorld") == 0 )
{
// add your own code here
com.sun.star.frame.XController xController = m_xFrame.getController();
if (xController != null) {
XModel xModel = (com.sun.star.frame.XModel) xController.getModel();
XTextDocument xTextDocument = (com.sun.star.text.XTextDocument)
UnoRuntime.queryInterface(XTextDocument.class, xModel);
XText xText = xTextDocument.getText();
XTextRange xTextRange = xText.getEnd();
xTextRange.setString( "Hello World (in Java)" );
return;
}
}
Now compile and deploy the extension. When the "Hello World" toolbar button is clicked, it should put "Hello World (in Java)" in the document.
The code was adapted from https://forum.openoffice.org/en/forum/viewtopic.php?f=47&t=72459.
In order to handle events like when the document is opened, I also tried calling a method of the extension from Basic code like this:
Sub CallJavaMacro
MSPF = createUnoService("com.sun.star.script.provider.MasterScriptProviderFactory")
scriptPro = MSPF.createScriptProvider("")
xScript = scriptPro.getScript("vnd.sun.star.script:" & _
"com.example.testaddon.TestAddOn.PutHello?" & _
"language=Java&location=user:uno_packages/TestAddOn.oxt")
Thing = xScript.Invoke()
End Sub
However the Basic routine said it could not find the method. Maybe I did not declare the method properly or something.