On Thu, Jan 31, 2013 at 05:48:11PM +0000, Steele, Raymond wrote:
> Thanks for the feedback. 
> 
> I implemented the following, but the method kills off any other
> instance of soffice that is running. 
> 
> Desktop_obj
> = component_factory.createInstanceWithContext("com.sun.star.frame.Desktop",
> context); XDesktop desktop = UnoRuntime.queryInterface(XDesktop.class,
> desktop_obj); desktop.terminate();
> 
> Any way that I can close the instance without killing off other
> soffice instances?

What do you mean by "instance"? There is only one instance of
soffice.bin per application using the same user installation directory.

If you mean that it closes all other documents, then you can check if
this document is the last opened document, and if true, terminate the
desktop:
http://www.openoffice.org/api/docs/common/ref/com/sun/star/frame/XDesktop.html#getComponents

XComponentLoader xComponentLoader = UnoRuntime.queryInterface(
    XComponentLoader.class,
    xContext.getServiceManager().createInstanceWithContext(
        "com.sun.star.frame.Desktop", xContext));
XTextDocument xTextDocument = UnoRuntime.queryInterface(
     XTextDocument.class,
     xComponentLoader.loadComponentFromURL(
        "private:factory/swriter",
        "_default",
        FrameSearchFlag.ALL,
        new PropertyValue[]{}));
xTextDocument.getText().setString("Dummy text.");

XCloseable xCloseable = UnoRuntime.queryInterface(
    XCloseable.class, xTextDocument);
xCloseable.close(true);

XDesktop xDesktop = UnoRuntime.queryInterface(
    XDesktop.class, xComponentLoader);
XEnumerationAccess xEnumerationAccess = xDesktop.getComponents();

if (!xEnumerationAccess.hasElements()) {
    xDesktop.terminate();
}


Regards
-- 
Ariel Constenla-Haile
La Plata, Argentina

Attachment: pgpnA9g8bsyQb.pgp
Description: PGP signature

Reply via email to