Class EventRouter
- java.lang.Object
-
- com.vaadin.event.EventRouter
-
- All Implemented Interfaces:
MethodEventSource,Serializable
public class EventRouter extends Object implements MethodEventSource
EventRouterclass implementing the inheritable event listening model. For more information on the event model see thepackage documentation.- Since:
- 3.0
- Author:
- Vaadin Ltd.
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description EventRouter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddListener(Class<?> eventType, Object object, Method method)Registers a new event listener with the specified activation method to listen events generated by this component.voidaddListener(Class<?> eventType, Object object, String methodName)Registers a new listener with the specified activation method to listen events generated by this component.voidfireEvent(EventObject event)Sends an event to all registered listeners.voidfireEvent(EventObject event, ErrorHandler errorHandler)Sends an event to all registered listeners.Collection<?>getListeners(Class<?> eventType)Returns all listeners that match or extend the given event type.booleanhasListeners(Class<?> eventType)Checks if the given Event type is listened by a listener registered to this router.voidremoveAllListeners()Removes all listeners from event router.voidremoveListener(Class<?> eventType, Object target)Removes all registered listeners matching the given parameters.voidremoveListener(Class<?> eventType, Object target, Method method)Removes one registered listener method.voidremoveListener(Class<?> eventType, Object target, String methodName)Removes one registered listener method.
-
-
-
Method Detail
-
addListener
public void addListener(Class<?> eventType, Object object, Method method)
Description copied from interface:MethodEventSourceRegisters a new event listener with the specified activation method to listen events generated by this component. If the activation method does not have any arguments the event object will not be passed to it when it's called.
For more information on the inheritable event mechanism see the
com.vaadin.event package documentation.- Specified by:
addListenerin interfaceMethodEventSource- Parameters:
eventType- the type of the listened event. Events of this type or its subclasses activate the listener.object- the object instance who owns the activation method.method- the activation method.
-
addListener
public void addListener(Class<?> eventType, Object object, String methodName)
Description copied from interface:MethodEventSourceRegisters a new listener with the specified activation method to listen events generated by this component. If the activation method does not have any arguments the event object will not be passed to it when it's called.
This version of
addListenergets the name of the activation method as a parameter. The actual method is reflected fromobject, and unless exactly one match is found,java.lang.IllegalArgumentExceptionis thrown.For more information on the inheritable event mechanism see the
com.vaadin.event package documentation.- Specified by:
addListenerin interfaceMethodEventSource- Parameters:
eventType- the type of the listened event. Events of this type or its subclasses activate the listener.object- the object instance who owns the activation method.methodName- the name of the activation method.
-
removeListener
public void removeListener(Class<?> eventType, Object target)
Description copied from interface:MethodEventSourceRemoves all registered listeners matching the given parameters. Since this method receives the event type and the listener object as parameters, it will unregister allobject's methods that are registered to listen to events of typeeventTypegenerated by this component.For more information on the inheritable event mechanism see the
com.vaadin.event package documentation.- Specified by:
removeListenerin interfaceMethodEventSource- Parameters:
eventType- the exact event type theobjectlistens to.target- the target object that has registered to listen to events of typeeventTypewith one or more methods.
-
removeListener
public void removeListener(Class<?> eventType, Object target, Method method)
Description copied from interface:MethodEventSourceRemoves one registered listener method. The given method owned by the given object will no longer be called when the specified events are generated by this component.For more information on the inheritable event mechanism see the
com.vaadin.event package documentation.- Specified by:
removeListenerin interfaceMethodEventSource- Parameters:
eventType- the exact event type theobjectlistens to.target- the target object that has registered to listen to events of type eventType with one or more methods.method- the method owned by the target that's registered to listen to events of type eventType.
-
removeListener
public void removeListener(Class<?> eventType, Object target, String methodName)
Description copied from interface:MethodEventSourceRemoves one registered listener method. The given method owned by the given object will no longer be called when the specified events are generated by this component.
This version of
removeListenergets the name of the activation method as a parameter. The actual method is reflected from the target, and unless exactly one match is found,java.lang.IllegalArgumentExceptionis thrown.For more information on the inheritable event mechanism see the
com.vaadin.event package documentation.- Specified by:
removeListenerin interfaceMethodEventSource- Parameters:
eventType- the exact event type theobjectlistens to.target- the target object that has registered to listen to events of typeeventTypewith one or more methods.methodName- the name of the method owned bytargetthat's registered to listen to events of typeeventType.
-
removeAllListeners
public void removeAllListeners()
Removes all listeners from event router.
-
fireEvent
public void fireEvent(EventObject event)
Sends an event to all registered listeners. The listeners will decide if the activation method should be called or not.- Parameters:
event- the Event to be sent to all listeners.
-
fireEvent
public void fireEvent(EventObject event, ErrorHandler errorHandler)
Sends an event to all registered listeners. The listeners will decide if the activation method should be called or not.If an error handler is set, the processing of other listeners will continue after the error handler method call unless the error handler itself throws an exception.
- Parameters:
event- the Event to be sent to all listeners.errorHandler- error handler to use to handle any exceptions thrown by listeners or null to let the exception propagate to the caller, preventing further listener calls
-
hasListeners
public boolean hasListeners(Class<?> eventType)
Checks if the given Event type is listened by a listener registered to this router.- Parameters:
eventType- the event type to be checked- Returns:
- true if a listener is registered for the given event type
-
getListeners
public Collection<?> getListeners(Class<?> eventType)
Returns all listeners that match or extend the given event type.- Parameters:
eventType- The type of event to return listeners for.- Returns:
- A collection with all registered listeners. Empty if no listeners are found.
-
-