Difference between revisions of "Calc/Add-In/Project Type"

From Apache OpenOffice Wiki
< Calc‎ | Add-In
Jump to: navigation, search
(23 intermediate revisions by 6 users not shown)
Line 1: Line 1:
 +
Back to [[OpenOffice_NetBeans_Integration|OpenOffice.org NetBeans Integration]]
 +
 
__TOC__
 
__TOC__
  
 
= Overview =
 
= 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. This new targets will be provided at the project node later, similar to the &quot;Create NBM&quot; in a plugin module project.<br>
+
The OpenOffice.org Calc Add-In wizard creates a new project based on a J2SE class library project. It supports additional targets to create a complete OpenOffice.org extension package and to deploy this package into the configured OpenOffice.org installation.<br>
The wizard will collect 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 (live deployment of calc add-ins does currently not work).<br>
+
The wizard collects all necessary information and allows you to define new built-in Calc functions.  The new Calc functions can be used directly in Calc after you deploy the extension and restart OpenOffice.org.<br>
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.
+
After finishing the wizard you can build the project, and create and deploy the OpenOffice.org extension package. The built-in functions you just created are implemented, but do nothing yet. 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 OpenOffice.org installation.
  
 
= Project Wizard =
 
= Project Wizard =
The project wizard should be simply to use, you simply choose
+
The project wizard is quite simple to use, you simply choose
*'' '''File -> New Project -> StarOffice/OpenOffice.org -> StarOffice/OpenOffice.org Calc Add-In''' ''
+
*'' '''File -> New Project -> OpenOffice.org -> OpenOffice.org Calc Add-In''' ''
 
and follow the wizard.
 
and follow the wizard.
  
* '''Step 1''': Selecting the project type
+
* '''Step 1''': Select the project type
 
<br>[[Image:Calc_AddIn1.png|center]]<br>
 
<br>[[Image:Calc_AddIn1.png|center]]<br>
* '''Step 2''': Defining the project name and the project location  
+
* '''Step 2''': Define the project name, Add-In name, an optional package and the project location  
 
<br>[[Image:Calc_AddIn2.png|center]]<br>
 
<br>[[Image:Calc_AddIn2.png|center]]<br>
* '''Step 3''': Defining Add-In name and an optional package
+
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.<br>
<br>[[Image:Calc_AddIn2b.png|center]]<br>
+
* '''Step 4''': Define the new Add-In functions
* '''Step 4''': Defining the new Add-In functions
+
 
<br>[[Image:Calc_AddIn3.png|center]]<br>
 
<br>[[Image:Calc_AddIn3.png|center]]<br>
* '''Step 5''': Deploying the extension package
+
On this panel you can define new Calc Add-In methods on a higher abstraction level, you do not have to deal with UNO IDL or xcu files directly. You can modify the default method, and insert localized descriptions and display names ... For more detailed descriptions of the different fields simply press the help button or read the appropriate chapter in the [http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Spreadsheet_Add-Ins Developer's Guide - Spreadsheet - Add-Ins]<br>
 +
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 from a list of supported languages which are not added. When you delete a language, you can only remove languages that have been added.<br>
 +
<br>[[Image:Calc_AddIn3a.png|center]]<br>
 +
<br>[[Image:Calc_AddIn3b.png|center]]<br>
 +
* '''Step 5''': Deploy the extension package
 
<br>[[Image:Calc_AddIn4.png|center]]<br>
 
<br>[[Image:Calc_AddIn4.png|center]]<br>
 +
You can simply create or deploy the '''oxt''' extension package by choosing:<br>
 +
::'''Project View -> Project Node -> Context Menu -> Deploy and Run Extension in OpenOffice.org'''<br><br>
  
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
+
To use the Calc Add-In function(s) after you have deployed them, open a new spreadsheet document -> open the built-in function dialog -> select the “Add-In” category -> search for a new Add-In function (uppercase notation) -> click next -> enter parameters ... -> ok
  
 
<br>[[Image:Calc_AddIn5.png|center]]<br>
 
<br>[[Image:Calc_AddIn5.png|center]]<br>
Line 29: Line 36:
  
 
= Generated Code =
 
= 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:
+
The Calc Add-In wizard generates more code than can be shown here. A new config (.xcu) file for the Add-In is generated.  The config file describes the Add-In functions with descriptions, displaynames etc. The new configuration allows you to support localization of the description and display names. The underlying schema comes with OpenOffice.org 2.0.4 and will be part of the backward compatible Add-In extension packages. In the example shown above, the following files are generated:
  
 
* '''CalcAddIn.xcu'''<br>the mentioned new configuration file
 
* '''CalcAddIn.xcu'''<br>the mentioned new configuration file
* '''uno-extension-manifest.xml'''<br>the package descriptor, will be packed as &quot;META-INF/manifest.xml&quot;
+
 
 +
<source lang="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>
 +
</source>
 +
 
 +
* '''uno-extension-manifest.xml'''<br>the package descriptor, will be packed as &quot;META-INF/manifest.xml&quot;, notice that a jar containing the compiled idl types is additionally created and referenced here.
 +
 
 +
<source lang="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:file-entry manifest:media-type="application/vnd.sun.star.uno-typelibrary;type=Java"
 +
                      manifest:full-path="TestAddIn_IDL_types.jar"/>
 +
</manifest:manifest>
 +
</source>
 +
 
 
* '''org/test/addin/XTestAddIn.idl'''<br>the Add-In interface describing the new Add-In functions
 
* '''org/test/addin/XTestAddIn.idl'''<br>the Add-In interface describing the new Add-In functions
 +
 +
<source lang="idl">
 +
/*
 +
* XTestAddin.idl
 +
*
 +
* Created on 05.09.2006 - 16:25:54
 +
*
 +
*/
 +
 +
#ifndef _org_openoffice_addin_XTestAddin_
 +
#define _org_openoffice_addin_XTestAddin_
 +
 +
#include <com/sun/star/lang/XLocalizable.idl>
 +
 +
#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);
 +
    };
 +
}; }; };
 +
 +
#endif
 +
</source>
 +
 
* '''org/test/addin/TestAddIn.idl'''<br>the appropriate Add-In service definition
 
* '''org/test/addin/TestAddIn.idl'''<br>the appropriate Add-In service definition
* '''org/test/addin/TestAddinImpl.java'''<br>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.
 
  
[[Category:Calc]]
+
<source lang="idl">
[[Category:Development]]
+
/*
 +
* TestAddin.idl
 +
*
 +
* Created on 05.09.2006 - 16:25:54
 +
*
 +
*/
 +
 
 +
#ifndef _org_openoffice_addin_TestAddin_
 +
#define _org_openoffice_addin_TestAddin_
 +
 
 +
#include "XTestAddin.idl"
 +
 
 +
module org { module openoffice { module addin {
 +
    service TestAddin : XTestAddin;
 +
}; }; };
 +
 
 +
#endif
 +
</source>
 +
 
 +
* '''org/test/addin/TestAddinImpl.java'''<br>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 implemented by default, so that the new generated project can be built and the extension can be deployed directly.
 +
 
 +
<source lang="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;
 +
    }
 +
 
 +
}
 +
</source>
 +
 
 +
[[Category:Calc|Add-In/Project Type]]
 +
[[Category:Add-In|Calc/Project Type]]
 +
[[Category:API]]

Revision as of 12:04, 28 March 2010

Back to OpenOffice.org NetBeans Integration

Overview

The OpenOffice.org Calc Add-In wizard creates a new project based on a J2SE class library project. It supports additional targets to create a complete OpenOffice.org extension package and to deploy this package into the configured OpenOffice.org installation.
The wizard collects all necessary information and allows you to define new built-in Calc functions. The new Calc functions can be used directly in Calc after you deploy the extension and restart OpenOffice.org.
After finishing the wizard you can build the project, and create and deploy the OpenOffice.org extension package. The built-in functions you just created are implemented, but do nothing yet. 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 OpenOffice.org installation.

Project Wizard

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

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

and follow the wizard.

  • Step 1: Select the project type

Calc AddIn1.png

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

Calc AddIn2.png

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.

  • Step 4: Define the new Add-In functions

Calc AddIn3.png

On this panel you can define new Calc Add-In methods on a higher abstraction level, you do not have to deal with UNO IDL or xcu files directly. You can modify the default method, and insert localized descriptions and display names ... 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 from a list of supported languages which are not added. When you delete a language, you can only remove languages that have been added.


Calc AddIn3a.png


Calc AddIn3b.png

  • Step 5: Deploy the extension package

Calc AddIn4.png

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

Project View -> Project Node -> Context Menu -> Deploy and Run Extension in OpenOffice.org

To use the Calc Add-In function(s) after you have deployed them, open a new spreadsheet document -> open the built-in function dialog -> select the “Add-In” category -> search for a new Add-In function (uppercase notation) -> click next -> enter parameters ... -> ok


Calc AddIn5.png


Calc AddIn6.png

Generated Code

The Calc Add-In wizard generates more code than can be shown here. A new config (.xcu) file for the Add-In is generated. The config file describes the Add-In functions with descriptions, displaynames etc. The new configuration allows you to support localization of the description and display names. The underlying schema comes with OpenOffice.org 2.0.4 and will be part of the backward compatible Add-In extension packages. In the example shown above, the following files are generated:

  • CalcAddIn.xcu
    the mentioned new configuration file
<?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", notice that a jar containing the compiled idl types is additionally created and referenced here.
<?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:file-entry manifest:media-type="application/vnd.sun.star.uno-typelibrary;type=Java"
                       manifest:full-path="TestAddIn_IDL_types.jar"/>
</manifest:manifest>
  • org/test/addin/XTestAddIn.idl
    the Add-In interface describing the new Add-In functions
/*
 * XTestAddin.idl
 *
 * Created on 05.09.2006 - 16:25:54
 *
 */
 
#ifndef _org_openoffice_addin_XTestAddin_
#define _org_openoffice_addin_XTestAddin_
 
#include <com/sun/star/lang/XLocalizable.idl>
 
#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);
    };
}; }; };
 
#endif
  • org/test/addin/TestAddIn.idl
    the appropriate Add-In service definition
/*
 * TestAddin.idl
 *
 * Created on 05.09.2006 - 16:25:54
 *
 */
 
#ifndef _org_openoffice_addin_TestAddin_
#define _org_openoffice_addin_TestAddin_
 
#include "XTestAddin.idl"
 
module org { module openoffice { module addin {
    service TestAddin : XTestAddin;
}; }; };
 
#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 implemented by default, so that the new generated project can be built and the extension can be deployed directly.
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