List Info

Thread: CloseVetoException has no effect




CloseVetoException has no effect
user name
2006-07-07 09:56:14
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: dev-unsubscribeapi.openoffice.org
For additional commands, e-mail: dev-helpapi.openoffice.org

CloseVetoException has no effect
user name
2006-07-26 11:20:52
Christoph Lutz wrote:

> 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?

I think there is nothing wrong. You have registered as a
CloseListener
at the document, the "model". I assume that this
has worked and the
model is still there, so it's not surprising that no
"notifyClosing" was
called.

But that doesn't mean that you have prevented the view(s)
on this model
from becoming closed, so the window can be closed as usual.
If you want
to prevent the views from being closed you must register as
a close
listener at the corresponding frames.

Best regards,
Mathias

-- 
Mathias Bauer - OpenOffice.org Application Framework Project
Lead
Please reply to the list only, nospamforMBAgmx.de is
a spam sink.

------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribeapi.openoffice.org
For additional commands, e-mail: dev-helpapi.openoffice.org

CloseVetoException has no effect
user name
2006-07-28 08:52:12
Hi Mathias,

thanks for your explanation which made the things much
clearer for me!

Best regards,
Christoph

------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribeapi.openoffice.org
For additional commands, e-mail: dev-helpapi.openoffice.org

[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )