I found this forum thread which suggests overriding ListSelectionModel to prevent rows from being selected.
I would like to prevent selection changes when there are unsaved changes (external to the table) for the currently selected item UNTIL the user confirms the discard. Something like:
public class confirmSelectionChange extends DefaultListSelectionModel {
public void setSelectionInterval(int index0, int index1) {
if (unsavedChanges()) {
super.setSelectionInterval(int index0, int index1);
}
}
private boolean unsavedChanges() {
if (noUnsavedChangesExist) {
return true;
}
// Present modal dialog: save, discard cancel
if (dialogAnswer == SAVE) {
// save changes
return true;
} else if (dialogAnswer == DISCARD) {
return true;
} else {
return false;
}
}
}
Is it possible to insert blocking code in the middle of ListSelectionModel changes? Is there a better way to intercept selection change events?
I'm already listening for them but the change has already happened by then.