public static class StandardEditor.BeforeCommitChangesEvent
extends java.util.EventObject
StandardEditor.commitChanges() call.
@Subscribe
protected void onBeforeCommit(BeforeCommitChangesEvent event) {
if (getEditedEntity().getDescription() == null) {
notifications.create().withCaption("Description required").show();
event.preventCommit();
}
}
Show dialog and resume commit after:
@Subscribe
protected void onBeforeCommit(BeforeCommitChangesEvent event) {
if (getEditedEntity().getDescription() == null) {
dialogs.createOptionDialog()
.withCaption("Question")
.withMessage("Do you want to set default description?")
.withActions(
new DialogAction(DialogAction.Type.YES).withHandler(e -> {
getEditedEntity().setDescription("No description");
// retry commit and resume action
event.resume(commitChanges());
}),
new DialogAction(DialogAction.Type.NO).withHandler(e -> {
// trigger standard commit and resume action
event.resume();
})
)
.show();
event.preventCommit();
}
}
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
commitPrevented |
protected OperationResult |
commitResult |
protected java.lang.Runnable |
resumeAction |
| Constructor and Description |
|---|
BeforeCommitChangesEvent(Screen source,
java.lang.Runnable resumeAction) |
| Modifier and Type | Method and Description |
|---|---|
OperationResult |
getCommitResult() |
DataContext |
getDataContext() |
Screen |
getSource() |
boolean |
isCommitPrevented() |
void |
preventCommit()
Prevents commit of the screen.
|
void |
preventCommit(OperationResult commitResult)
Prevents commit of the screen.
|
void |
resume()
Resume standard execution.
|
void |
resume(OperationResult result)
Resume with the passed result ignoring standard execution.
|
protected final java.lang.Runnable resumeAction
protected boolean commitPrevented
protected OperationResult commitResult
public BeforeCommitChangesEvent(Screen source, @Nullable java.lang.Runnable resumeAction)
public Screen getSource()
getSource in class java.util.EventObjectpublic DataContext getDataContext()
public void preventCommit()
public void preventCommit(OperationResult commitResult)
commitResult - result object that will be returned from the StandardEditor.commitChanges()} methodpublic void resume()
public void resume(OperationResult result)
@Nullable public OperationResult getCommitResult()
preventCommit(OperationResult) methodpublic boolean isCommitPrevented()
preventCommit() method