use of org.jowidgets.cap.ui.api.model.DataModelChangeType 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;
}
Aggregations