12.07.2015 Views

OpenOf fice - NetBeans

OpenOf fice - NetBeans

OpenOf fice - NetBeans

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>OpenOf</strong><strong>fice</strong>.org <strong>NetBeans</strong> Integrationskeleton. The AddOns.xcu configurationfile includes the add-on parameters, andProtocolHandler.xcu defines the protocolhandler configuration. Protocol handlersare part of <strong>OpenOf</strong><strong>fice</strong>.org dispatchframework; they bind user-interface controls,such as menu or toolbar items, tothe functionality of <strong>OpenOf</strong><strong>fice</strong>.org. Everythingreachable through the user interfaceis described by a command URL and correspondingparameters.The structure of the ProtocolHandler.xcu file defines a namespacefor the add-on (org.openof<strong>fice</strong>.myaddon,for ourexample). All commandsdefined by the same addonuse this namespace.See Listing 1.The Java code skeletonlooks more complicatedthan it really is. Most ofthe methods are necessaryonly for <strong>OpenOf</strong><strong>fice</strong>.org internal implementationreasons and don’tneed to be changed at all.<strong>OpenOf</strong><strong>fice</strong>.org calls thedispatch() method each time theprotocol handler routes commands.The fully implementeddispatch() method, which addsthe “Hello World” message tothe current document is shownin Listing 2. Note that only thelines in bold are new; the restwere part of the skeleton. Thecode basically determines thecurrent document and thenadds text to it. Notice also thatthe aURL parameter uses the<strong>OpenOf</strong><strong>fice</strong>.org specific com.sun.star.util.URL class instead of thejava.net.URL class.A 2Since all commands fired by the user interface are passedthrough the dispatch() method, it’s necessary to filter explicitly forthe namespace org.openof<strong>fice</strong>.myaddon, which represents thecommands of our add-on. Finally, myAddOn is the command that’sfired when the user calls the add-on via the toolbar or menu.Our add-on is now ready to deploy. Right click the project nameand choose Deploy Of<strong>fice</strong> Extension from the context menu. Net-Beans compiles all necessary files, creates an <strong>OpenOf</strong><strong>fice</strong>.org extensionpackage file, and deploys it. Depending on the setup ofthe add-on, a new top-level menu and/or a toolbar are displayed inBListing 1. Excerpt from the ProtocolHandler.xcu configuration file.org.openof<strong>fice</strong>.myaddon:*BListing 2. dispatch() method example.public void dispatch( URL aURL, PropertyValue[] aArguments ){if ( aURL.Protocol.compareTo(“org.openof<strong>fice</strong>.myaddon:”) == 0 ) {if ( aURL.Path.compareTo(“myAddOn”) == 0 ) {XTextDocument xDoc = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, m_xFrame.getController().getModel());xDoc.getText().setString(“Hello World”);return;}}}AFigure 2Defining thetoolbar for theadd-on.Issue Three N 55

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!