Did you know? DZone has great portals for Python, Cloud, NoSQL, and HTML5!

Geertjan is a DZone Zone Leader and has posted 415 posts at DZone. You can read more from them at their website. View Full User Profile

OpenOffice on the NetBeans Platform on Ubuntu

March 08, 2010 AT 5:36 PM
  • submit to reddit

Here's where I am with my OpenOffice integration on the NetBeans Platform:

OpenOffice opens in a TopComponent and I've copied a bunch of code into the document. Clearly, that's what one would hope to have as a result of this integration. Problems that remain are that the document isn't editable, the heavyweight/lightweight thing, and when I close the window OpenOffice crashes.

But those are all details at this point. How to get to the above state? Create a NetBeans Platform application, with a module that has this content:

Next, in the Installer, add this code:

public class Installer extends ModuleInstall {

    @Override
    public void restored() {
        WindowManager.getDefault().invokeWhenUIReady(new Runnable() {
            @Override
            public void run() {
                try {
                    OOoBean oBean = new OOoBean();
                    TopComponent tc = WindowManager.getDefault().findTopComponent("OooTopComponent");
                    tc.add(oBean);
                    oBean.loadFromURL("private:factory/swriter", null);
                    Thread.sleep(3000);
                    oBean.aquireSystemWindow();
                } catch (InterruptedException ex) {
                    Exceptions.printStackTrace(ex);
                } catch (SystemWindowException ex) {
                    Exceptions.printStackTrace(ex);
                } catch (IOException ex) {
                    Exceptions.printStackTrace(ex);
                } catch (IllegalArgumentException ex) {
                    Exceptions.printStackTrace(ex);
                } catch (CloseVetoException ex) {
                    Exceptions.printStackTrace(ex);
                } catch (NoConnectionException ex) {
                    Exceptions.printStackTrace(ex);
                }
            }
        });
    }

}
 

The Thread.sleep is to provide some time while OpenOffice starts up and is embedded, but maybe that time isn't necessary after all.

The most important thing to get this to work is to include the appropriate JARs and native libs:

 

The bootstrapconnector.jar comes from here and is required for finding the OpenOffice installation, though that isn't necessary in this sample. (It is used in a different scenario where I wanted to simply open OpenOffice, not embed it. I don't think OfficeBean requires the above.) On the other hand, libjpipe.so is crucial (get it from /usr/lib/ure/lib).

More experiments with this scenario coming soon. Hope someone can help with the problems pointed out above, re editable mode of the OpenOffice document, especially.

 

 

0
Average: 5 (1 vote)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Toni Epple replied on Tue, 2010/03/09 - 4:00am

Which version of Java do you use? Heavyweight-Lightweight shouldn't be a problem anymore with JDK > u12:

http://java.sun.com/developer/technicalArticles/GUI/mixing_components/index.html

Enrico Scantamburlo replied on Fri, 2010/03/12 - 10:27am

Geerjan, have you set any Enviromental variable to make it work ?

Santi Srilasak replied on Sat, 2010/09/04 - 9:26pm

Help Please, OOoBean.aquireSystemWindow throws SystemWindowException and OOoBean does not fit in Netbeans application's window. I use Netbeans Platform 6.9 and Open Office 3.2.0. The unoil.jar attached from Open Office 3.2 library does not support ClassVetoException. To solve this compile error I download from internet so that application can build but the application throws the above error. Regards, Santi Srilasak

Robson Peixoto replied on Thu, 2012/01/12 - 1:46pm

If you set the env SAL_USE_VCLPLUGIN=gen on linux, you will can edit the document.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.