Page 1 of 1
Create extension(add-on) in Java
Posted: Fri Sep 11, 2015 6:34 pm
by pelonchasva
Hi, I'm currently creating an extension for OpenOffice with Java in Netbeans 8.0.2, and what I need to do is to add some macros to every function of my extension that consists into a Menu with Submenus, like this:
Menu
-Option 1
-Option 2
-Option 3
-Option 4
-Option 5
-Submenu
-Option 1
-Option 2
-Option 3
I've already created the extension and the menus and submenus in the Addons.xcu file, but I don't have idea how to add the files of my macros.
Hope someone can help me with this.
Thanks in advance.
Re: Create extension(add-on) in Java
Posted: Fri Sep 11, 2015 6:39 pm
by RoryOF
Re: Create extension(add-on) in Java
Posted: Fri Sep 11, 2015 7:24 pm
by pelonchasva
Hi RoryOF, I think I need to explain more of what I'm doing.
My macros are developed in Java with JBoss Studio, they are JARs along with a parcel-descriptor.xml that contains the methods of the macro, for me, it is easy to add them in OO in Tools->Customize->Menus->'MyMenu', which are located into the OO macros directory (C:/Program Files (x86)/OpenOffice4/share/Scripts/Java).
But it is very annoying do all this in every document, so I just thought of do it with an extension, but the problem is how to tell the extension to load the correct files for each option?
I'm assuming it is a lot different than doing it with the OO interface, for example:
I have a macro that has 3 different methods, and in OO I can add each one apart because the parcel descriptor is in that directory.
But in code I don't know how to do that either.
Hope this helps to understand more what I am trying to achieve.
Thanks
Re: Create extension(add-on) in Java
Posted: Thu Sep 17, 2015 5:43 pm
by johnrdorazio
When you create your menus and submenus, you then have in your main class file a method called "dispatch", and for each menu item you have created you have an "add your own code here" area.
Here is an example of what it can look like:
Code: Select all
public void dispatch( com.sun.star.util.URL aURL,
com.sun.star.beans.PropertyValue[] aArguments )
{
if ( aURL.Protocol.compareTo("com.yourdomain.yourextension:") == 0 )
{
if ( aURL.Path.compareTo("MenuItem1") == 0 )
{
// add your own code here
return;
}
if ( aURL.Path.compareTo("MenuItem2") == 0 )
{
// add your own code here
return;
}
}
}
If you bundle your own classes into the extension, then you just have to invoke your methods from the "//your own code here" area for each menu item.