250,
msg);
// Use a barrier and LastChanceSaveEvent to allow source documents
// and client state to be synchronized before quitting.
Barrier barrier = new Barrier();
barrier.addBarrierReleasedHandler(new BarrierReleasedHandler()
{
public void onBarrierReleased(BarrierReleasedEvent event)
{
// All last chance save operations have completed (or possibly
// failed). Now do the real quit.
// notify the desktop frame that we are about to quit
if (Desktop.isDesktop())
{
Desktop.getFrame().setPendingQuit(switchToProject_ != null ?
DesktopFrame.PENDING_QUIT_RESTART_AND_RELOAD :
DesktopFrame.PENDING_QUIT_AND_EXIT);
}
server_.quitSession(
saveChanges_,
switchToProject_,
new ServerRequestCallback<Boolean>()
{
@Override
public void onResponseReceived(Boolean response)
{
if (response)
{
// clear progress only if we aren't switching projects
// (otherwise we want to leave progress up until
// the app reloads)
if (switchToProject_ == null)
progress.dismiss();
// fire onQuitAcknowledged
if (onQuitAcknowledged_ != null)
onQuitAcknowledged_.execute();
}
else
{
onFailedToQuit();
}
}
@Override
public void onError(ServerError error)
{
onFailedToQuit();
}
private void onFailedToQuit()
{
progress.dismiss();
if (Desktop.isDesktop())
{
Desktop.getFrame().setPendingQuit(
DesktopFrame.PENDING_QUIT_NONE);
}
}
});
}
});
// We acquire a token to make sure that the barrier doesn't fire before
// all the LastChanceSaveEvent listeners get a chance to acquire their
// own tokens.
Token token = barrier.acquire();
try
{
eventBus_.fireEvent(new LastChanceSaveEvent(barrier));
}
finally