Create OpenOffice Extensions ?

For the readers who are completely new to the phrase Open Office ,It is an open source project with word processing,presentation,Spread Sheet + many more applications which can be a good alternative to Microsoft Office package. It supports the ISO/IEC standard OpenDocument Format (ODF) for data interchange as its default file format. It is a community project where developers from all the over the world contribute to improve product features or to add new facilities.

This post will give you a basic idea on how to become a part of this wonderful project . I will be using Netbeans as my IDE and java as my language.Still you need to install NetBeans OpenOffice plug in as well as the OpenOffice SDK.

Setting up the Environment
  • Download the latest version of OO plugin within NetBeans by clicking on Tools ---> Plugins. You can find the plugin in the "Available Plugins" section as "OpenOffice.org API Plugin"(For the latest version of NetBeans (6.9) above method will not work.So download this file and install it manually.)
  • Then download OO SDK  (I assume that you have already installed OpenOffice package ) and install it.
Now We Are Ready to Rock and Roll !!

Creating your FIRST Project

Restart the IDE .Then go to File--->New Project  . Scroll down on New project window and find OpenOffice.org entry.Click on it

Select Project Type
From the above window select the entry "Open Office Add-on" .Click Next.
Now It is time to give a unique project name to your work.I chose "MyProject".And click Next !

Command Name
The above is an important window where you need to specify your unique command. As an example when you click "save" menu item in an application Save window get opened. So you should give a command name to your task . hmmm Lets say command is "Say Hello " . You can also insert icon images to your project using that icon column .For now, Lets just forget icons and click Next to proceed .

Menu Name
Alright now it's time to give a menu name . I gave "My Menu" .After that proceed by clicking next !In the next window you will have Check Boxes for each Open Office application.(Etc Writer ,Calc) Select the checkBox of the writer.This will add your add-on to the writer application.Then just press Finish! Your Friendly IDE will create the Project for you
 Now it's time to play with some codes! Go to SourcePackages---->com.example------->MyProject.java file.Using the CTRL+F key combination find the method named "dispatch" inside that java file .That method looks like this.

public void dispatch( com.sun.star.util.URL aURL,
                           com.sun.star.beans.PropertyValue[] aArguments )
    {
         if ( aURL.Protocol.compareTo("com.example.myproject:") == 0 )
        {
            if ( aURL.Path.compareTo("Say Hello") == 0 )
            {
                //add your own code

                return;
            }
        }
    }

Now replace that " // add your own code here" line with the code segment below.

String name = JOptionPane.showInputDialog("Enter your Name");                 JOptionPane.showMessageDialog(null, "Hello " + name + " How are you?", "Hello", JOptionPane.INFORMATION_MESSAGE);

Right Click Menu
Alright we are almost there now ! Right click on the project and find "Deploy and Run Extension ...." menu item. And observe other two menu items Debug Extension and Create OXT . For now let us use the middle one Deploy and run .This will run your extension on the Open Office package which is installed in your computer . After few steps Open Office will be automatically started . Open a Text Document .And you will see your Menu "My Menu" in the top menu bar. 
Click on it and it will have the "Say Hello" entry .Voillaaaaaa !! You just created your first OO extension!!

Comments

Post a Comment

Leave your ideas

Popular Posts