UNO, how to use theDesktop singleton instead of deprecated Desktop?

Alberto González Palomo alberto at matracas.org
Wed Sep 21 17:45:45 UTC 2016


   I have a working Java application that uses UNO with LibreOffice 5.
   I'm using createInstanceWithContext for com.sun.star.frame.Desktop, 
but in the documentation it says that this interface is deprecated and 
we should use the "theDesktop singleton" instead:

http://api.libreoffice.org/docs/idl/ref/servicecom_1_1sun_1_1star_1_1frame_1_1Desktop.html#details

   However I haven't found any information on how to do that.

   I acquire the component loader as follows:

-----------------------------------------
com.sun.star.uno.XComponentContext       componentContext;
com.sun.star.lang.XMultiComponentFactory serviceManager;
com.sun.star.frame.XComponentLoader      componentLoader;
componentContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
serviceManager   = componentContext.getServiceManager();
componentLoader  =
     UnoRuntime.queryInterface
     (com.sun.star.frame.XComponentLoader.class,
      serviceManager.createInstanceWithContext
      ("com.sun.star.frame.Desktop", componentContext)
      )
     ;
-----------------------------------------

   I've tried writing "com.sun.star.frame.theDesktop" instead of the 
call to serviceManager.createInstanceWithContext() but that doesn't 
compile, then I tried some other semi-random stuff but nothing worked.

   How can I do that?
   Is this documented anywhere, or is there any example that uses 
theDesktop instead of Desktop?

   Cheers,
-- 
     Alberto González Palomo
     Toledo, España / Saarbrücken, Deutschland
     http://www.matracas.org


More information about the LibreOffice mailing list