Cancelable events

Version 9.1 by Thomas Mortagne on 2010/08/19 09:23

General goal

Be able to use event to cancel actions.

Use case

- cancel document saving
- cancel script execution
- ...

Proposal

interface CancelableEvent extends Event
{
  boolean isCanceled();

  void cancel();
}

class AbstractCancelableEvent implements CancelableEvent
{
  private boolean canceled = false;

  public boolean isCanceled()
  {
    return this.canceled;
  }

  public void cancel()
  {
    this.cancel = true;
  }
}

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.

Get Connected