Best way to veto detachment of components?

I want to show a warning when a user tries to navigate away from a form if the form has not yet been committed ("You have unsaved data in the form. Proceed anyway? [Yes]
[No]
"). The warning only has to work inside the application, I don’t care if the user goes to another site external to the application.

What would be the best way to do this in Vaadin? I would prefer something along the lines of the VetoableChangeListener/PropertyVetoException paradigm in JavaBeans but I have not found an event that is generated before a component is about to be detached, only after the detachment is already a fact. Any help would be much appreciated.

Thanks,
Thomas