Swing Applet losing dirty data
Hello,
In reaction to a button being pressed on a toolbar, the user is prompted if he wants to Discard his changes (dirty data). If he selects YES that he wants to Discard his changes the displayed applet is stopped and destroyed. Alternatively, if the user selects NO that he does not want to Discard his changes, I trick the application into saving his changes (dirty data). I force a ToolbarController.SAVE event which ties into a SaveAction Thread to force his changes.
I want to allow enough time for the SaveAction thread to do its job, so I wrapped the code in a SwingUtilities.invokeAndWait thread method call.
At runtime, the dirty data is lost. Is the SwingUtilities.invokeAndWait the proper method to use in this case ?
Here is the code snippet:
Code:
public void shutdown() {
if (configurationManager.isModifedConfigurations()) {
int selection = 999;
// Discard changes ?
selection = JOptionPane.showConfirmDialog(null, messages.getString("ConfigPowerbarChangeConfirmMsg"),
messages.getString("ConfigPowerbarChangeConfirmMsgTitle"),
JOptionPane.YES_NO_OPTION);
if (selection == JOptionPane.NO_OPTION) { //Discard Changes
configurationManager.setModifedConfigurations(false);
super.shutdown();
removeBindings();
stopCurrentApplet();
} else if (selection == JOptionPane.YES_OPTION) { //Force Save changes
System.out.println("Catch ApplicationEvent !!! Force Save of Mutable Table fields.");
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
toolbarController = new ToolbarController(ToolbarModelFactory.getSystemwideToolbarModel());
ApplicationEvent evt = new ApplicationEvent(ToolbarController.SAVE, toolbarController);
toolbarController.handleApplicationEvent(evt);
}
});
} catch (InterruptedException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
}
Paolo
Re: Swing Applet losing dirty data
Quote:
the dirty data is lost
Can you explain what "data is lost" means?