Hi Denis,

To 1)

The following code is a little example how to execute a dispatch in java:

private static void updateFields(XComponentContext componentContext, Object
oDesktop, String unoUrl) throws com.sun.star.uno.Exception,
MalformedURLException, UpdateIndexesException {
       XMultiComponentFactory serviceManager =
componentContext.getServiceManager();
       XDesktop xd = (XDesktop)UnoRuntime.queryInterface(XDesktop.class,
oDesktop);
       final Object helper = serviceManager.createInstanceWithContext("
com.sun.star.frame.DispatchHelper", componentContext);
       XDispatchHelper xdh = (XDispatchHelper)UnoRuntime.queryInterface(
XDispatchHelper.class, helper);

       // this code is executed from a remote machinbe via uno, so we need
to identify the right document
       XEnumerationAccess xea = xd.getComponents();
       XEnumeration xe = xea.createEnumeration();

       XModel currentModel = null;

       while (xe.hasMoreElements()) {
           final XModel xModel = (XModel)UnoRuntime.queryInterface(
XModel.class, xe.nextElement());
           if (xModel != null) {
               final String modelUrl = xModel.getURL();
               if (modelUrl.equals(unoUrl)) {
                   currentModel = xModel;
                   break;
               }
           }
       }

       if (currentModel != null) {
           final XFrame currentFrame = currentModel.getCurrentController
().getFrame();
           XDispatchProvider xdp =
(XDispatchProvider)UnoRuntime.queryInterface(XDispatchProvider.class,
currentFrame);
           // instert your uno-cmd
           xdh.executeDispatch(xdp, ".uno:UpdateAllIndexes", "", 0, new
PropertyValue[0]);
       } else {
           // should not happen
           throw new UpdateIndexesException();
       }
   }


Sometimes ist better to use the dispatch than do it by yourself in java,
cause of some performance and syncronize-issues

Regards

Jan

Reply via email to