| View previous topic :: View next topic |
| Author |
Message |
anestikas General User

Joined: 10 May 2008 Posts: 43
|
Posted: Mon May 26, 2008 3:55 am Post subject: Calling dispatcher synchronously in Java |
|
|
I think this code might help a couple of you...
| Code: | private Semaphore lock = new Semaphore(1, true);
private void dispatch(String command, XTextDocument doc) {
try {
lock.acquire();
XMultiServiceFactory xFactory = (XMultiServiceFactory) UnoRuntime.queryInterface(
XMultiServiceFactory.class, xMCF);
XDispatchProvider xDispatchProvider = (XDispatchProvider)UnoRuntime.queryInterface(XDispatchProvider.class, doc.getCurrentController().getFrame());
Object object = xFactory.createInstance("com.sun.star.util.URLTransformer");
XURLTransformer xURLTransformer = (XURLTransformer) UnoRuntime.queryInterface(XURLTransformer.class, object);
URL[] url = new URL[1];
url[0] = new URL();
url[0].Complete = ".uno:" + command;
xURLTransformer.parseStrict(url);
XDispatch xDispatcher = xDispatchProvider.queryDispatch(url[0], "", 0);
XNotifyingDispatch xNotifyingDispatcher = (XNotifyingDispatch)UnoRuntime.queryInterface(XNotifyingDispatch.class, xDispatcher);
if(xNotifyingDispatcher != null) {
xNotifyingDispatcher.dispatchWithNotification(url[0], new PropertyValue[0], this);
lock.acquire();
}
lock.release();
} catch (java.lang.Exception e) {
e.printStackTrace();
}
}
public void dispatchFinished(DispatchResultEvent e) {
lock.release();
}
public void disposing(EventObject e) {
} |
Note that this implements XDispatchResultListener
This solution does not work for every call eg .uno:ApplyStyleDefault and .uno:SetDefault since the XNotifyingDispatch is not available
If you can improve this code, please do... |
|
| Back to top |
|
 |
ms777 Super User


Joined: 07 Feb 2004 Posts: 1355
|
Posted: Wed May 28, 2008 12:59 pm Post subject: |
|
|
| very interesting ... do you have a list or some examples of dispatches, which support XNotifyingDispatch ? |
|
| Back to top |
|
 |
anestikas General User

Joined: 10 May 2008 Posts: 43
|
Posted: Wed May 28, 2008 2:37 pm Post subject: |
|
|
I have only used it successfully with:
.uno:Copy
.uno:Paste
.uno:ResetAttributes
I don't know which other commands support XNotifyingDispatch. If anyone has such a list, please post it here. |
|
| Back to top |
|
 |
|