OpenOffice.org Extensions development in Java with NetBeans in practise. Jürgen Schmidt OpenOffice.org Sun Microsystems, Inc.



Similar documents
NetBeans IDE Field Guide

Tutorial Reference Manual. Java WireFusion 4.1

Web Services API Developer Guide

NetBeans IDE Field Guide

OpenOffice.org 2.x... and beyond. Michael Bemmer Director Software Engineering StarOffice/OpenOffice.org Sun Microsystems

Eclipse Rich Client Platform. Kai Tödter Karsten Becker et al. Organized by:

Installing the Android SDK

With a single download, the ADT Bundle includes everything you need to begin developing apps:

Getting Started Guide. Chapter 14 Customizing LibreOffice

Selenium Automation set up with TestNG and Eclipse- A Beginners Guide

Tutorial: setting up a web application

IBM Tivoli Workload Scheduler Integration Workbench V8.6.: How to customize your automation environment by creating a custom Job Type plug-in

Oracle WebLogic Foundation of Oracle Fusion Middleware. Lawrence Manickam Toyork Systems Inc

JAVA WEB START OVERVIEW

Learn how to create web enabled (browser) forms in InfoPath 2013 and publish them in SharePoint InfoPath 2013 Web Enabled (Browser) forms

INFOPATH FORMS FOR OUTLOOK, SHAREPOINT, OR THE WEB

Work with XI 3.0 Java Proxies

TESTING WITH JUNIT. Lab 3 : Testing

Hosted VoIP Phone System. Meet-Me Conferencing Add-in for Microsoft Outlook

INTEGRATING MICROSOFT DYNAMICS CRM WITH SIMEGO DS3

Using the Monitoring and Report Viewer Web Services

ADT Plugin for Eclipse

Running a Program on an AVD

An Overview of Java. overview-1

FAQ CE 5.0 and WM 5.0 Application Development

WIRIS quizzes web services Getting started with PHP and Java

Automation using Selenium

C O N F I G U R I N G Y O U R W E B B R O W S E R TO A L L O W P O P - U P W I N D O W S

user guide version 4.1

Installing Java. Table of contents

Oracle SOA Suite 11g Oracle SOA Suite 11g HL7 Inbound Example

The Benefits of Modular Programming

Brekeke PBX Web Service

UML PROFILING AND DSL

Java. How to install the Java Runtime Environment (JRE)

Law Conferencing uses the Webinterpoint 8.2 web conferencing platform. This service is completely reservationless and available 24/7.

DEVELOPING CONTRACT - DRIVEN WEB SERVICES USING JDEVELOPER. The purpose of this tutorial is to develop a java web service using a top-down approach.

Android Application Development: Hands- On. Dr. Jogesh K. Muppala

Introduction to Mobile Phone. Programming in Java Me

Web Service Caching Using Command Cache

Braindumps.C questions

One of the fundamental kinds of Web sites that SharePoint 2010 allows

NetBeans: Universal Tool for Java Development and More. Roman Štrobl Technology Evangelist

Chapter 12 Creating Web Pages

SilkTest Workbench. Getting Started with.net Scripts

Overview of Web Services API

Programming with Android: SDK install and initial setup. Dipartimento di Informatica: Scienza e Ingegneria Università di Bologna

Creating a Java application using Perfect Developer and the Java Develo...

Overview of Active Directory Rights Management Services with Windows Server 2008 R2

Chapter 12 Creating Web Pages

Xiaoming Gao Hui Li Thilina Gunarathne

HOBOlink Web Services V2 Developer s Guide

Glassfish, JAVA EE, Servlets, JSP, EJB

Programming Android Smart Phones. Tom Chothia Internet Computing Workshop

Visual Basic. murach's TRAINING & REFERENCE

WORKING WITH LOAD BALANCING AND QUEUEING FOR ADOBE INDESIGN CS5 SERVER

Developing SQL and PL/SQL with JDeveloper

Appium mobile test automation

Quartz.Net Scheduler in Depth

PACK'N DEPLOY GUIDE. Version 2.58

SSRS Reporting Using Report Builder 3.0. By Laura Rogers Senior SharePoint Consultant Rackspace Hosting

Using Netbeans and the Derby Database for Projects Contents

Smartphone market share

Data Flow Static Code Analysis Best Practices

Hello World RESTful web service tutorial

Tutorial 5: Developing Java applications

Crystal Reports for Eclipse

PTC Integrity Eclipse and IBM Rational Development Platform Guide

HP AppPulse Mobile. Adding HP AppPulse Mobile to Your Android App

Java CPD (I) Frans Coenen Department of Computer Science

<Insert Picture Here> What's New in NetBeans IDE 7.2

NLUI Server User s Guide

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

Getting Started with Telerik Data Access. Contents

OTN Developer Day: Oracle Big Data. Hands On Lab Manual. Introduction to Oracle NoSQL Database

IBM Operational Decision Manager Version 8 Release 5. Getting Started with Business Rules

T300 Acumatica Customization Platform

IBM Configuring Rational Insight and later for Rational Asset Manager

WESTERNACHER OUTLOOK -MANAGER OPERATING MANUAL

Oracle FLEXCUBE Direct Banking Android Tab Client Installation Guide Release

Getting Started with Microsoft Office Live Meeting. Published October 2007

Creating Form Rendering ASP.NET Applications

Systems must meet the following requirements when using the Matrix WebConnect service: Average Network Bandwidth Utilization

Quick Start Guide Mobile Entrée 4

Xcode Project Management Guide. (Legacy)

Android Mobile App Building Tutorial

Java Language Tools COPYRIGHTED MATERIAL. Part 1. In this part...

What is OpenOffice.org?

Getting Started with Microsoft Office Live Meeting. Published October 2007 Last Update: August 2009

Developer Guide. Android Printing Framework. ISB Vietnam Co., Ltd. (IVC) Page i

SDK Quick Start Guide

Getting Started Guide Testable Architecture

Development. with NetBeans 5.0. A Quick Start in Basic Web and Struts Applications. Geertjan Wielenga

Shakambaree Technologies Pvt. Ltd.

Web Conferencing User Guide

McAfee Cloud Identity Manager

FAQ: troubleshooting Java for Saba Web Access

System Administration Training Guide. S100 Installation and Site Management

Introduction to Android Development. Jeff Avery CS349, Mar 2013

Acrolinx IQ. Acrolinx IQ Plug-in for Adobe CQ Rich Text Editor Installation Guide Version: 2.9

Transcription:

OpenOffice.org Extensions development in Java with NetBeans in practise Jürgen Schmidt OpenOffice.org Sun Microsystems, Inc. 1

OpenOffice.org Extensions development in Java with NetBeans in practise Motivation Introduction Demo I: Smart Tag Extension Demo II: Addon with Option page More Information foss.in Indian's Premier FOSS Event December 2007 2

Motivation for OpenOffice.org Extensions Growing popularity of ODF worldwide Growing popularity of OpenOffice.org Multi platform support > Solaris/Open Solaris, Linux, Windows, Mac OS,... Demand for customization, extending or integration of the OpenOffice.org Community building > lower entry barrier > fast feeling of success foss.in Indian's Premier FOSS Event December 2007 3

Introduction OpenOffice.org API plugin for NetBeans New specialized project types > > > > > > > Wizards to speed up development Support for UNOIDL and configuration files Context sensitive API help Code completion Debug support Pre-configured OpenOffice.org library Online update foss.in Indian's Premier FOSS Event December 2007 4

Introduction OpenOffice.org API plugin for NetBeans UNO client application project > Primary a normal Java 2 Platform, Standard Edition (J2SE platform) project > Special packaging Bundle UNO bootstrap glue code from the SDK Search default office, Customized classloader Special manifest entries > > > > Provide remote Office context Office start on demand Named pipe connection Typical use case remote control of OpenOffice.org foss.in Indian's Premier FOSS Event December 2007 5

Introduction OpenOffice.org API plugin for NetBeans Common for all UNO component project types > > > > > > > > Specialized J2SE class library project Generated code skeletons Completely functional, buildable out of the box Special packaging support Office extension packages (.oxt) Debug support Final deployment in target office Project properties for Extension Identifier, Dependencies and Licenses foss.in Indian's Premier FOSS Event December 2007 6

Introduction OpenOffice.org API plugin for NetBeans Calc Add-in project > High-level definition of new built-in Calc function Abstraction from underlying technology > Localization support Function, parameter names and descriptions Completely functional skeleton > Generated code for Calc add-in specific interfaces > Add-in functions default implemented foss.in Indian's Premier FOSS Event December 2007 7

Introduction OpenOffice.org API plugin for NetBeans Add-on project wizard > User interface integration > High-level definition of New commands Top level menu with menu entries and/or sub-menus Toolbar with simple button controls > Localization support > Menu and toolbar entries > Default implementation for add-on specific interfaces SPI: com.sun.star.frame.protocolhandler foss.in Indian's Premier FOSS Event December 2007 8

Introduction OpenOffice.org API plugin for NetBeans UNO Component project wizard > Integrated UNOIDL wizard Definition of new type definitions Type browser for existing Office types Reuse in new types Implementation of existing services and/or interfaces > Completely functional code skeletons Generated code for component specific interfaces Default implementation for interface methods New File Type Java UNO Object > similar to the Component project wizard foss.in Indian's Premier FOSS Event December 2007 9

Demo I: OOIssue Smart Tag Java UNO component Extension Implements two objects > OOIssueSmartTag recognizer com.sun.star.smarttag.smarttagrecognizer detect OpenOffice.org Issues in the form of i94678 no properties dialog > OOIssueSmartTagAction com.sun.star.smarttag.smarttagaction two actions are be implemented View in Browser Replace by URL foss.in Indian's Premier FOSS Event December 2007 10

Demo I: OOIssue Smart Tag Select File New Project OpenOffice.org Component foss.in Indian's Premier FOSS Event December 2007 11

Demo I: OOIssue Smart Tag Specify your project properties foss.in Indian's Premier FOSS Event December 2007 12

Demo I: OOIssue Smart Tag Select the com.sun.star.smarttags.smarttagrecognizer foss.in Indian's Premier FOSS Event December 2007 13

Demo I: OOIssue Smart Tag Finish the wizard to create the new project foss.in Indian's Premier FOSS Event December 2007 14

Demo I: OOIssue Smart Tag Create a second UNO implementation object foss.in Indian's Premier FOSS Event December 2007 15

Demo I: OOIssue Smart Tag Select com.sun.star.smarttags.smarttagaction and finish foss.in Indian's Premier FOSS Event December 2007 16

Demo I: OOIssue Smart Tag Extend the generated SmartTagRecognizer object... private static final String m_smarttagtype = "org.openoffice#oooissue"; public static String getoooissuesmarttagname() { return m_smarttagtype;... // com.sun.star.smarttags.xsmarttagrecognizer: public int getsmarttagcount() { return 1; // let these function default implemented public String getname(locale alocale) public String getdescription(locale alocale)... foss.in Indian's Premier FOSS Event December 2007 17

Demo I: OOIssue Smart Tag Extend the generated SmartTagRecognizer object... public String getsmarttagname(int nsmarttagindex) throws com.sun.star.lang.indexoutofboundsexception { return m_smarttagtype; // let public public public these function default implemented String getsmarttagdownloadurl(int nsmarttagindex) boolean haspropertypage(...) void displaypropertypage() foss.in Indian's Premier FOSS Event December 2007 18

Demo I: OOIssue Smart Tag Extend the generated SmartTagRecognizer object... public void recognize(...) { final int nendpos = nstart + nlength; Boundary awordbounds = xtokenizer.getwordboundary( atext, nstart, alocale, WordType.DICTIONARY_WORD, true ); while ( awordbounds.startpos < awordbounds.endpos && awordbounds.endpos <= nendpos ) { final String aword = atext.substring(awordbounds.startpos, awordbounds.endpos); if ( aword.matches("i\\d{5,6") ) { XStringKeyMap xprops = null; xtextmarkup.committextmarkup( TextMarkupType.SMARTTAG, m_smarttagtype, awordbounds.startpos, awordbounds.endpos awordbounds.startpos, xprops ); // continue with next word awordbounds = xtokenizer.nextword( atext, awordbounds.startpos, alocale, WordType.DICTIONARY_WORD ); foss.in Indian's Premier FOSS Event December 2007 19

Demo I: OOIssue Smart Tag Extend the generated SmartTagAction object... private final int m_idbase = this.hashcode(); private static final String[] m_actionnames = { "oooissueviewaction", "oooissuereplacebyurlaction" ; private static final String[] m_actioncaptions = { "View Issue in Browser", "Replace by Url" ;... // com.sun.star.smarttags.xsmarttagaction: public int getsmarttagcount() { return 1; // let these functions default implemented public String getname(com.sun.star.lang.locale alocale) public String getdescription(com.sun.star.lang.locale alocale) public String getsmarttagname(int nsmarttagindex) throws com.sun.star.lang.indexoutofboundsexception { return OOoIssueSmartTag.getOOoIssueSmartTagName();... foss.in Indian's Premier FOSS Event December 2007 20

Demo I: OOIssue Smart Tag Extend the generated SmartTagAction object... public String getsmarttagcaption(int nsmarttagindex, Locale alocale) throws com.sun.star.lang.indexoutofboundsexception { return "OpenOffice.org Issue"; public int getactioncount(string asmarttagname, XController xcontroller) { return 2; public int getactionid(string asmarttagname, int nactionindex, XController xcontroller) throws com.sun.star.lang.illegalargumentexception { return m_idbase + nactionindex; public String getactioncaptionfromid(int nactionid,...) throws com.sun.star.lang.illegalargumentexception { return m_actioncaptions[nactionid - m_idbase]; public String getactionnamefromid(int nactionid, XController xcontroller) throws com.sun.star.lang.illegalargumentexception { return m_actionnames[nactionid - m_idbase]; foss.in Indian's Premier FOSS Event December 2007 21

Demo I: OOIssue Smart Tag Extend the generated SmartTagAction object... public void invokeaction(int nactionid, String aapplicationname, com.sun.star.frame.xcontroller xcontroller, com.sun.star.text.xtextrange xtarget, com.sun.star.container.xstringkeymap xproperties, String atext, String axml, com.sun.star.lang.locale alocale) throws com.sun.star.lang.illegalargumentexception { final int index = nactionid - m_idbase; if (index == 0) { viewaction(aapplicationname, xcontroller, xtarget, xproperties, atext, axml, alocale); else if (index == 1) { replaceaction(aapplicationname, xcontroller, xtarget, xproperties, atext, axml, alocale); // let these function default implmeented public boolean iscaptiondynamic(...) public boolean isshowsmarttagindicator(...) foss.in Indian's Premier FOSS Event December 2007 22

Demo I: OOIssue Smart Tag Extend the generated SmartTagAction object... private void viewaction(string aapplicationname, com.sun.star.frame.xcontroller xcontroller, com.sun.star.text.xtextrange xtarget, com.sun.star.container.xstringkeymap xproperties, String atext, String axml, com.sun.star.lang.locale alocale) throws com.sun.star.lang.illegalargumentexception { try { final XMultiComponentFactory xfact = m_xcontext.getservicemanager(); final Object xobject = xfact.createinstancewithcontext( "com.sun.star.system.systemshellexecute", m_xcontext); final XSystemShellExecute xsystemshellexecute = (XSystemShellExecute) UnoRuntime.queryInterface(XSystemShellExecute.class, xobject); String aurlstring = "http://www.openoffice.org/issues/show_bug.cgi?id=" + xtarget.getstring().substring(1); xsystemshellexecute.execute( aurlstring, "", com.sun.star.system.systemshellexecuteflags.defaults ); catch (Exception ex) { ex.printstacktrace(); foss.in Indian's Premier FOSS Event December 2007 23

Demo I: OOIssue Smart Tag Extend the generated SmartTagAction object... private void replaceaction(string aapplicationname, com.sun.star.frame.xcontroller xcontroller, com.sun.star.text.xtextrange xtarget, com.sun.star.container.xstringkeymap xproperties, String atext, String axml, com.sun.star.lang.locale alocale) throws com.sun.star.lang.illegalargumentexception { String aurlstring = "http://www.openoffice.org/issues/show_bug.cgi?id=" + xtarget.getstring().substring(1); XPropertySet xprop = (XPropertySet)UnoRuntime.queryInterface( XPropertySet.class, xtarget); if (xprop!= null) { try { xprop.setpropertyvalue("hyperlinkurl", aurlstring); catch (Exception ex) { ex.printstacktrace(); foss.in Indian's Premier FOSS Event December 2007 24

Demo Step By Step example OOIssue Smart Tag Extension 25

Demo I: Addon with Option page Simple Add-On example Options page > Two configuration options Message ColoredMessage New menu and toolbar > Both with a Insert Message command Insert the configured message at the end of the document Text color depends on the Colored Message flag > Visible in the Writer context only foss.in Indian's Premier FOSS Event December 2007 26

Demo I: Addon with Option page Select File New Project OpenOffice.org Add-On foss.in Indian's Premier FOSS Event December 2007 27

Demo I: Addon with Option page Specify your project properties foss.in Indian's Premier FOSS Event December 2007 28

Demo I: Addon with Option page Define a new command and localized display names foss.in Indian's Premier FOSS Event December 2007 29

Demo I: Addon with Option page Define a new menu and arrange your commands foss.in Indian's Premier FOSS Event December 2007 30

Demo I: Addon with Option page Define a new toolbar and arrange your commands foss.in Indian's Premier FOSS Event December 2007 31

Demo I: Addon with Option page Create a new configuration schema (I) foss.in Indian's Premier FOSS Event December 2007 32

Demo I: Addon with Option page Create a new configuration schema (II) foss.in Indian's Premier FOSS Event December 2007 33

Demo I: Addon with Option page Create a new OptionHandler service with implementation (I) foss.in Indian's Premier FOSS Event December 2007 34

Demo I: Addon with Option page Create a new OptionHandler service with implementation (II) foss.in Indian's Premier FOSS Event December 2007 35

Demo I: Addon with Option page Create a new OptionHandler service with implementation (III) foss.in Indian's Premier FOSS Event December 2007 36

Demo I: Addon with Option page Create a new DemoOptionsDialog configuration file (I) foss.in Indian's Premier FOSS Event December 2007 37

Demo I: Addon with Option page Create a new DemoOptionsDialog configuration file (II) foss.in Indian's Premier FOSS Event December 2007 38

Demo I: Addon with Option page Create a new DemoOptionsDialog with the Office (I) foss.in Indian's Premier FOSS Event December 2007 39

Demo I: Addon with Option page Create a new DemoOptionsDialog with the Office (II) foss.in Indian's Premier FOSS Event December 2007 40

Demo I: Addon with Option page Create a new DemoOptionsDialog with the Office (III) foss.in Indian's Premier FOSS Event December 2007 41

Demo I: OOIssue Smart Tag Define the configuration schema (WorkshopOptionsDemo.xcs) <?xml version="1.0" encoding="utf-8"?> <oor:component-schema xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/xmlschema" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" oor:name="workshopoptions" oor:package="org.openoffice.workshop.demo" xml:lang="en-us"> <info> <author></author> <esc>contains the options data used for the workshop demo extension.</desc> </info> <component> <group oor:name="demooptions"> <info> <desc>the data properties for the demo option page.</desc> </info> <prop oor:name="message" oor:type="xs:string"> <value>hello FOSS.in Conference 2007</value> </prop> <prop oor:name="coloredmessage" oor:type="xs:boolean"> <value>false</value> </prop> </group> </component> </oor:component-schema> foss.in Indian's Premier FOSS Event December 2007 42

Demo I: OOIssue Smart Tag Define the configuration for dialog (DemoOptionsDialog.xcu) <?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" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" oor:name="optionsdialog" oor:package="org.openoffice.office"> <node oor:name="nodes"> <node oor:name="writer" oor:op="fuse"> <node oor:name="leaves"> <node oor:name="org.openoffice.workshop.demo.options" oor:op="fuse"> <prop oor:name="id"> <value>org.openoffice.demo.workshopoptionsdemo</value> </prop> <prop oor:name="label"> <value xml:lang="en-us">workshop Demo</value> </prop> <prop oor:name="optionspage"> <value>%origin%/dialogs/demooptionsdialog.xdl</value> </prop> <prop oor:name="eventhandlerservice"> <value>org.openoffice.demo.demooptionshandler</value> </prop> </node> </node></node></node> </oor:component-data> foss.in Indian's Premier FOSS Event December 2007 43

Demo I: OOIssue Smart Tag Extend the generated WorkshopOptionsDemo Add-On... private XPropertySet m_xdemooptions = null;... // com.sun.star.frame.xdispatch: public void dispatch(url aurl, PropertyValue[] aarguments ) { if ( aurl.protocol.compareto("org.openoffice.demo.workshopoptionsdemo:") == 0 ) { if ( aurl.path.compareto("insertmsg") == 0 ) { try { XTextDocument xdoc = (XTextDocument)UnoRuntime.queryInterface( XTextDocument.class, m_xframe.getcontroller().getmodel()); XText xtext = xdoc.gettext(); XTextCursor xcursor = xtext.createtextcursor(); xcursor.gotoend(false); xtext.insertstring(xcursor, readmessage(), true); settextcolor(xcursor); xcursor.gotoend(false); xtext.insertcontrolcharacter(xcursor, ControlCharacter.PARAGRAPH_BREAK, false); catch (com.sun.star.uno.exception e) { e.printstacktrace(); foss.in Indian's Premier FOSS Event December 2007 44

Demo I: OOIssue Smart Tag Extend the generated WorkshopOptionsDemo Add-On private String readmessage() { String msg = ""; if (m_xdemooptions == null ) initoptionsdata(); try { msg = AnyConverter.toString(m_xDemoOptions.getPropertyValue("Message")); catch (com.sun.star.uno.exception e) { e.printstacktrace(); return msg; private void settextcolor(xtextcursor xcursor) { if (m_xdemooptions == null ) initoptionsdata(); try { if (AnyConverter.toBoolean(m_xDemoOptions.getPropertyValue("ColoredMessage"))) { XPropertySet xprop = (XPropertySet)UnoRuntime.queryInterface( XPropertySet.class, xcursor); int c = AnyConverter.toInt(xProp.getPropertyValue("CharColor")); xprop.setpropertyvalue("charcolor", 0xff0000); xcursor.collapsetoend(); xprop.setpropertyvalue("charcolor", c); catch (com.sun.star.uno.exception e) { e.printstacktrace(); foss.in Indian's Premier FOSS Event December 2007 45

Demo I: OOIssue Smart Tag Extend the generated WorkshopOptionsDemo Add-On private void initoptionsdata() { try { XMultiServiceFactory xconfig = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, m_xcontext.getservicemanager().createinstancewithcontext( "com.sun.star.configuration.configurationprovider", m_xcontext)); Object[] args = new Object[1]; args[0] = new PropertyValue("nodepath", 0, "/org.openoffice.workshop.demo.workshopoptions/demooptions", PropertyState.DIRECT_VALUE); m_xdemooptions = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xconfig.createinstancewitharguments( "com.sun.star.configuration.configurationaccess", args)); catch (com.sun.star.uno.exception e) { e.printstacktrace(); foss.in Indian's Premier FOSS Event December 2007 46

Demo I: OOIssue Smart Tag Extend the generated DemoOptionsHandler object... private final XMultiComponentFactory m_xmcf; private XPropertySet m_xpropoptions = null; private final String m_resrooturl;... public DemoOptionsHandlerImpl( XComponentContext context ) { m_xcontext = context; m_xmcf = m_xcontext.getservicemanager(); XPackageInformationProvider xpkginfo = PackageInformationProvider.get(m_xContext); m_resrooturl = xpkginfo.getpackagelocation( "org.openoffice.demo.workshopoptionsdemo") + "/dialogs/"; XMultiServiceFactory xconfig; try { xconfig = (XMultiServiceFactory) UnoRuntime.queryInterface( xmultiservicefactory.class, xmcf.createinstancewithcontext( "com.sun.star.configuration.configurationprovider", m_xcontext)); catch (com.sun.star.uno.exception e) { e.printstacktrace(); return;... foss.in Indian's Premier FOSS Event December 2007 47

Demo I: OOIssue Smart Tag Extend the generated DemoOptionsHandler object... public DemoOptionsHandlerImpl( XComponentContext context ) {... Object[] args = new Object[1]; args[0] = new PropertyValue("nodepath", 0, "/org.openoffice.workshop.demo.workshopoptions/demooptions", PropertyState.DIRECT_VALUE); try { m_xpropoptions = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xconfig.createinstancewitharguments( "com.sun.star.configuration.configurationupdateaccess", args)); catch (com.sun.star.uno.exception e) { e.printstacktrace(); return; ; foss.in Indian's Premier FOSS Event December 2007 48

Demo I: OOIssue Smart Tag Extend the generated DemoOptionsHandler object... // com.sun.star.awt.xcontainerwindoweventhandler: public boolean callhandlermethod(com.sun.star.awt.xwindow xwindow, Object aeventobject, String smethodname) throws com.sun.star.lang.wrappedtargetexception { if (smethodname.equals("external_event") ) { try { return handleexternalevent(xwindow, aeventobject); catch (com.sun.star.uno.runtimeexception re) { throw re; catch (com.sun.star.uno.exception e) { throw new WrappedTargetException(sMethodName, this, e); return true; public String[] getsupportedmethodnames() { return new String[] {"external_event"; foss.in Indian's Premier FOSS Event December 2007 49

Demo I: OOIssue Smart Tag Extend the generated DemoOptionsHandler object... private boolean handleexternalevent(com.sun.star.awt.xwindow awindow, Object aeventobject) throws com.sun.star.uno.exception { try { String smethod = AnyConverter.toString(aEventObject); if (smethod.equals("ok")) { savedata(awindow); else if (smethod.equals("back") smethod.equals("initialize")) { loaddata(awindow); catch (com.sun.star.lang.illegalargumentexception e) { throw new com.sun.star.lang.illegalargumentexception( "Method external_event requires a string in the event object argument.", this, (short) -1); return true; foss.in Indian's Premier FOSS Event December 2007 50

Demo I: OOIssue Smart Tag Extend the generated DemoOptionsHandler object private void savedata(com.sun.star.awt.xwindow awindow) throws com.sun.star.lang.illegalargumentexception, com.sun.star.uno.exception { XControlContainer xcontainer = (XControlContainer) UnoRuntime.queryInterface( XControlContainer.class, awindow); if (xcontainer == null) throw new com.sun.star.uno.exception( "Could not get XControlContainer from window.", this); XControl xcontrol = xcontainer.getcontrol("coloredmessage"); if (xcontrol!= null) { XCheckBox xcheckbox = (XCheckBox)UnoRuntime.queryInterface( XCheckBox.class, xcontrol); if (xcheckbox.getstate() == 0) m_xpropoptions.setpropertyvalue("coloredmessage", new Boolean(false)); else m_xpropoptions.setpropertyvalue("coloredmessage", new Boolean(true));... foss.in Indian's Premier FOSS Event December 2007 51

Demo I: OOIssue Smart Tag Extend the generated DemoOptionsHandler object private void savedata(com.sun.star.awt.xwindow awindow) throws com.sun.star.lang.illegalargumentexception, com.sun.star.uno.exception {... xcontrol = xcontainer.getcontrol("message"); if (xcontrol!= null) { XPropertySet xprop = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xcontrol.getmodel()); Object atext = xprop.getpropertyvalue("text"); m_xpropoptions.setpropertyvalue("message", AnyConverter.toString(aText)); //Committing the changes will cause or changes to be written to the registry. XChangesBatch xupdatecommit = (XChangesBatch) UnoRuntime.queryInterface( XChangesBatch.class, m_xpropoptions); xupdatecommit.commitchanges(); foss.in Indian's Premier FOSS Event December 2007 52

Demo I: OOIssue Smart Tag Extend the generated DemoOptionsHandler object private void loaddata(com.sun.star.awt.xwindow awindow) throws com.sun.star.uno.exception { XControlContainer xcontainer = (XControlContainer) UnoRuntime.queryInterface( XControlContainer.class, awindow); if (xcontainer == null) throw new com.sun.star.uno.exception( "Could not get XControlContainer from window.", this); // init the image control, just a worksaround XControl xcontrol = xcontainer.getcontrol("logoimage"); if (xcontrol!= null) { XPropertySet xprop = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xcontrol.getmodel()); xprop.setpropertyvalue("imageurl", m_resrooturl + "fossinlogo.jpg");... foss.in Indian's Premier FOSS Event December 2007 53

Demo I: OOIssue Smart Tag Extend the generated DemoOptionsHandler object private void loaddata(com.sun.star.awt.xwindow awindow) throws com.sun.star.uno.exception {... xcontrol = xcontainer.getcontrol("coloredmessage"); if (xcontrol!= null) { XCheckBox xcheckbox = (XCheckBox)UnoRuntime.queryInterface( XCheckBox.class, xcontrol); Object avalue = m_xpropoptions.getpropertyvalue("coloredmessage"); if (AnyConverter.toBoolean(aValue)) xcheckbox.setstate((short)1); else xcheckbox.setstate((short)0);... foss.in Indian's Premier FOSS Event December 2007 54

Demo I: OOIssue Smart Tag Extend the generated DemoOptionsHandler object private void loaddata(com.sun.star.awt.xwindow awindow) throws com.sun.star.uno.exception {... xcontrol = xcontainer.getcontrol("message"); if (xcontrol!= null) { Object avalue = m_xpropoptions.getpropertyvalue("message"); XPropertySet xprop = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xcontrol.getmodel()); xprop.setpropertyvalue("text", avalue); foss.in Indian's Premier FOSS Event December 2007 55

Demo Step By Step example WorkshopDemoAddon Extensions with own an Option page 56

More information API project > home page: api.openoffice.orgmailing list: dev@api.openoffice.org > IRC (freenode): #ooo-api for all API relevant topics Extensions project > home page: extensions.openoffice.org > mailing list: dev@extensions.openoffice.org > IRC (freenode): #ooo-ext for general extension topics OpenOffice.org Wiki > OpenOffice.org API plugin for NetBeans http://wiki.services.openoffice.org/wiki/openoffice_netbeans_int egration foss.in Indian's Premier FOSS Event December 2007 57

Q&A foss.in Indian's Premier FOSS Event December 2007 58

OpenOffice.org Extensions development in Java with NetBeans in practise Jürgen Schmidt juergen.schmidt@sun.com