Use XCloseListener to be notified when the document gets closed. To stop the document from closing, throw a CloseVetoException
from the queryClosing
method.
There is some related Basic code at [Solved] Intercept onClose event of database doc? (in Basic) (View topic) • Apache OpenOffice Community Forum.
EDIT:
Sorry, but what you want is impossible. The code you posted is correct. Throwing CloseVetoException
will prevent the outer frame from closing if you call addCloseListener
on the frame.
frame = xComponent.getCurrentController().getFrame()
frame.addCloseListener(myListener)
But the inner frame containing the document can still be closed, as explained at http://openoffice.2283327.n4.nabble.com/api-dev-prevent-document-closing-td2767642.html. Listening to the inner frame (xComponent
) will still result in the method being called, but in that case, CloseVetoException
has no effect.
It sounds like a different approach is needed instead, such as a button that says “Validate document”.
A similar question was asked at [Solved] Cancel event, [Impossible] Cancel close document (View topic) • Apache OpenOffice Community Forum.