public class ComponentEventBus extends Object implements Serializable
Component
s.
Handles adding and removing event listeners, and firing events of type
ComponentEvent
.
Events can either be fired manually through
fireEvent(ComponentEvent)
or automatically based on a DOM event
(see @DomEvent
). Automatically fired events must have a suitable
constructor, as defined in DomEvent
.
Constructor and Description |
---|
ComponentEventBus(Component component)
Creates an event bus for the given component.
|
Modifier and Type | Method and Description |
---|---|
<T extends ComponentEvent<?>> |
addListener(Class<T> eventType,
ComponentEventListener<T> listener)
Adds a listener for the given event type.
|
<T extends ComponentEvent<?>> |
addListener(Class<T> eventType,
ComponentEventListener<T> listener,
Consumer<DomListenerRegistration> domListenerConsumer)
Adds a listener for the given event type, and customizes the
corresponding DOM event listener with the given consumer.
|
void |
fireEvent(ComponentEvent event)
Dispatches the event to all listeners registered for the event type.
|
boolean |
hasListener(Class<? extends ComponentEvent> eventType)
Checks if there is at least one listener registered for the given event
type.
|
public ComponentEventBus(Component component)
component
- the component which will be used as a source for all fired
eventspublic <T extends ComponentEvent<?>> Registration addListener(Class<T> eventType, ComponentEventListener<T> listener)
T
- the event typeeventType
- the event type for which to call the listenerlistener
- the listener to call when the event occurspublic <T extends ComponentEvent<?>> Registration addListener(Class<T> eventType, ComponentEventListener<T> listener, Consumer<DomListenerRegistration> domListenerConsumer)
DomEvent
annotation.
Note that customizing the DOM event listener works only for event types
which are annotated with DomEvent
. Use
addListener(Class, ComponentEventListener)
for other listeners,
or if you don't need to customize the DOM listener.
T
- the event typeeventType
- the event type for which to call the listener, must be
annotated with DomEvent
listener
- the listener to call when the event occursdomListenerConsumer
- a consumer to customize the behavior of the DOM event
listener, not null
IllegalArgumentException
- if the event type is not annotated with DomEvent
public boolean hasListener(Class<? extends ComponentEvent> eventType)
eventType
- the component event typetrue
if at least one listener is registered,
false
otherwisepublic void fireEvent(ComponentEvent event)
event
- the event to fireCopyright © 2020. All rights reserved.