use of org.jowidgets.api.types.QuestionResult in project jo-client-platform by jo-source.
the class DataModelContextImpl method permitChangeAsync.
@Override
public void permitChangeAsync(final IChangeResponse changeRespose, final ICallback<Boolean> callback) {
Assert.paramHasType(changeRespose, ChangeResponseImpl.class, "changeRespose");
final ChangeResponseImpl changeResponseImpl = (ChangeResponseImpl) changeRespose;
final DataModelChangeType changeType = changeResponseImpl.getChangeType();
final Set<IDataModel> relevantModels = getRelevantModels(changeType);
if (hasInvalidChanged(relevantModels)) {
if (shouldDataBeRefused()) {
for (final IDataModel model : relevantModels) {
model.undo();
}
callback.call(Boolean.TRUE);
hasAsyncRequest = false;
return;
} else {
callback.call(Boolean.FALSE);
hasAsyncRequest = false;
return;
}
} else if (hasChanged(relevantModels)) {
final QuestionResult questionResult = shouldDataBeSaved();
if (QuestionResult.YES == questionResult) {
// do the save
doSave(changeResponseImpl, callback);
return;
}
if (QuestionResult.CANCEL == questionResult) {
// to not permit in case of cancel
callback.call(Boolean.FALSE);
hasAsyncRequest = false;
return;
} else {
// do not save, do refuse, in this case permit the change
for (final IDataModel model : relevantModels) {
model.undo();
}
callback.call(Boolean.TRUE);
hasAsyncRequest = false;
return;
}
}
hasAsyncRequest = false;
}
use of org.jowidgets.api.types.QuestionResult in project jo-client-platform by jo-source.
the class DataModelContextImpl method shouldDataBeRefused.
private boolean shouldDataBeRefused() {
final IQuestionDialogBluePrint dialogBp = BPF.questionDialog();
dialogBp.setTitle(UNSAVED_INVALID_DATA_TITLE.get());
dialogBp.setText(UNSAVED_INVALID_DATA_TEXT.get());
dialogBp.setYesButton(BPF.button(UNSAVED_INVALID_DATA_YES_BTN.get()));
dialogBp.setNoButton(BPF.button(UNSAVED_INVALID_DATA_NO_BTN.get()));
final IQuestionDialog dialog = Toolkit.getActiveWindow().createChildWindow(dialogBp);
final QuestionResult questionResult = dialog.question();
if (QuestionResult.YES == questionResult) {
return true;
} else {
return false;
}
}
Aggregations