Cancelable Events
Last modified by Vincent Massol on 2024/11/19 16:12
Description
General goal
Be able to use event to cancel actions.
Use case
- cancel document saving
- cancel script execution
- for security reasons (e.g. nested scripts)
- because of errors in initialization
- ...
Proposal
interface CancelableEvent extends Event
{
boolean isCanceled();
void cancel();
void cancel(String reason);
String getReason();
}
class AbstractCancelableEvent implements CancelableEvent
{
private boolean canceled = false;
private String reason;
public boolean isCanceled()
{
return this.canceled;
}
public void cancel()
{
this.cancel = true;
}
public void cancel(String reason)
{
this.reason = reason;
}
public String getReason()
{
retrun this.reason;
}
}A cancelable event implements CancelableEvent and any listener of this event can cancel the event by calling #cancel() method. Then the sender of the event uses #isCanceled() to know it has to cancel the action.
Thomas Mortagne