Create extension(add-on) in Java

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
pelonchasva
Posts: 7
Joined: Mon Aug 03, 2015 7:37 pm

Create extension(add-on) in Java

Post 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.
OpenOffice 4.0.1 on Windows 8.1
User avatar
RoryOF
Moderator
Posts: 34618
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Create extension(add-on) in Java

Post by RoryOF »

Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
pelonchasva
Posts: 7
Joined: Mon Aug 03, 2015 7:37 pm

Re: Create extension(add-on) in Java

Post 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
OpenOffice 4.0.1 on Windows 8.1
johnrdorazio
Posts: 35
Joined: Sun Aug 17, 2014 2:04 pm
Location: Italy

Re: Create extension(add-on) in Java

Post 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.
OpenOffice 4.1.6, NetBeans 8.1, Windows 10 x64 Home
Post Reply