OpenOffice Add-On Project Type

From Apache OpenOffice Wiki
Revision as of 12:12, 29 December 2006 by Jsc (Talk | contribs)

Jump to: navigation, search

Back to OpenOffice.org NetBeans Integration

Overview

The Add-On wizard will enable users to create a StarOffice component that including support of UI extensions. The component is based on a on a J2SE class library project and supports additional targets to create and deploy the package into the office installation. All interface methods are default implemented and do nothing. In a second step you can insert your implementation in the generated skeleton, rebuild the extension and deploy it again to see the effect in your office.

Project Wizard

The project wizard is quite simple to use, you simply choose

  • File -> New Project -> StarOffice/OpenOffice.org -> StarOffice/OpenOffice.org Add-On

and follow the wizard.

  • Step 1: Selecting the project type

AddOn1.png

  • Step 2: Defining the project name, Add-On name, an optional package and the project location

AddOn2.png

The necessary xcu files are generated as well and becomes part of the final oxt package. This xcu files can be easy adapted later to extend the initial project to a more complex Add-On example. The generated Add-On skeleton implments a simple com.sun.star.frame.ProtocolHanlder Addon.

  • Step 4: Defining the new toplevel menu

AddOn3.png


AddOn4.png

On this panel you have the possibility to define new toplevel menus with submenus on a higher abstraction level. You won't have to deal with xcu files directly. You can modify the default menu and command, can add new menus and commands and you can insert localized displaynames ... For more detailed descriptions of the different fields simply press the help button or read the appropriate chapter in the Developer's Guide - Writing UNO components - Integrating Components into OpenOffice.org - Protocol Handler

When you add a new language you can choose of a list of supported languages which are not added and when you delete a language, only the added languages are offered for removal.


Calc AddIn3a.png


Calc AddIn3b.png

  • Step 5: Deploying the extension package

Calc AddIn4.png

You can simply create or deploy the oxt extension package by choosing:

Project View -> Project Node -> Context Menu -> Create OXT | Deploy Office Extension

When you have deployed the package the new defined menus are visible in the specified context. for example if you choose the context Writer the menu is visible when you open or create a text document.


AddOn5.png

Generated Code

For a Calc Add-In the wizard generates more code and it would be to much to show them here. But new is that we generate a new config (.xcu) file for the Add-In describing the Add-In functions with descriptions, displaynames etc. The new configuration allows the easy support of localization of the description and displaynames. The underlying schema comes with OO.org 2.0.4 and will be part of backward compatible Add-In extension packages. For the above shown example the following files are generated:

  • Addons.xcu
    xcu file defining the new menus with submenus and commands. This file can be easy extended to support toolbars as well (toolbar support will supported later by the wizard).

[xml] <?xml version='1.0' encoding='UTF-8'?>

<oor:component-data xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" oor:name="Addons" oor:package="org.openoffice.Office">

 <node oor:name="AddonUI">
   <node oor:name="OfficeMenuBar">
     <node oor:name="org.openoffice.testaddon.testaddon" oor:op="replace">
       <prop oor:name="Title" oor:type="xs:string">
         <value/>
         <value xml:lang="en">My Menu</value>
       </prop>
       <prop oor:name="Target" oor:type="xs:string">
         <value>_self</value>
       </prop>
       <prop oor:name="ImageIdentifier" oor:type="xs:string">
         <value/>
       </prop>
       <node oor:name="Submenu">
         <node oor:name="m1" oor:op="replace">
           <prop oor:name="URL" oor:type="xs:string">
             <value>org.openoffice.testaddon.testaddon:mycommands</value>
           </prop>
           <prop oor:name="ImageIdentifier" oor:type="xs:string">
             <value/>
           </prop>
           <prop oor:name="Target" oor:type="xs:string">
             <value>_self</value>
           </prop>
           <prop oor:name="Context" oor:type="xs:string">
             <value/>
           </prop>
           <prop oor:name="Title" oor:type="xs:string">
             <value/>
             <value xml:lang="en">Hello World</value>
           </prop>
         </node>
       </node>
     </node>
   </node>
   <node oor:name="Images">
     <node oor:name="org.openoffice.testaddon.testaddon.mycommands.images" oor:op="replace">
       <prop oor:name="URL" oor:type="xs:string">
         <value>org.openoffice.testaddon.testaddon:mycommands</value>
       </prop>
       <node oor:name="UserDefinedImages">
         <prop oor:name="ImageSmallURL">
           <value/>
         </prop>
       </node>
     </node>
     </node>
 </node>

</oor:component-data>

  • ProtocolHandler.xcu
    xcu file defining the automatically generated protocol. The protocol is generated based on the package and add-On name.

[xml] <?xml version='1.0' encoding='UTF-8'?>

<oor:component-data oor:name="ProtocolHandler" oor:package="org.openoffice.Office" xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

 <node oor:name="HandlerSet">
   <node oor:name="org.openoffice.testaddon.TestAddOn" oor:op="replace">
     <prop oor:name="Protocols" oor:type="oor:string-list">
       <value>org.openoffice.testaddon.testaddon:*</value>
     </prop>
   </node>
 </node>

</oor:component-data>

  • uno-extension-manifest.xml
    the package descriptor, will be packed as "META-INF/manifest.xml"

[xml] <?xml version="1.0" encoding="UTF-8"?> <manifest:manifest xmlns:manifest="http://openoffice.org/2001/manifest">

 <manifest:file-entry manifest:media-type="application/vnd.sun.star.configuration-data"
                      manifest:full-path="ProtocolHandler.xcu"/>
 <manifest:file-entry manifest:media-type="application/vnd.sun.star.configuration-data"
                      manifest:full-path="Addons.xcu"/>
 <manifest:file-entry manifest:media-type="application/vnd.sun.star.uno-component;type=Java"
                      manifest:full-path="TestAddOn.jar"/>

</manifest:manifest>

  • org/openoffice/testaddon/TestAddOn.java
    the generated Add-On code skeleton where generated class acts itself as dispatch object (can be easy changed to support more complex Add-Ons). Most of the methods are already implemented and you can easy add your own code in the dipatch method in the right place for each specified command.

[java] package org.openoffice.testaddon;

import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.XComponentContext; import com.sun.star.lib.uno.helper.Factory; import com.sun.star.lang.XSingleComponentFactory; import com.sun.star.registry.XRegistryKey; import com.sun.star.lib.uno.helper.WeakBase;


public final class TestAddOn extends WeakBase

  implements com.sun.star.lang.XServiceInfo,
             com.sun.star.frame.XDispatchProvider,
             com.sun.star.lang.XInitialization,
             com.sun.star.frame.XDispatch

{

   private final XComponentContext m_xContext;
   private com.sun.star.frame.XFrame m_xFrame;
   private static final String m_implementationName = TestAddOn.class.getName();
   private static final String[] m_serviceNames = {
       "com.sun.star.frame.ProtocolHandler" };


   public TestAddOn( XComponentContext context )
   {
       m_xContext = context;
   };
   public static XSingleComponentFactory __getComponentFactory( String sImplementationName ) {
       XSingleComponentFactory xFactory = null;
       if ( sImplementationName.equals( m_implementationName ) )
           xFactory = Factory.createComponentFactory(TestAddOn.class, m_serviceNames);
       return xFactory;
   }
   public static boolean __writeRegistryServiceInfo( XRegistryKey xRegistryKey ) {
       return Factory.writeRegistryServiceInfo(m_implementationName,
                                               m_serviceNames,
                                               xRegistryKey);
   }
   // com.sun.star.lang.XServiceInfo:
   public String getImplementationName() {
        return m_implementationName;
   }
   public boolean supportsService( String sService ) {
       int len = m_serviceNames.length;
       for( int i=0; i < len; i++) {
           if (sService.equals(m_serviceNames[i]))
               return true;
       }
       return false;
   }
   public String[] getSupportedServiceNames() {
       return m_serviceNames;
   }
   // com.sun.star.frame.XDispatchProvider:
   public com.sun.star.frame.XDispatch queryDispatch( com.sun.star.util.URL aURL,
                                                      String sTargetFrameName,
                                                      int iSearchFlags )
   {
       if ( aURL.Protocol.compareTo("org.openoffice.testaddon.testaddon:") == 0 )
       {
           if ( aURL.Path.compareTo("mycommands") == 0 )
               return this;
       }
       return null;
   }
   // com.sun.star.frame.XDispatchProvider:
   public com.sun.star.frame.XDispatch[] queryDispatches(
        com.sun.star.frame.DispatchDescriptor[] seqDescriptors )
   {
       int nCount = seqDescriptors.length;
       com.sun.star.frame.XDispatch[] seqDispatcher =
           new com.sun.star.frame.XDispatch[seqDescriptors.length];
       for( int i=0; i < nCount; ++i )
       {
           seqDispatcher[i] = queryDispatch(seqDescriptors[i].FeatureURL,
                                            seqDescriptors[i].FrameName,
                                            seqDescriptors[i].SearchFlags );
       }
       return seqDispatcher;
   }
   // com.sun.star.lang.XInitialization:
   public void initialize( Object[] object )
       throws com.sun.star.uno.Exception
   {
       if ( object.length > 0 )
       {
           m_xFrame = (com.sun.star.frame.XFrame)UnoRuntime.queryInterface(
               com.sun.star.frame.XFrame.class, object[0]);
       }
   }
   // com.sun.star.frame.XDispatch:
    public void dispatch( com.sun.star.util.URL aURL,
                          com.sun.star.beans.PropertyValue[] aArguments )
   {
        if ( aURL.Protocol.compareTo("org.openoffice.testaddon.testaddon:") == 0 )
       {
           if ( aURL.Path.compareTo("mycommands") == 0 )
           {
               // add your own code here
               return;
           }
       }
   }
   public void addStatusListener( com.sun.star.frame.XStatusListener xControl,
                                   com.sun.star.util.URL aURL )
   {
       // add your own code here
   }
   public void removeStatusListener( com.sun.star.frame.XStatusListener xControl,
                                      com.sun.star.util.URL aURL )
   {
       // add your own code here
   }

}

Personal tools