Hi,
I would like to veto the close-action (clicking on the x in a writer
document) in such a form, that the document doesn't get closed until
my program decides when it's time to close the document. This should
be possible by throwing a CloseVetoException in the queryClosing(...)
handler when getsOwnership==true, but it does not to work with my
example code (below). The CloseVetoException I throw does not seem to
prevent OOo from actually closing the document.
Any Ideas what could be wrong with my example?
How to reproduce:
1) Create a new writer-document
2) running my example code returns a System.out-message:
waiting for close - events
3) pressing the x-Button in the writer-document to try(!) to close
it returns a System.out-message:
queryClosing(). getsOwnership=true
4) the document gets closed by OOo, though I throw a
CloseVetoException in the case of getsOwnership==true!!!
5) Why dont I get informed via notifyClosing about the actual closing?
here the example-code:
import com.sun.star.comp.helper.Bootstrap;
import com.sun.star.comp.helper.BootstrapException;
import com.sun.star.frame.XDesktop;
import com.sun.star.lang.EventObject;
import com.sun.star.lang.XComponent;
import com.sun.star.uno.Exception;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
import com.sun.star.util.CloseVetoException;
import com.sun.star.util.XCloseListener;
import com.sun.star.util.XCloseable;
public class CloseListenerTest implements XCloseListener {
public static void main(String[] args) throws BootstrapException,
Exception, InterruptedException {
XComponentContext ctx = Bootstrap.bootstrap();
Object desktop = ctx.getServiceManager().createInstanceWithContext(
com.sun.star.frame.Desktop, ctx);
XDesktop xDesktop = (XDesktop) UnoRuntime.queryInterface(
XDesktop.class, desktop);
XComponent compo = xDesktop.getCurrentComponent();
XCloseable xCloseable = (XCloseable) UnoRuntime.queryInterface(
XCloseable.class, compo);
CloseListenerTest ct = new CloseListenerTest();
xCloseable.addCloseListener(ct);
System.out.println(waiting for close - events);
}
public void queryClosing(EventObject event, boolean getsOwnership)
throws CloseVetoException {
System.out.println(queryClosing(). getsOwnership= + getsOwnership);
if (getsOwnership) {
throw new CloseVetoException();
}
}
public void notifyClosing(EventObject event) {
System.out.println(notifyClosing);
XCloseable xCloseable = (XCloseable) UnoRuntime.queryInterface(
XCloseable.class, event.Source);
if (xCloseable != null)
xCloseable.removeCloseListener(this);
}
public void disposing(EventObject arg0) {
System.out.println(disposing);
}
}
best regards,
Christoph
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]