Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

ApplicationListeners & shutting down in Java 1.4



In all our Java 1.4 apps on Mac, we have a minor bug when it comes to shutting down.

We've registered a com.apple.eawt.ApplicationListener to know when the user tries to quit the program from the application menu, or by other OS-specific means. (For example, right-clicking the app's icon in the dock and selecting 'Quit', or by logging out or shutting down.)

We need to prompt the user to save/discard all their changes when they try to close the program. We do this in a separate thread, so the AWT thread is free for progress dialogs and question dialogs. (Technically if we made every dialog a modal dialog this might solve our problem, but we found that's very dangerous; two stacked modal dialogs is bad news in Java. For example: if an error occurs while saving, then juggling the modal dialogs safely is a real pain.)

The bug is this: in our current implementation, we correctly close the application when requested, but if the quit is a result of the user's attempt to log off/shutdown/restart, then we're always told "The application X has cancelled shutdown/restart/etc."

We can fix this by changing our code to the following:

public void handleQuit(ApplicationEvent e) {
	...
	windowClosingThread.start();
	e.setHandled(true);
}

But then once the true flag gets set, the program immediately closes... the users work isn't saved.
So instead we say:


public void handleQuit(final ApplicationEvent e) {
	...
	windowClosingThread.start();
}

And inside the extra thread, we eventually say "e.setHandled(true)" when all the user's work is safe. (This is the current implementation that stops the user from logging out.)

From our primitive dabbling, it looks like we have 2 options:
1.  Stop the user from logging out
2.  Discarding all their changes

Has anyone experienced this before?  If so, how did you approach it?

(This is not a problem in the one app we still use Java 1.3 for... but the listener is completely different in 1.3.)

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.