@Retention(value=RUNTIME) @Target(value=METHOD) public @interface VetoSubscriber
This annotation simplifies much of the repetitive boilerplate used for adding veto listeners (which in EventBus 2.0 will be called VetoSubscribers, thus this annotation name difference) to EventService Events. Example:
public class MyAppController { public MyAppController { AnnotationProcessor.process(this);//this line can be avoided with a compile-time tool or an Aspect } @EventSubscriber(eventClass=AppAppClosingEvent.class) public void onAppClosingEvent(AppClosingEvent appClosingEvent) { //close connections, close windows } } public class MyDocumentController { @VetoSubscriber(eventClass=AppAppClosingEvent.class) public boolean ensureDocumentIsSaved(AppAppClosingEvent appClosingEvent) { if (docHasUnsavedChanges()) { boolean answer = MyModalDialog.show("Are you sure you want to close and lose your changes?"); if (answer == StandardButtonValues.Cancel) { //stop processing this event return true; } } //It's OK to close return false; } }
Modifier and Type | Optional Element and Description |
---|---|
Class<? extends EventService> |
autoCreateEventServiceClass
Whether or not to autocreate the event service if it doesn't exist on subscription, default is true.
|
Class |
eventClass
The class to subscribe to, if not specified, a subscription is created for the type of the method parameter.
|
String |
eventServiceName
The event service to subscribe to, default to the EventServiceLocator.SERVICE_NAME_EVENT_BUS.
|
boolean |
exact
Whether or not to subscribe to the exact class or a class hierarchy, defaults to class hierarchy (false).
|
int |
priority
Determines the order in which this veto subscriber is called, default is FIFO.
|
ReferenceStrength |
referenceStrength
Whether to subscribe weakly or strongly.
|
public abstract Class eventClass
public abstract int priority
public abstract boolean exact
public abstract ReferenceStrength referenceStrength
public abstract String eventServiceName
public abstract Class<? extends EventService> autoCreateEventServiceClass
Copyright © 2013 Bushe Enterprises, Inc.. All Rights Reserved.