Calc/Add-In/Project Type

From Apache OpenOffice Wiki
< Calc‎ | Add-In
Revision as of 12:10, 6 October 2006 by Jsc (Talk | contribs)

Jump to: navigation, search

Overview

The StarOffice/OpenOffice.org Calc Add-In wizard creates a new project based on a J2SE class library project and supports additional targets to create a complete office extension package and to deploy this package into the configured office installation.
The wizard collects all necessary information and allows the definition of new build-in Calc functions which can be used in the spreadsheet application directly after deploying the extension and restarting the office.
After finishing the wizard you can directly build the project and can create and deploy the office extension package in your office. The created build-in functions are default implemented and do nothing. In a second step you can insert your implementation in the generated skeleton (searching for the add-in function body), rebuild the extension and deploy it again to see the effect in your office.

Project Wizard

The project wizard should be simply to use, you simply choose

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

and follow the wizard.

  • Step 1: Selecting the project type

Calc AddIn1.png

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

Calc AddIn2.png

The checkbox Create backward comptible Calc Add-In should be marked if you want create a Calc Add-In working with older office versions as well. The default mode creates a simplified code skeleton. Since OpenOffice.org 2.0.4 the Spreadsheet application takes care of a new configuration schema for Calc Add-In functions. An appropriate xcu file is generated as well and becomes part of the final oxt package. The backward compatible mode maps the older Add-In interfaces to the configuration in the generated code and deploys the schema with the final extension.

  • Step 4: Defining the new Add-In functions

Calc AddIn3.png

On this panel you have the possibility to define new Calc Add-In methods on a higher abstraction level, you won't have to deal with UNO IDL or xcu files directly. You can modify the default method, can insert localized descriptions and displaynames ... For more detailed descriptions of the different fields simply press the help button or read the appropriate chapter in the Developer's Guide - Spreadsheet - Add-Ins
Add a new function will always add the new function on top of the list. Add parameter will add the parameter as the first parameter when the function node is selected or will append the parameter behind the currently selected parameter. 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 usage of the Calc Add-In function(s) in your office is straight forward. Simply open a new spreadsheet document -> open the build-in function dialog -> select the “AddIn” category -> search a new Add-In function (uppercase notation) -> clicking next -> enter parameters ... -> ok


Calc AddIn5.png


Calc AddIn6.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 gets currently deployed with the extension package but with OO.org 2.0.4 the schema should be already come with the office. For the above shown example the following files are generated:

  • CalcAddIn.xcu
    the mentioned new configuration file

[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="CalcAddIns"
 oor:package="org.openoffice.Office">
 <node oor:name="AddInInfo">
   <node oor:name="org.openoffice.addin.TestAddin" oor:op="replace">
     <node oor:name="AddInFunctions">
       <node oor:name="redouble" oor:op="replace">
         <prop oor:name="DisplayName">
           <value xml:lang="en">redouble</value>
           <value xml:lang="de">verdoppeln</value>
         </prop>
         <prop oor:name="Description">
           <value xml:lang="en">simply returns the redoubled input parameter</value>
           <value xml:lang="de">liefert einfach den verdoppleten Wert des Eingabeparameters
                    zurück</value>
         </prop>
         <prop oor:name="Category">
           <value>Add-In</value>
         </prop>
         <prop oor:name="CompatibilityName">
           <value/>
         </prop>
         <node oor:name="Parameters">
           <node oor:name="nValue" oor:op="replace">
             <prop oor:name="DisplayName">
               <value xml:lang="en">nValue</value>
               <value xml:lang="de">nWert</value>
             </prop>
             <prop oor:name="Description">
               <value xml:lang="en">the input value</value>
               <value xml:lang="de">der Eingabewert</value>
             </prop>
           </node>
         </node>
       </node>
     </node>
   </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="CalcAddins.xcu"/>
 <manifest:file-entry manifest:media-type="application/vnd.sun.star.uno-typelibrary;type=RDB"
                      manifest:full-path="types.rdb"/>
 <manifest:file-entry manifest:media-type="application/vnd.sun.star.uno-component;type=Java"
                      manifest:full-path="TestAddin.jar"/>

</manifest:manifest>

  • org/test/addin/XTestAddIn.idl
    the Add-In interface describing the new Add-In functions

[idl] /*

* XTestAddin.idl
*
* Created on 05.09.2006 - 16:25:54
*
*/
  1. ifndef _org_openoffice_addin_XTestAddin_
  2. define _org_openoffice_addin_XTestAddin_
  1. include <com/sun/star/lang/XLocalizable.idl>
  1. include <com/sun/star/uno/XInterface.idl>

module org { module openoffice { module addin {

   interface XTestAddin {
       /// used to set an add-in locale for formatting reasons for example
       [optional] interface ::com::sun::star::lang::XLocalizable;
       long redouble([in] long nValue);
   };

}; }; };

  1. endif

  • org/test/addin/TestAddIn.idl
    the appropriate Add-In service definition

[idl] /*

* TestAddin.idl
*
* Created on 05.09.2006 - 16:25:54
*
*/
  1. ifndef _org_openoffice_addin_TestAddin_
  2. define _org_openoffice_addin_TestAddin_
  1. include "XTestAddin.idl"

module org { module openoffice { module addin {

   service TestAddin : XTestAddin;

}; }; };

  1. endif

  • org/test/addin/TestAddinImpl.java
    the generated Add-In code skeleton where only the Add-In functions have to be implemented. Everything else is already implemented and even the Add-In functions are default implemented, so that the new generated project can be build and the extension can be deployed directly.

[java] package org.openoffice.addin;

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 TestAddinImpl extends WeakBase

  implements org.openoffice.addin.XTestAddin,
             com.sun.star.lang.XServiceInfo,
             com.sun.star.lang.XLocalizable

{

   private final XComponentContext m_xContext;
   private static final String m_implementationName = TestAddinImpl.class.getName();
   private static final String[] m_serviceNames = {
       "org.openoffice.addin.TestAddin" };
   private com.sun.star.lang.Locale m_locale = new com.sun.star.lang.Locale();
   public TestAddinImpl( XComponentContext context )
   {
       m_xContext = context;
   }
   public static XSingleComponentFactory __getComponentFactory(String sImplementationName ) {
       XSingleComponentFactory xFactory = null;
       if ( sImplementationName.equals( m_implementationName ) )
           xFactory = Factory.createComponentFactory(TestAddinImpl.class, m_serviceNames);
       return xFactory;
   }
   public static boolean __writeRegistryServiceInfo(XRegistryKey xRegistryKey ) {
       return Factory.writeRegistryServiceInfo(m_implementationName,
                                               m_serviceNames,
                                               xRegistryKey);
   }
   // org.openoffice.addin.XTestAddin:
   public int redouble(int nValue)
   {
       // TODO !!!
       // Exchange the default return implementation.
       // NOTE: Default initialized polymorphic structs can cause problems
       // because of missing default initialization of primitive types of
       // some C++ compilers or different Any initialization in Java and C++
       // polymorphic structs.
       return 0;
   }
   // 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.lang.XLocalizable:
   public void setLocale(com.sun.star.lang.Locale eLocale)
   {
       m_locale = eLocale;
   }
   public com.sun.star.lang.Locale getLocale()
   {
       return m_locale;
   }

}

Personal tools