public boolean canClose()
{
boolean userBreak = false;
int answer = JOptionPane.NO_OPTION;
FormModel detailFormModel = getDetailForm().getFormModel();
if (detailFormModel.isEnabled() && detailFormModel.isDirty())
{
if (detailFormModel.isCommittable())
{
answer = RcpSupport.showWarningDialog(getComponent(), UNSAVEDCHANGES_WARNING_ID,
JOptionPane.YES_NO_CANCEL_OPTION);
}
else // form is uncomittable, change it or revert it
{
answer = RcpSupport.showWarningDialog(getComponent(),
UNSAVEDCHANGES_UNCOMMITTABLE_WARNING_ID, JOptionPane.YES_NO_OPTION);
// the following might seem strange, but it aligns the answer with the other part of this if construction
// if we said 'yes keep editing': don't discard changes, continue editing to save it later on == CANCEL in previous if
// if we said 'no discard changes': discard changed and switch to other row == NO in previous if
answer = answer == JOptionPane.YES_OPTION ? JOptionPane.CANCEL_OPTION : JOptionPane.NO_OPTION;
}
switch (answer)
{
case JOptionPane.CANCEL_OPTION:
userBreak = true;
break;
case JOptionPane.YES_OPTION:
getCommitCommand().execute();
break;
case JOptionPane.NO_OPTION:
detailFormModel.revert();
break;
}
}
return !userBreak;