aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/main/java/com/vaadin/event
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/main/java/com/vaadin/event')
-rw-r--r--server/src/main/java/com/vaadin/event/EventRouter.java16
-rw-r--r--server/src/main/java/com/vaadin/event/MethodEventSource.java9
2 files changed, 19 insertions, 6 deletions
diff --git a/server/src/main/java/com/vaadin/event/EventRouter.java b/server/src/main/java/com/vaadin/event/EventRouter.java
index c5237d9aca..b07efb6c53 100644
--- a/server/src/main/java/com/vaadin/event/EventRouter.java
+++ b/server/src/main/java/com/vaadin/event/EventRouter.java
@@ -28,6 +28,7 @@ import java.util.logging.Logger;
import com.vaadin.server.ErrorEvent;
import com.vaadin.server.ErrorHandler;
+import com.vaadin.shared.Registration;
/**
* <code>EventRouter</code> class implementing the inheritable event listening
@@ -51,12 +52,16 @@ public class EventRouter implements MethodEventSource {
* use the default documentation from implemented interface.
*/
@Override
- public void addListener(Class<?> eventType, Object object, Method method) {
+ public Registration addListener(Class<?> eventType, Object object,
+ Method method) {
Objects.requireNonNull(object, "Listener must not be null.");
if (listenerList == null) {
listenerList = new LinkedHashSet<>();
}
- listenerList.add(new ListenerMethod(eventType, object, method));
+ ListenerMethod listenerMethod = new ListenerMethod(eventType, object,
+ method);
+ listenerList.add(listenerMethod);
+ return () -> listenerList.remove(listenerMethod);
}
/*
@@ -65,13 +70,16 @@ public class EventRouter implements MethodEventSource {
* here, we use the default documentation from implemented interface.
*/
@Override
- public void addListener(Class<?> eventType, Object object,
+ public Registration addListener(Class<?> eventType, Object object,
String methodName) {
Objects.requireNonNull(object, "Listener must not be null.");
if (listenerList == null) {
listenerList = new LinkedHashSet<>();
}
- listenerList.add(new ListenerMethod(eventType, object, methodName));
+ ListenerMethod listenerMethod = new ListenerMethod(eventType, object,
+ methodName);
+ listenerList.add(listenerMethod);
+ return () -> listenerList.remove(listenerMethod);
}
/*
diff --git a/server/src/main/java/com/vaadin/event/MethodEventSource.java b/server/src/main/java/com/vaadin/event/MethodEventSource.java
index 42f4902122..2ba5586eb1 100644
--- a/server/src/main/java/com/vaadin/event/MethodEventSource.java
+++ b/server/src/main/java/com/vaadin/event/MethodEventSource.java
@@ -19,6 +19,8 @@ package com.vaadin.event;
import java.io.Serializable;
import java.lang.reflect.Method;
+import com.vaadin.shared.Registration;
+
/**
* <p>
* Interface for classes supporting registration of methods as event receivers.
@@ -54,13 +56,15 @@ public interface MethodEventSource extends Serializable {
* the object instance who owns the activation method.
* @param method
* the activation method.
+ * @return a registration object for removing the listener
* @throws java.lang.IllegalArgumentException
* unless <code>method</code> has exactly one match in
* <code>object</code>
* @throws NullPointerException
* if {@code object} is {@code null}
*/
- public void addListener(Class<?> eventType, Object object, Method method);
+ public Registration addListener(Class<?> eventType, Object object,
+ Method method);
/**
* <p>
@@ -89,13 +93,14 @@ public interface MethodEventSource extends Serializable {
* the object instance who owns the activation method.
* @param methodName
* the name of the activation method.
+ * @return a registration object for removing the listener
* @throws java.lang.IllegalArgumentException
* unless <code>method</code> has exactly one match in
* <code>object</code>
* @throws NullPointerException
* if {@code object} is {@code null}
*/
- public void addListener(Class<?> eventType, Object object,
+ public Registration addListener(Class<?> eventType, Object object,
String methodName);
/**