public interface OperationResult
public OperationResult commit() {
if (!valid()) {
return OperationResult.fail(); // result is FAIL
}
// create undetermined result object
UnknownOperationResult result = new UnknownOperationResult();
dialogs.createOptionDialog()
.withCaption("Question")
.withMessage("Are you sure?")
.withActions(
new DialogAction(DialogAction.Type.YES).withHandler(event -> {
commitData(); // here we resume work after modal dialog
result.success(); // send SUCCESS status to callbacks of the result
}),
new DialogAction(DialogAction.Type.NO)
.withHandler(event -> result.fail()) // result is FAIL
)
.show();
return result;
}
Callers can subscribe on success/fail of the operation:
commit()
.then(() -> {
// on success
})
.otherwise(() -> {
// on fail
});
Modifier and Type | Interface and Description |
---|---|
static class |
OperationResult.Status
Status of the operation invocation.
|
Modifier and Type | Method and Description |
---|---|
OperationResult |
compose(java.util.function.Supplier<OperationResult> nextStep)
Creates new operation result that represents composition of two operation results.
|
static OperationResult |
fail() |
OperationResult.Status |
getStatus() |
OperationResult |
otherwise(java.lang.Runnable runnable)
Adds fail callback to the operation result.
|
static OperationResult |
success() |
OperationResult |
then(java.lang.Runnable runnable)
Adds success callback to the operation result.
|
static OperationResult fail()
static OperationResult success()
OperationResult.Status getStatus()
OperationResult compose(java.util.function.Supplier<OperationResult> nextStep)
nextStep
- the next operation result supplierOperationResult then(java.lang.Runnable runnable)
runnable
- callbackOperationResult otherwise(java.lang.Runnable runnable)
runnable
- callback