Search in sources :

Example 1 with QuestionResult

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;
}
Also used : DataModelChangeType(org.jowidgets.cap.ui.api.model.DataModelChangeType) IDataModel(org.jowidgets.cap.ui.api.model.IDataModel) QuestionResult(org.jowidgets.api.types.QuestionResult)

Example 2 with QuestionResult

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;
    }
}
Also used : IQuestionDialogBluePrint(org.jowidgets.api.widgets.blueprint.IQuestionDialogBluePrint) IQuestionDialog(org.jowidgets.api.widgets.IQuestionDialog) QuestionResult(org.jowidgets.api.types.QuestionResult)

Aggregations

QuestionResult (org.jowidgets.api.types.QuestionResult)2 IQuestionDialog (org.jowidgets.api.widgets.IQuestionDialog)1 IQuestionDialogBluePrint (org.jowidgets.api.widgets.blueprint.IQuestionDialogBluePrint)1 DataModelChangeType (org.jowidgets.cap.ui.api.model.DataModelChangeType)1 IDataModel (org.jowidgets.cap.ui.api.model.IDataModel)1