aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/main')
-rw-r--r--server/src/main/java/com/vaadin/event/Action.java9
-rw-r--r--server/src/main/java/com/vaadin/event/ContextClickEvent.java15
-rw-r--r--server/src/main/java/com/vaadin/event/EventRouter.java3
-rw-r--r--server/src/main/java/com/vaadin/event/FieldEvents.java36
-rw-r--r--server/src/main/java/com/vaadin/event/LayoutEvents.java27
-rw-r--r--server/src/main/java/com/vaadin/event/MethodEventSource.java4
-rw-r--r--server/src/main/java/com/vaadin/event/UIEvents.java12
-rw-r--r--server/src/main/java/com/vaadin/navigator/Navigator.java6
-rw-r--r--server/src/main/java/com/vaadin/server/AbstractClientConnector.java10
-rw-r--r--server/src/main/java/com/vaadin/server/ClientConnector.java7
-rw-r--r--server/src/main/java/com/vaadin/server/DragAndDropService.java13
-rw-r--r--server/src/main/java/com/vaadin/server/Page.java66
-rw-r--r--server/src/main/java/com/vaadin/server/data/AbstractDataSource.java1
-rw-r--r--server/src/main/java/com/vaadin/ui/AbsoluteLayout.java25
-rw-r--r--server/src/main/java/com/vaadin/ui/AbstractColorPicker.java6
-rw-r--r--server/src/main/java/com/vaadin/ui/AbstractComponent.java28
-rw-r--r--server/src/main/java/com/vaadin/ui/AbstractComponentContainer.java53
-rw-r--r--server/src/main/java/com/vaadin/ui/AbstractDateField.java45
-rw-r--r--server/src/main/java/com/vaadin/ui/AbstractField.java1
-rw-r--r--server/src/main/java/com/vaadin/ui/AbstractFocusable.java14
-rw-r--r--server/src/main/java/com/vaadin/ui/AbstractMultiSelect.java3
-rw-r--r--server/src/main/java/com/vaadin/ui/AbstractOrderedLayout.java24
-rw-r--r--server/src/main/java/com/vaadin/ui/AbstractSingleComponentContainer.java14
-rw-r--r--server/src/main/java/com/vaadin/ui/AbstractSingleSelect.java1
-rw-r--r--server/src/main/java/com/vaadin/ui/AbstractSplitPanel.java27
-rw-r--r--server/src/main/java/com/vaadin/ui/Button.java33
-rw-r--r--server/src/main/java/com/vaadin/ui/CheckBox.java19
-rw-r--r--server/src/main/java/com/vaadin/ui/ColorPickerArea.java1
-rw-r--r--server/src/main/java/com/vaadin/ui/ComboBox.java11
-rw-r--r--server/src/main/java/com/vaadin/ui/Component.java11
-rw-r--r--server/src/main/java/com/vaadin/ui/ComponentContainer.java29
-rw-r--r--server/src/main/java/com/vaadin/ui/CssLayout.java26
-rw-r--r--server/src/main/java/com/vaadin/ui/Embedded.java31
-rw-r--r--server/src/main/java/com/vaadin/ui/Grid.java3
-rw-r--r--server/src/main/java/com/vaadin/ui/GridLayout.java26
-rw-r--r--server/src/main/java/com/vaadin/ui/HasComponents.java17
-rw-r--r--server/src/main/java/com/vaadin/ui/Image.java33
-rw-r--r--server/src/main/java/com/vaadin/ui/LegacyWindow.java4
-rw-r--r--server/src/main/java/com/vaadin/ui/Panel.java32
-rw-r--r--server/src/main/java/com/vaadin/ui/PopupView.java35
-rw-r--r--server/src/main/java/com/vaadin/ui/TabSheet.java48
-rw-r--r--server/src/main/java/com/vaadin/ui/UI.java37
-rw-r--r--server/src/main/java/com/vaadin/ui/Upload.java142
-rw-r--r--server/src/main/java/com/vaadin/ui/Window.java71
-rw-r--r--server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerGradient.java7
-rw-r--r--server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerGrid.java17
-rw-r--r--server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerHistory.java17
-rw-r--r--server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPopup.java7
-rw-r--r--server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPreview.java4
-rw-r--r--server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerSelect.java6
-rw-r--r--server/src/main/java/com/vaadin/ui/components/colorpicker/HasColorChangeListener.java14
-rw-r--r--server/src/main/java/com/vaadin/ui/renderers/ClickableRenderer.java10
52 files changed, 484 insertions, 657 deletions
diff --git a/server/src/main/java/com/vaadin/event/Action.java b/server/src/main/java/com/vaadin/event/Action.java
index 392f23dffe..49b8033417 100644
--- a/server/src/main/java/com/vaadin/event/Action.java
+++ b/server/src/main/java/com/vaadin/event/Action.java
@@ -19,6 +19,7 @@ package com.vaadin.event;
import java.io.Serializable;
import com.vaadin.server.Resource;
+import com.vaadin.shared.Registration;
/**
* Implements the action framework. This class contains subinterfaces for action
@@ -106,8 +107,14 @@ public class Action implements Serializable {
}
public interface ShortcutNotifier extends Serializable {
- public void addShortcutListener(ShortcutListener shortcut);
+ public Registration addShortcutListener(ShortcutListener shortcut);
+ /**
+ * @deprecated As of 8.0, replaced by {@link Registration#remove()} in
+ * the registration object returned from
+ * {@link #addShortcutListener(ShortcutListener)}.
+ */
+ @Deprecated
public void removeShortcutListener(ShortcutListener shortcut);
}
diff --git a/server/src/main/java/com/vaadin/event/ContextClickEvent.java b/server/src/main/java/com/vaadin/event/ContextClickEvent.java
index d1b089af08..ecf53e2ba2 100644
--- a/server/src/main/java/com/vaadin/event/ContextClickEvent.java
+++ b/server/src/main/java/com/vaadin/event/ContextClickEvent.java
@@ -18,8 +18,10 @@ package com.vaadin.event;
import java.io.Serializable;
import java.lang.reflect.Method;
+import com.vaadin.event.FieldEvents.FocusListener;
import com.vaadin.event.MouseEvents.ClickEvent;
import com.vaadin.shared.MouseEventDetails;
+import com.vaadin.shared.Registration;
import com.vaadin.ui.Component;
import com.vaadin.util.ReflectTools;
@@ -64,10 +66,14 @@ public class ContextClickEvent extends ClickEvent {
* Adds a context click listener that gets notified when a context click
* happens.
*
+ * @see Registration
+ *
* @param listener
- * the context click listener to add
+ * the context click listener to add, not null
+ * @return a registration object for removing the listener
*/
- public void addContextClickListener(ContextClickListener listener);
+ public Registration addContextClickListener(
+ ContextClickListener listener);
/**
* Removes a context click listener that was previously added with
@@ -75,7 +81,12 @@ public class ContextClickEvent extends ClickEvent {
*
* @param listener
* the context click listener to remove
+ *
+ * @deprecated As of 8.0, replaced by {@link Registration#remove()} in
+ * the registration object returned from
+ * {@link #addContextClickListener(FocusListener)}.
*/
+ @Deprecated
public void removeContextClickListener(ContextClickListener listener);
}
diff --git a/server/src/main/java/com/vaadin/event/EventRouter.java b/server/src/main/java/com/vaadin/event/EventRouter.java
index 9ef6c8123b..c5237d9aca 100644
--- a/server/src/main/java/com/vaadin/event/EventRouter.java
+++ b/server/src/main/java/com/vaadin/event/EventRouter.java
@@ -23,6 +23,7 @@ import java.util.EventObject;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
+import java.util.Objects;
import java.util.logging.Logger;
import com.vaadin.server.ErrorEvent;
@@ -51,6 +52,7 @@ public class EventRouter implements MethodEventSource {
*/
@Override
public void addListener(Class<?> eventType, Object object, Method method) {
+ Objects.requireNonNull(object, "Listener must not be null.");
if (listenerList == null) {
listenerList = new LinkedHashSet<>();
}
@@ -65,6 +67,7 @@ public class EventRouter implements MethodEventSource {
@Override
public void addListener(Class<?> eventType, Object object,
String methodName) {
+ Objects.requireNonNull(object, "Listener must not be null.");
if (listenerList == null) {
listenerList = new LinkedHashSet<>();
}
diff --git a/server/src/main/java/com/vaadin/event/FieldEvents.java b/server/src/main/java/com/vaadin/event/FieldEvents.java
index ba84e96b3f..3a4cfc209e 100644
--- a/server/src/main/java/com/vaadin/event/FieldEvents.java
+++ b/server/src/main/java/com/vaadin/event/FieldEvents.java
@@ -20,6 +20,7 @@ import java.io.Serializable;
import java.lang.reflect.Method;
import com.vaadin.shared.EventId;
+import com.vaadin.shared.Registration;
import com.vaadin.shared.communication.FieldRpc.FocusAndBlurServerRpc;
import com.vaadin.ui.Component;
import com.vaadin.ui.Component.Event;
@@ -45,20 +46,27 @@ public interface FieldEvents {
* when a <code>Field</code> receives keyboard focus.
*
* @param listener
+ * the focus listener to add, not null
+ * @return a registration object for removing the listener
* @see FocusListener
- * @since 6.2
+ * @see Registration
+ * @since 8.0
*/
- public void addFocusListener(FocusListener listener);
+ public Registration addFocusListener(FocusListener listener);
/**
- * Removes a <code>FocusListener</code> from the Component.
+ * Removes a <code>BlurListener</code> from the Component.
*
* @param listener
* @see FocusListener
* @since 6.2
+ *
+ * @deprecated As of 8.0, replaced by {@link Registration#remove()} in
+ * the registration object returned from
+ * {@link #addFocusListener(FocusListener)}.
*/
+ @Deprecated
public void removeFocusListener(FocusListener listener);
-
}
/**
@@ -75,21 +83,31 @@ public interface FieldEvents {
* Adds a <code>BlurListener</code> to the Component which gets fired
* when a <code>Field</code> loses keyboard focus.
*
- * @param listener
* @see BlurListener
- * @since 6.2
+ * @see Registration
+ * @since 8.0
+ *
+ * @param listener
+ * the blur listener to add, not null
+ * @return a registration object for removing the listener
*/
- public void addBlurListener(BlurListener listener);
+ public Registration addBlurListener(BlurListener listener);
/**
* Removes a <code>BlurListener</code> from the Component.
*
- * @param listener
* @see BlurListener
* @since 6.2
+ *
+ * @param listener
+ * the listener to remove
+ *
+ * @deprecated As of 8.0, replaced by {@link Registration#remove()} in
+ * the registration object returned from
+ * {@link #addFocusListener(FocusListener)}.
*/
+ @Deprecated
public void removeBlurListener(BlurListener listener);
-
}
/**
diff --git a/server/src/main/java/com/vaadin/event/LayoutEvents.java b/server/src/main/java/com/vaadin/event/LayoutEvents.java
index 9d6dd20fff..627a9610ed 100644
--- a/server/src/main/java/com/vaadin/event/LayoutEvents.java
+++ b/server/src/main/java/com/vaadin/event/LayoutEvents.java
@@ -21,6 +21,7 @@ import java.lang.reflect.Method;
import com.vaadin.event.MouseEvents.ClickEvent;
import com.vaadin.shared.Connector;
import com.vaadin.shared.MouseEventDetails;
+import com.vaadin.shared.Registration;
import com.vaadin.ui.Component;
import com.vaadin.ui.ComponentContainer;
import com.vaadin.util.ReflectTools;
@@ -72,35 +73,27 @@ public interface LayoutEvents {
* The child component that was clicked is included in the
* {@link LayoutClickEvent}.
*
- * Use {@link #removeListener(LayoutClickListener)} to remove the
- * listener.
+ * @see Registration
*
* @param listener
* The listener to add
+ * @return a registration object for removing the listener
*/
- public void addLayoutClickListener(LayoutClickListener listener);
-
- /**
- * @deprecated As of 7.0, replaced by
- * {@link #addLayoutClickListener(LayoutClickListener)}
- **/
- @Deprecated
- public void addListener(LayoutClickListener listener);
+ public Registration addLayoutClickListener(
+ LayoutClickListener listener);
/**
* Removes an LayoutClickListener.
*
* @param listener
* LayoutClickListener to be removed
+ *
+ * @deprecated As of 8.0, replaced by {@link Registration#remove()} in
+ * the registration object returned from
+ * {@link #addLayoutClickListener(LayoutClickListener)}.
*/
- public void removeLayoutClickListener(LayoutClickListener listener);
-
- /**
- * @deprecated As of 7.0, replaced by
- * {@link #removeLayoutClickListener(LayoutClickListener)}
- **/
@Deprecated
- public void removeListener(LayoutClickListener listener);
+ public void removeLayoutClickListener(LayoutClickListener listener);
}
/**
diff --git a/server/src/main/java/com/vaadin/event/MethodEventSource.java b/server/src/main/java/com/vaadin/event/MethodEventSource.java
index f10f136671..42f4902122 100644
--- a/server/src/main/java/com/vaadin/event/MethodEventSource.java
+++ b/server/src/main/java/com/vaadin/event/MethodEventSource.java
@@ -57,6 +57,8 @@ public interface MethodEventSource extends Serializable {
* @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);
@@ -90,6 +92,8 @@ public interface MethodEventSource extends Serializable {
* @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,
String methodName);
diff --git a/server/src/main/java/com/vaadin/event/UIEvents.java b/server/src/main/java/com/vaadin/event/UIEvents.java
index a822c35926..1f696e9d6c 100644
--- a/server/src/main/java/com/vaadin/event/UIEvents.java
+++ b/server/src/main/java/com/vaadin/event/UIEvents.java
@@ -18,6 +18,7 @@ package com.vaadin.event;
import java.io.Serializable;
import java.lang.reflect.Method;
+import com.vaadin.shared.Registration;
import com.vaadin.ui.Component;
import com.vaadin.ui.UI;
import com.vaadin.util.ReflectTools;
@@ -98,10 +99,12 @@ public interface UIEvents {
*
* @see UI#setPollInterval(int)
* @see #removePollListener(PollListener)
+ * @see Registration
* @param listener
- * the {@link PollListener} to add
+ * the {@link PollListener} to add, not null
+ * @return a registration object for removing the listener
*/
- public void addPollListener(PollListener listener);
+ public Registration addPollListener(PollListener listener);
/**
* Remove a poll listener.
@@ -109,7 +112,12 @@ public interface UIEvents {
* @see #addPollListener(PollListener)
* @param listener
* the listener to be removed
+ *
+ * @deprecated As of 8.0, replaced by {@link Registration#remove()} in
+ * the registration object returned from
+ * {@link #addPollListener(PollListener)}.
*/
+ @Deprecated
public void removePollListener(PollListener listener);
}
diff --git a/server/src/main/java/com/vaadin/navigator/Navigator.java b/server/src/main/java/com/vaadin/navigator/Navigator.java
index 13e3b4c2e7..4fb3906e9e 100644
--- a/server/src/main/java/com/vaadin/navigator/Navigator.java
+++ b/server/src/main/java/com/vaadin/navigator/Navigator.java
@@ -722,8 +722,7 @@ public class Navigator implements Serializable {
// a copy of the listener list is needed to avoid
// ConcurrentModificationException as a listener can add/remove
// listeners
- for (ViewChangeListener l : new ArrayList<>(
- listeners)) {
+ for (ViewChangeListener l : new ArrayList<>(listeners)) {
if (!l.beforeViewChange(event)) {
return false;
}
@@ -786,8 +785,7 @@ public class Navigator implements Serializable {
// a copy of the listener list is needed to avoid
// ConcurrentModificationException as a listener can add/remove
// listeners
- for (ViewChangeListener l : new ArrayList<>(
- listeners)) {
+ for (ViewChangeListener l : new ArrayList<>(listeners)) {
l.afterViewChange(event);
}
}
diff --git a/server/src/main/java/com/vaadin/server/AbstractClientConnector.java b/server/src/main/java/com/vaadin/server/AbstractClientConnector.java
index ea969bea2b..3299568778 100644
--- a/server/src/main/java/com/vaadin/server/AbstractClientConnector.java
+++ b/server/src/main/java/com/vaadin/server/AbstractClientConnector.java
@@ -30,11 +30,13 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
+import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;
import com.vaadin.event.EventRouter;
import com.vaadin.event.MethodEventSource;
+import com.vaadin.shared.Registration;
import com.vaadin.shared.communication.ClientRpc;
import com.vaadin.shared.communication.ServerRpc;
import com.vaadin.shared.communication.SharedState;
@@ -95,9 +97,11 @@ public abstract class AbstractClientConnector
private static final ConcurrentHashMap<Class<? extends AbstractClientConnector>, Class<? extends SharedState>> stateTypeCache = new ConcurrentHashMap<>();
@Override
- public void addAttachListener(AttachListener listener) {
+ public Registration addAttachListener(AttachListener listener) {
addListener(AttachEvent.ATTACH_EVENT_IDENTIFIER, AttachEvent.class,
listener, AttachListener.attachMethod);
+ return () -> removeListener(AttachEvent.ATTACH_EVENT_IDENTIFIER,
+ AttachEvent.class, listener);
}
@Override
@@ -107,9 +111,11 @@ public abstract class AbstractClientConnector
}
@Override
- public void addDetachListener(DetachListener listener) {
+ public Registration addDetachListener(DetachListener listener) {
addListener(DetachEvent.DETACH_EVENT_IDENTIFIER, DetachEvent.class,
listener, DetachListener.detachMethod);
+ return () -> removeListener(DetachEvent.DETACH_EVENT_IDENTIFIER,
+ DetachEvent.class, listener);
}
@Override
diff --git a/server/src/main/java/com/vaadin/server/ClientConnector.java b/server/src/main/java/com/vaadin/server/ClientConnector.java
index 87c6b8309e..80453d4733 100644
--- a/server/src/main/java/com/vaadin/server/ClientConnector.java
+++ b/server/src/main/java/com/vaadin/server/ClientConnector.java
@@ -23,6 +23,7 @@ import java.util.List;
import com.vaadin.event.ConnectorEvent;
import com.vaadin.event.ConnectorEventListener;
import com.vaadin.shared.Connector;
+import com.vaadin.shared.Registration;
import com.vaadin.shared.communication.SharedState;
import com.vaadin.ui.UI;
import com.vaadin.util.ReflectTools;
@@ -95,12 +96,14 @@ public interface ClientConnector extends Connector {
public void detach(DetachEvent event);
}
- public void addAttachListener(AttachListener listener);
+ public Registration addAttachListener(AttachListener listener);
+ @Deprecated
public void removeAttachListener(AttachListener listener);
- public void addDetachListener(DetachListener listener);
+ public Registration addDetachListener(DetachListener listener);
+ @Deprecated
public void removeDetachListener(DetachListener listener);
/**
diff --git a/server/src/main/java/com/vaadin/server/DragAndDropService.java b/server/src/main/java/com/vaadin/server/DragAndDropService.java
index 23bea5138b..d23c87e468 100644
--- a/server/src/main/java/com/vaadin/server/DragAndDropService.java
+++ b/server/src/main/java/com/vaadin/server/DragAndDropService.java
@@ -34,6 +34,7 @@ import com.vaadin.event.dd.TargetDetails;
import com.vaadin.event.dd.TargetDetailsImpl;
import com.vaadin.event.dd.acceptcriteria.AcceptCriterion;
import com.vaadin.shared.ApplicationConstants;
+import com.vaadin.shared.Registration;
import com.vaadin.shared.communication.SharedState;
import com.vaadin.shared.ui.dd.DragEventType;
import com.vaadin.ui.Component;
@@ -360,18 +361,26 @@ public class DragAndDropService implements VariableOwner, ClientConnector {
}
@Override
- public void addAttachListener(AttachListener listener) {
+ public Registration addAttachListener(AttachListener listener) {
+ return () -> {
+ /* NO-OP */
+ };
}
@Override
+ @Deprecated
public void removeAttachListener(AttachListener listener) {
}
@Override
- public void addDetachListener(DetachListener listener) {
+ public Registration addDetachListener(DetachListener listener) {
+ return () -> {
+ /* NO-OP */
+ };
}
@Override
+ @Deprecated
public void removeDetachListener(DetachListener listener) {
}
diff --git a/server/src/main/java/com/vaadin/server/Page.java b/server/src/main/java/com/vaadin/server/Page.java
index 9330c08a28..35fc6b96e8 100644
--- a/server/src/main/java/com/vaadin/server/Page.java
+++ b/server/src/main/java/com/vaadin/server/Page.java
@@ -27,6 +27,8 @@ import java.util.LinkedList;
import java.util.List;
import com.vaadin.event.EventRouter;
+import com.vaadin.event.FieldEvents.FocusListener;
+import com.vaadin.shared.Registration;
import com.vaadin.shared.ui.BorderStyle;
import com.vaadin.shared.ui.ui.PageClientRpc;
import com.vaadin.shared.ui.ui.PageState;
@@ -506,24 +508,18 @@ public class Page implements Serializable {
*
* @see #getUriFragment()
* @see #setUriFragment(String)
- * @see #removeUriFragmentChangedListener(UriFragmentChangedListener)
+ * @see Registration
*
* @param listener
* the URI fragment listener to add
+ * @return a registration object for removing the listener
*/
- public void addUriFragmentChangedListener(
+ public Registration addUriFragmentChangedListener(
Page.UriFragmentChangedListener listener) {
addListener(UriFragmentChangedEvent.class, listener,
URI_FRAGMENT_CHANGED_METHOD);
- }
-
- /**
- * @deprecated As of 7.0, replaced by
- * {@link #addUriFragmentChangedListener(UriFragmentChangedListener)}
- **/
- @Deprecated
- public void addListener(Page.UriFragmentChangedListener listener) {
- addUriFragmentChangedListener(listener);
+ return () -> removeListener(UriFragmentChangedEvent.class, listener,
+ URI_FRAGMENT_CHANGED_METHOD);
}
/**
@@ -533,7 +529,12 @@ public class Page implements Serializable {
* the URI fragment listener to remove
*
* @see Page#addUriFragmentChangedListener(UriFragmentChangedListener)
+ *
+ * @deprecated As of 8.0, replaced by {@link Registration#remove()} in the
+ * registration object returned from
+ * {@link #addUriFragmentChangedListener(FocusListener)}.
*/
+ @Deprecated
public void removeUriFragmentChangedListener(
Page.UriFragmentChangedListener listener) {
removeListener(UriFragmentChangedEvent.class, listener,
@@ -541,15 +542,6 @@ public class Page implements Serializable {
}
/**
- * @deprecated As of 7.0, replaced by
- * {@link #removeUriFragmentChangedListener(UriFragmentChangedListener)}
- **/
- @Deprecated
- public void removeListener(Page.UriFragmentChangedListener listener) {
- removeUriFragmentChangedListener(listener);
- }
-
- /**
* Sets the fragment part in the current location URI. Optionally fires a
* {@link UriFragmentChangedEvent}.
* <p>
@@ -745,24 +737,23 @@ public class Page implements Serializable {
*
* @param resizeListener
* the listener to add
+ * @return a registration object for removing the listener
*
* @see BrowserWindowResizeListener#browserWindowResized(BrowserWindowResizeEvent)
* @see UI#setResizeLazy(boolean)
+ * @see Registration
*/
- public void addBrowserWindowResizeListener(
+ public Registration addBrowserWindowResizeListener(
BrowserWindowResizeListener resizeListener) {
addListener(BrowserWindowResizeEvent.class, resizeListener,
BROWSER_RESIZE_METHOD);
getState(true).hasResizeListeners = true;
- }
-
- /**
- * @deprecated As of 7.0, replaced by
- * {@link #addBrowserWindowResizeListener(BrowserWindowResizeListener)}
- **/
- @Deprecated
- public void addListener(BrowserWindowResizeListener resizeListener) {
- addBrowserWindowResizeListener(resizeListener);
+ return () -> {
+ removeListener(BrowserWindowResizeEvent.class, resizeListener,
+ BROWSER_RESIZE_METHOD);
+ getState(true).hasResizeListeners = hasEventRouter()
+ && eventRouter.hasListeners(BrowserWindowResizeEvent.class);
+ };
}
/**
@@ -771,7 +762,13 @@ public class Page implements Serializable {
*
* @param resizeListener
* the listener to remove
+ *
+ * @deprecated As of 8.0, replaced by {@link Registration#remove()} in the
+ * registration object returned from
+ * {@link #addBrowserWindowResizeListener(BrowserWindowResizeListener)}
+ * .
*/
+ @Deprecated
public void removeBrowserWindowResizeListener(
BrowserWindowResizeListener resizeListener) {
removeListener(BrowserWindowResizeEvent.class, resizeListener,
@@ -781,15 +778,6 @@ public class Page implements Serializable {
}
/**
- * @deprecated As of 7.0, replaced by
- * {@link #removeBrowserWindowResizeListener(BrowserWindowResizeListener)}
- **/
- @Deprecated
- public void removeListener(BrowserWindowResizeListener resizeListener) {
- removeBrowserWindowResizeListener(resizeListener);
- }
-
- /**
* Gets the last known height of the browser window in which this UI
* resides.
*
diff --git a/server/src/main/java/com/vaadin/server/data/AbstractDataSource.java b/server/src/main/java/com/vaadin/server/data/AbstractDataSource.java
index 9dba0bd35e..f54056e1b0 100644
--- a/server/src/main/java/com/vaadin/server/data/AbstractDataSource.java
+++ b/server/src/main/java/com/vaadin/server/data/AbstractDataSource.java
@@ -36,7 +36,6 @@ public abstract class AbstractDataSource<T> implements DataSource<T> {
@Override
public Registration addDataSourceListener(DataSourceListener listener) {
- Objects.requireNonNull(listener, "listener cannot be null");
addListener(DataChangeEvent.class, listener,
DataSourceListener.class.getMethods()[0]);
return () -> removeListener(DataChangeEvent.class, listener);
diff --git a/server/src/main/java/com/vaadin/ui/AbsoluteLayout.java b/server/src/main/java/com/vaadin/ui/AbsoluteLayout.java
index d435bc806b..5aa008e829 100644
--- a/server/src/main/java/com/vaadin/ui/AbsoluteLayout.java
+++ b/server/src/main/java/com/vaadin/ui/AbsoluteLayout.java
@@ -20,6 +20,7 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
+import java.util.Objects;
import org.jsoup.nodes.Attributes;
import org.jsoup.nodes.Element;
@@ -32,6 +33,7 @@ import com.vaadin.server.Sizeable;
import com.vaadin.shared.Connector;
import com.vaadin.shared.EventId;
import com.vaadin.shared.MouseEventDetails;
+import com.vaadin.shared.Registration;
import com.vaadin.shared.ui.absolutelayout.AbsoluteLayoutServerRpc;
import com.vaadin.shared.ui.absolutelayout.AbsoluteLayoutState;
import com.vaadin.ui.declarative.DesignAttributeHandler;
@@ -643,38 +645,21 @@ public class AbsoluteLayout extends AbstractLayout
}
@Override
- public void addLayoutClickListener(LayoutClickListener listener) {
+ public Registration addLayoutClickListener(LayoutClickListener listener) {
addListener(EventId.LAYOUT_CLICK_EVENT_IDENTIFIER,
LayoutClickEvent.class, listener,
LayoutClickListener.clickMethod);
+ return () -> removeListener(EventId.LAYOUT_CLICK_EVENT_IDENTIFIER,
+ LayoutClickEvent.class, listener);
}
- /**
- * @deprecated As of 7.0, replaced by
- * {@link #addLayoutClickListener(LayoutClickListener)}
- **/
@Override
@Deprecated
- public void addListener(LayoutClickListener listener) {
- addLayoutClickListener(listener);
- }
-
- @Override
public void removeLayoutClickListener(LayoutClickListener listener) {
removeListener(EventId.LAYOUT_CLICK_EVENT_IDENTIFIER,
LayoutClickEvent.class, listener);
}
- /**
- * @deprecated As of 7.0, replaced by
- * {@link #removeLayoutClickListener(LayoutClickListener)}
- **/
- @Override
- @Deprecated
- public void removeListener(LayoutClickListener listener) {
- removeLayoutClickListener(listener);
- }
-
/*
* (non-Javadoc)
*
diff --git a/server/src/main/java/com/vaadin/ui/AbstractColorPicker.java b/server/src/main/java/com/vaadin/ui/AbstractColorPicker.java
index d7d12c6d03..695187a6eb 100644
--- a/server/src/main/java/com/vaadin/ui/AbstractColorPicker.java
+++ b/server/src/main/java/com/vaadin/ui/AbstractColorPicker.java
@@ -18,10 +18,12 @@ package com.vaadin.ui;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.Collection;
+import java.util.Objects;
import org.jsoup.nodes.Attributes;
import org.jsoup.nodes.Element;
+import com.vaadin.shared.Registration;
import com.vaadin.shared.ui.colorpicker.Color;
import com.vaadin.shared.ui.colorpicker.ColorPickerServerRpc;
import com.vaadin.shared.ui.colorpicker.ColorPickerState;
@@ -217,11 +219,13 @@ public abstract class AbstractColorPicker extends AbstractComponent
}
@Override
- public void addColorChangeListener(ColorChangeListener listener) {
+ public Registration addColorChangeListener(ColorChangeListener listener) {
addListener(ColorChangeEvent.class, listener, COLOR_CHANGE_METHOD);
+ return () -> removeListener(ColorChangeEvent.class, listener);
}
@Override
+ @Deprecated
public void removeColorChangeListener(ColorChangeListener listener) {
removeListener(ColorChangeEvent.class, listener);
}
diff --git a/server/src/main/java/com/vaadin/ui/AbstractComponent.java b/server/src/main/java/com/vaadin/ui/AbstractComponent.java
index a34b09e9d8..f794cab51b 100644
--- a/server/src/main/java/com/vaadin/ui/AbstractComponent.java
+++ b/server/src/main/java/com/vaadin/ui/AbstractComponent.java
@@ -26,6 +26,7 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Objects;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.logging.Logger;
@@ -57,6 +58,7 @@ import com.vaadin.shared.ComponentConstants;
import com.vaadin.shared.ContextClickRpc;
import com.vaadin.shared.EventId;
import com.vaadin.shared.MouseEventDetails;
+import com.vaadin.shared.Registration;
import com.vaadin.shared.ui.ComponentStateUtil;
import com.vaadin.shared.util.SharedUtil;
import com.vaadin.ui.declarative.DesignAttributeHandler;
@@ -787,16 +789,14 @@ public abstract class AbstractComponent extends AbstractClientConnector
* implemented interface.
*/
@Override
- public void addListener(Component.Listener listener) {
+ public Registration addListener(Component.Listener listener) {
addListener(Component.Event.class, listener, COMPONENT_EVENT_METHOD);
+ return () -> removeListener(Component.Event.class, listener,
+ COMPONENT_EVENT_METHOD);
}
- /*
- * Removes a previously registered listener from this component. Don't add a
- * JavaDoc comment here, we use the default documentation from implemented
- * interface.
- */
@Override
+ @Deprecated
public void removeListener(Component.Listener listener) {
removeListener(Component.Event.class, listener, COMPONENT_EVENT_METHOD);
}
@@ -1084,8 +1084,7 @@ public abstract class AbstractComponent extends AbstractClientConnector
}
} else {
// remove responsive extensions
- List<Extension> extensions = new ArrayList<>(
- getExtensions());
+ List<Extension> extensions = new ArrayList<>(getExtensions());
for (Extension e : extensions) {
if (e instanceof Responsive) {
removeExtension(e);
@@ -1263,8 +1262,7 @@ public abstract class AbstractComponent extends AbstractClientConnector
* implementation
*/
protected Collection<String> getCustomAttributes() {
- ArrayList<String> l = new ArrayList<>(
- Arrays.asList(customAttributes));
+ ArrayList<String> l = new ArrayList<>(Arrays.asList(customAttributes));
if (this instanceof Focusable) {
l.add("tab-index");
l.add("tabindex");
@@ -1365,10 +1363,13 @@ public abstract class AbstractComponent extends AbstractClientConnector
}
- public void addShortcutListener(ShortcutListener shortcut) {
+ public Registration addShortcutListener(ShortcutListener shortcut) {
+ Objects.requireNonNull(shortcut, "Listener must not be null.");
getActionManager().addAction(shortcut);
+ return () -> getActionManager().removeAction(shortcut);
}
+ @Deprecated
public void removeShortcutListener(ShortcutListener shortcut) {
getActionManager().removeAction(shortcut);
}
@@ -1394,7 +1395,7 @@ public abstract class AbstractComponent extends AbstractClientConnector
}
@Override
- public void addContextClickListener(ContextClickListener listener) {
+ public Registration addContextClickListener(ContextClickListener listener) {
// Register default Context Click RPC if needed. This RPC won't be
// called if there are no listeners on the server-side. A client-side
// connector can override this and use a different RPC channel.
@@ -1410,9 +1411,12 @@ public abstract class AbstractComponent extends AbstractClientConnector
addListener(EventId.CONTEXT_CLICK, ContextClickEvent.class, listener,
ContextClickEvent.CONTEXT_CLICK_METHOD);
+ return () -> removeListener(EventId.CONTEXT_CLICK,
+ ContextClickEvent.class, listener);
}
@Override
+ @Deprecated
public void removeContextClickListener(ContextClickListener listener) {
removeListener(EventId.CONTEXT_CLICK, ContextClickEvent.class,
listener);
diff --git a/server/src/main/java/com/vaadin/ui/AbstractComponentContainer.java b/server/src/main/java/com/vaadin/ui/AbstractComponentContainer.java
index b5fe4e9bcd..8c10027cc4 100644
--- a/server/src/main/java/com/vaadin/ui/AbstractComponentContainer.java
+++ b/server/src/main/java/com/vaadin/ui/AbstractComponentContainer.java
@@ -22,6 +22,7 @@ import java.util.Iterator;
import java.util.LinkedList;
import com.vaadin.server.ComponentSizeValidator;
+import com.vaadin.shared.Registration;
/**
* Extension to {@link AbstractComponent} that defines the default
@@ -99,58 +100,36 @@ public abstract class AbstractComponentContainer extends AbstractComponent
/* documented in interface */
@Override
- public void addComponentAttachListener(ComponentAttachListener listener) {
+ public Registration addComponentAttachListener(
+ ComponentAttachListener listener) {
addListener(ComponentAttachEvent.class, listener,
ComponentAttachListener.attachMethod);
- }
-
- /**
- * @deprecated As of 7.0, replaced by
- * {@link #addComponentAttachListener(com.vaadin.ui.ComponentContainer.ComponentAttachListener)}
- **/
- @Override
- @Deprecated
- public void addListener(ComponentAttachListener listener) {
- addComponentAttachListener(listener);
+ return () -> removeListener(ComponentAttachEvent.class, listener,
+ ComponentAttachListener.attachMethod);
}
/* documented in interface */
@Override
+ @Deprecated
public void removeComponentAttachListener(
ComponentAttachListener listener) {
removeListener(ComponentAttachEvent.class, listener,
ComponentAttachListener.attachMethod);
}
- /**
- * @deprecated As of 7.0, replaced by
- * {@link #addComponentDetachListener(com.vaadin.ui.ComponentContainer.ComponentDetachListener)}
- **/
- @Override
- @Deprecated
- public void addListener(ComponentDetachListener listener) {
- addComponentDetachListener(listener);
- }
-
/* documented in interface */
@Override
- public void addComponentDetachListener(ComponentDetachListener listener) {
+ public Registration addComponentDetachListener(
+ ComponentDetachListener listener) {
addListener(ComponentDetachEvent.class, listener,
ComponentDetachListener.detachMethod);
- }
-
- /**
- * @deprecated As of 7.0, replaced by
- * {@link #removeComponentAttachListener(com.vaadin.ui.ComponentContainer.ComponentAttachListener)}
- **/
- @Override
- @Deprecated
- public void removeListener(ComponentAttachListener listener) {
- removeComponentAttachListener(listener);
+ return () -> removeListener(ComponentDetachEvent.class, listener,
+ ComponentDetachListener.detachMethod);
}
/* documented in interface */
@Override
+ @Deprecated
public void removeComponentDetachListener(
ComponentDetachListener listener) {
removeListener(ComponentDetachEvent.class, listener,
@@ -158,16 +137,6 @@ public abstract class AbstractComponentContainer extends AbstractComponent
}
/**
- * @deprecated As of 7.0, replaced by
- * {@link #removeComponentDetachListener(com.vaadin.ui.ComponentContainer.ComponentDetachListener)}
- **/
- @Override
- @Deprecated
- public void removeListener(ComponentDetachListener listener) {
- removeComponentDetachListener(listener);
- }
-
- /**
* Fires the component attached event. This should be called by the
* addComponent methods after the component have been added to this
* container.
diff --git a/server/src/main/java/com/vaadin/ui/AbstractDateField.java b/server/src/main/java/com/vaadin/ui/AbstractDateField.java
index ac945256f7..ab0aed1b0c 100644
--- a/server/src/main/java/com/vaadin/ui/AbstractDateField.java
+++ b/server/src/main/java/com/vaadin/ui/AbstractDateField.java
@@ -32,11 +32,14 @@ import com.vaadin.data.Result;
import com.vaadin.data.validator.RangeValidator;
import com.vaadin.event.FieldEvents.BlurEvent;
import com.vaadin.event.FieldEvents.BlurListener;
+import com.vaadin.event.FieldEvents.BlurNotifier;
import com.vaadin.event.FieldEvents.FocusEvent;
import com.vaadin.event.FieldEvents.FocusListener;
+import com.vaadin.event.FieldEvents.FocusNotifier;
import com.vaadin.server.PaintException;
import com.vaadin.server.PaintTarget;
import com.vaadin.server.UserError;
+import com.vaadin.shared.Registration;
import com.vaadin.shared.ui.datefield.DateFieldConstants;
import com.vaadin.shared.ui.datefield.Resolution;
import com.vaadin.shared.ui.datefield.TextualDateFieldState;
@@ -52,7 +55,7 @@ import com.vaadin.ui.declarative.DesignContext;
*
*/
public abstract class AbstractDateField extends AbstractField<Date>
- implements LegacyComponent {
+ implements LegacyComponent, FocusNotifier, BlurNotifier {
/**
* Value of the field.
@@ -669,46 +672,30 @@ public abstract class AbstractDateField extends AbstractField<Date>
markAsDirty();
}
- /**
- * Adds a <code>FocusListener</code> to the Component which gets fired when
- * a <code>LegacyField</code> receives keyboard focus.
- *
- * @param listener
- * @see FocusListener
- */
- public void addFocusListener(FocusListener listener) {
+ @Override
+ public Registration addFocusListener(FocusListener listener) {
addListener(FocusEvent.EVENT_ID, FocusEvent.class, listener,
FocusListener.focusMethod);
+ return () -> removeListener(FocusEvent.EVENT_ID, FocusEvent.class,
+ listener);
}
- /**
- * Removes a <code>FocusListener</code> from the Component.
- *
- * @param listener
- * @see FocusListener
- */
+ @Override
+ @Deprecated
public void removeFocusListener(FocusListener listener) {
removeListener(FocusEvent.EVENT_ID, FocusEvent.class, listener);
}
- /**
- * Adds a <code>BlurListener</code> to the Component which gets fired when a
- * <code>LegacyField</code> loses keyboard focus.
- *
- * @param listener
- * @see BlurListener
- */
- public void addBlurListener(BlurListener listener) {
+ @Override
+ public Registration addBlurListener(BlurListener listener) {
addListener(BlurEvent.EVENT_ID, BlurEvent.class, listener,
BlurListener.blurMethod);
+ return () -> removeListener(BlurEvent.EVENT_ID, BlurEvent.class,
+ listener);
}
- /**
- * Removes a <code>BlurListener</code> from the Component.
- *
- * @param listener
- * @see BlurListener
- */
+ @Override
+ @Deprecated
public void removeBlurListener(BlurListener listener) {
removeListener(BlurEvent.EVENT_ID, BlurEvent.class, listener);
}
diff --git a/server/src/main/java/com/vaadin/ui/AbstractField.java b/server/src/main/java/com/vaadin/ui/AbstractField.java
index 4946d3c95b..012a5df5a1 100644
--- a/server/src/main/java/com/vaadin/ui/AbstractField.java
+++ b/server/src/main/java/com/vaadin/ui/AbstractField.java
@@ -101,7 +101,6 @@ public abstract class AbstractField<T> extends AbstractComponent
@Override
public Registration addValueChangeListener(
ValueChangeListener<? super T> listener) {
- Objects.requireNonNull(listener, "listener cannot be null");
addListener(ValueChange.class, listener, VALUE_CHANGE_METHOD);
return () -> removeListener(ValueChange.class, listener);
}
diff --git a/server/src/main/java/com/vaadin/ui/AbstractFocusable.java b/server/src/main/java/com/vaadin/ui/AbstractFocusable.java
index ac0f911fbc..eb0c957a80 100644
--- a/server/src/main/java/com/vaadin/ui/AbstractFocusable.java
+++ b/server/src/main/java/com/vaadin/ui/AbstractFocusable.java
@@ -15,6 +15,8 @@
*/
package com.vaadin.ui;
+import java.util.Objects;
+
import com.vaadin.event.FieldEvents.BlurEvent;
import com.vaadin.event.FieldEvents.BlurListener;
import com.vaadin.event.FieldEvents.BlurNotifier;
@@ -22,6 +24,7 @@ import com.vaadin.event.FieldEvents.FocusAndBlurServerRpcImpl;
import com.vaadin.event.FieldEvents.FocusEvent;
import com.vaadin.event.FieldEvents.FocusListener;
import com.vaadin.event.FieldEvents.FocusNotifier;
+import com.vaadin.shared.Registration;
import com.vaadin.shared.ui.TabIndexState;
import com.vaadin.ui.Component.Focusable;
@@ -45,24 +48,29 @@ public abstract class AbstractFocusable extends AbstractComponent
}
@Override
- public void addBlurListener(BlurListener listener) {
+ public Registration addBlurListener(BlurListener listener) {
addListener(BlurEvent.EVENT_ID, BlurEvent.class, listener,
BlurListener.blurMethod);
+ return () -> removeListener(BlurEvent.EVENT_ID, BlurEvent.class,
+ listener);
}
@Override
+ @Deprecated
public void removeBlurListener(BlurListener listener) {
removeListener(BlurEvent.EVENT_ID, BlurEvent.class, listener);
}
@Override
- public void addFocusListener(FocusListener listener) {
+ public Registration addFocusListener(FocusListener listener) {
addListener(FocusEvent.EVENT_ID, FocusEvent.class, listener,
FocusListener.focusMethod);
-
+ return () -> removeListener(FocusEvent.EVENT_ID, FocusEvent.class,
+ listener);
}
@Override
+ @Deprecated
public void removeFocusListener(FocusListener listener) {
removeListener(FocusEvent.EVENT_ID, FocusEvent.class, listener);
}
diff --git a/server/src/main/java/com/vaadin/ui/AbstractMultiSelect.java b/server/src/main/java/com/vaadin/ui/AbstractMultiSelect.java
index 4094ee383c..48b47ca2d5 100644
--- a/server/src/main/java/com/vaadin/ui/AbstractMultiSelect.java
+++ b/server/src/main/java/com/vaadin/ui/AbstractMultiSelect.java
@@ -303,7 +303,6 @@ public abstract class AbstractMultiSelect<T>
*/
public Registration addSelectionListener(
MultiSelectionListener<T> listener) {
- Objects.requireNonNull(listener, "listener cannot be null");
addListener(MultiSelectionEvent.class, listener,
SELECTION_CHANGE_METHOD);
return () -> removeListener(MultiSelectionEvent.class, listener);
@@ -404,4 +403,4 @@ public abstract class AbstractMultiSelect<T>
this.itemEnabledProvider = itemEnabledProvider;
}
-} \ No newline at end of file
+}
diff --git a/server/src/main/java/com/vaadin/ui/AbstractOrderedLayout.java b/server/src/main/java/com/vaadin/ui/AbstractOrderedLayout.java
index 331a0e72be..3be9ca668a 100644
--- a/server/src/main/java/com/vaadin/ui/AbstractOrderedLayout.java
+++ b/server/src/main/java/com/vaadin/ui/AbstractOrderedLayout.java
@@ -31,6 +31,7 @@ import com.vaadin.server.Sizeable;
import com.vaadin.shared.Connector;
import com.vaadin.shared.EventId;
import com.vaadin.shared.MouseEventDetails;
+import com.vaadin.shared.Registration;
import com.vaadin.shared.ui.MarginInfo;
import com.vaadin.shared.ui.orderedlayout.AbstractOrderedLayoutServerRpc;
import com.vaadin.shared.ui.orderedlayout.AbstractOrderedLayoutState;
@@ -367,39 +368,22 @@ public abstract class AbstractOrderedLayout extends AbstractLayout
}
@Override
- public void addLayoutClickListener(LayoutClickListener listener) {
+ public Registration addLayoutClickListener(LayoutClickListener listener) {
addListener(EventId.LAYOUT_CLICK_EVENT_IDENTIFIER,
LayoutClickEvent.class, listener,
LayoutClickListener.clickMethod);
+ return () -> removeListener(EventId.LAYOUT_CLICK_EVENT_IDENTIFIER,
+ LayoutClickEvent.class, listener);
}
- /**
- * @deprecated As of 7.0, replaced by
- * {@link #addLayoutClickListener(LayoutClickListener)}
- **/
@Override
@Deprecated
- public void addListener(LayoutClickListener listener) {
- addLayoutClickListener(listener);
- }
-
- @Override
public void removeLayoutClickListener(LayoutClickListener listener) {
removeListener(EventId.LAYOUT_CLICK_EVENT_IDENTIFIER,
LayoutClickEvent.class, listener);
}
/**
- * @deprecated As of 7.0, replaced by
- * {@link #removeLayoutClickListener(LayoutClickListener)}
- **/
- @Override
- @Deprecated
- public void removeListener(LayoutClickListener listener) {
- removeLayoutClickListener(listener);
- }
-
- /**
* Returns the index of the given component.
*
* @param component
diff --git a/server/src/main/java/com/vaadin/ui/AbstractSingleComponentContainer.java b/server/src/main/java/com/vaadin/ui/AbstractSingleComponentContainer.java
index 3e47a739cf..dc92ece1e9 100644
--- a/server/src/main/java/com/vaadin/ui/AbstractSingleComponentContainer.java
+++ b/server/src/main/java/com/vaadin/ui/AbstractSingleComponentContainer.java
@@ -24,6 +24,7 @@ import org.jsoup.select.Elements;
import com.vaadin.server.ComponentSizeValidator;
import com.vaadin.server.VaadinService;
import com.vaadin.server.VaadinSession;
+import com.vaadin.shared.Registration;
import com.vaadin.ui.declarative.DesignContext;
import com.vaadin.ui.declarative.DesignException;
@@ -57,14 +58,17 @@ public abstract class AbstractSingleComponentContainer extends AbstractComponent
/* documented in interface */
@Override
- public void addComponentAttachListener(ComponentAttachListener listener) {
+ public Registration addComponentAttachListener(
+ ComponentAttachListener listener) {
addListener(ComponentAttachEvent.class, listener,
ComponentAttachListener.attachMethod);
-
+ return () -> removeListener(ComponentAttachEvent.class, listener,
+ ComponentAttachListener.attachMethod);
}
/* documented in interface */
@Override
+ @Deprecated
public void removeComponentAttachListener(
ComponentAttachListener listener) {
removeListener(ComponentAttachEvent.class, listener,
@@ -73,13 +77,17 @@ public abstract class AbstractSingleComponentContainer extends AbstractComponent
/* documented in interface */
@Override
- public void addComponentDetachListener(ComponentDetachListener listener) {
+ public Registration addComponentDetachListener(
+ ComponentDetachListener listener) {
addListener(ComponentDetachEvent.class, listener,
ComponentDetachListener.detachMethod);
+ return () -> removeListener(ComponentDetachEvent.class, listener,
+ ComponentDetachListener.detachMethod);
}
/* documented in interface */
@Override
+ @Deprecated
public void removeComponentDetachListener(
ComponentDetachListener listener) {
removeListener(ComponentDetachEvent.class, listener,
diff --git a/server/src/main/java/com/vaadin/ui/AbstractSingleSelect.java b/server/src/main/java/com/vaadin/ui/AbstractSingleSelect.java
index 257e1c9da8..bf521f34cb 100644
--- a/server/src/main/java/com/vaadin/ui/AbstractSingleSelect.java
+++ b/server/src/main/java/com/vaadin/ui/AbstractSingleSelect.java
@@ -269,7 +269,6 @@ public abstract class AbstractSingleSelect<T> extends
*/
public Registration addSelectionListener(
SingleSelectionListener<T> listener) {
- Objects.requireNonNull(listener, "listener cannot be null");
addListener(SingleSelectionChange.class, listener,
SELECTION_CHANGE_METHOD);
return () -> removeListener(SingleSelectionChange.class, listener);
diff --git a/server/src/main/java/com/vaadin/ui/AbstractSplitPanel.java b/server/src/main/java/com/vaadin/ui/AbstractSplitPanel.java
index 3add13cd4a..5f481cb537 100644
--- a/server/src/main/java/com/vaadin/ui/AbstractSplitPanel.java
+++ b/server/src/main/java/com/vaadin/ui/AbstractSplitPanel.java
@@ -29,6 +29,7 @@ import com.vaadin.server.SizeWithUnit;
import com.vaadin.server.Sizeable;
import com.vaadin.shared.EventId;
import com.vaadin.shared.MouseEventDetails;
+import com.vaadin.shared.Registration;
import com.vaadin.shared.ui.splitpanel.AbstractSplitPanelRpc;
import com.vaadin.shared.ui.splitpanel.AbstractSplitPanelState;
import com.vaadin.shared.ui.splitpanel.AbstractSplitPanelState.SplitterState;
@@ -575,45 +576,32 @@ public abstract class AbstractSplitPanel extends AbstractComponentContainer {
}
- public void addSplitterClickListener(SplitterClickListener listener) {
+ public Registration addSplitterClickListener(
+ SplitterClickListener listener) {
addListener(EventId.CLICK_EVENT_IDENTIFIER, SplitterClickEvent.class,
listener, SplitterClickListener.clickMethod);
+ return () -> removeListener(EventId.CLICK_EVENT_IDENTIFIER,
+ SplitterClickEvent.class, listener);
}
- /**
- * @deprecated As of 7.0, replaced by
- * {@link #addSplitterClickListener(SplitterClickListener)}
- **/
@Deprecated
- public void addListener(SplitterClickListener listener) {
- addSplitterClickListener(listener);
- }
-
public void removeSplitterClickListener(SplitterClickListener listener) {
removeListener(EventId.CLICK_EVENT_IDENTIFIER, SplitterClickEvent.class,
listener);
}
/**
- * @deprecated As of 7.0, replaced by
- * {@link #removeSplitterClickListener(SplitterClickListener)}
- **/
- @Deprecated
- public void removeListener(SplitterClickListener listener) {
- removeSplitterClickListener(listener);
- }
-
- /**
* Register a listener to handle {@link SplitPositionChangeEvent}s.
*
* @since 7.5.0
* @param listener
* {@link SplitPositionChangeListener} to be registered.
*/
- public void addSplitPositionChangeListener(
+ public Registration addSplitPositionChangeListener(
SplitPositionChangeListener listener) {
addListener(SplitPositionChangeEvent.class, listener,
SplitPositionChangeListener.moveMethod);
+ return () -> removeListener(SplitPositionChangeEvent.class, listener);
}
/**
@@ -623,6 +611,7 @@ public abstract class AbstractSplitPanel extends AbstractComponentContainer {
* @param listener
* SplitPositionChangeListener to be removed.
*/
+ @Deprecated
public void removeSplitPositionChangeListener(
SplitPositionChangeListener listener) {
removeListener(SplitPositionChangeEvent.class, listener);
diff --git a/server/src/main/java/com/vaadin/ui/Button.java b/server/src/main/java/com/vaadin/ui/Button.java
index da77a1760b..499713ffbd 100644
--- a/server/src/main/java/com/vaadin/ui/Button.java
+++ b/server/src/main/java/com/vaadin/ui/Button.java
@@ -30,6 +30,7 @@ import com.vaadin.event.ShortcutAction.ModifierKey;
import com.vaadin.event.ShortcutListener;
import com.vaadin.server.Resource;
import com.vaadin.shared.MouseEventDetails;
+import com.vaadin.shared.Registration;
import com.vaadin.shared.ui.button.ButtonServerRpc;
import com.vaadin.shared.ui.button.ButtonState;
import com.vaadin.ui.declarative.DesignAttributeHandler;
@@ -118,7 +119,7 @@ public class Button extends AbstractFocusable
*/
public Button(String caption, ClickListener listener) {
this(caption);
- addListener(listener);
+ addClickListener(listener);
}
/**
@@ -306,21 +307,17 @@ public class Button extends AbstractFocusable
/**
* Adds the button click listener.
*
+ * @see Registration
+ *
* @param listener
* the Listener to be added.
+ * @return a registration object for removing the listener
*/
- public void addClickListener(ClickListener listener) {
+ public Registration addClickListener(ClickListener listener) {
addListener(ClickEvent.class, listener,
ClickListener.BUTTON_CLICK_METHOD);
- }
-
- /**
- * @deprecated As of 7.0, replaced by
- * {@link #addClickListener(ClickListener)}
- **/
- @Deprecated
- public void addListener(ClickListener listener) {
- addClickListener(listener);
+ return () -> removeListener(ClickEvent.class, listener,
+ ClickListener.BUTTON_CLICK_METHOD);
}
/**
@@ -328,22 +325,18 @@ public class Button extends AbstractFocusable
*
* @param listener
* the Listener to be removed.
+ *
+ * @deprecated As of 8.0, replaced by {@link Registration#remove()} in the
+ * registration object returned from
+ * {@link #addClickListener(ClickListener)}.
*/
+ @Deprecated
public void removeClickListener(ClickListener listener) {
removeListener(ClickEvent.class, listener,
ClickListener.BUTTON_CLICK_METHOD);
}
/**
- * @deprecated As of 7.0, replaced by
- * {@link #removeClickListener(ClickListener)}
- **/
- @Deprecated
- public void removeListener(ClickListener listener) {
- removeClickListener(listener);
- }
-
- /**
* Simulates a button click, notifying all server-side listeners.
*
* No action is taken is the button is disabled.
diff --git a/server/src/main/java/com/vaadin/ui/CheckBox.java b/server/src/main/java/com/vaadin/ui/CheckBox.java
index 2620b42464..4fa08a82b5 100644
--- a/server/src/main/java/com/vaadin/ui/CheckBox.java
+++ b/server/src/main/java/com/vaadin/ui/CheckBox.java
@@ -21,18 +21,21 @@ import java.util.Collection;
import org.jsoup.nodes.Attributes;
import org.jsoup.nodes.Element;
+import com.vaadin.event.FieldEvents;
import com.vaadin.event.FieldEvents.BlurEvent;
import com.vaadin.event.FieldEvents.BlurListener;
import com.vaadin.event.FieldEvents.FocusAndBlurServerRpcImpl;
import com.vaadin.event.FieldEvents.FocusEvent;
import com.vaadin.event.FieldEvents.FocusListener;
import com.vaadin.shared.MouseEventDetails;
+import com.vaadin.shared.Registration;
import com.vaadin.shared.ui.checkbox.CheckBoxServerRpc;
import com.vaadin.shared.ui.checkbox.CheckBoxState;
import com.vaadin.ui.declarative.DesignAttributeHandler;
import com.vaadin.ui.declarative.DesignContext;
-public class CheckBox extends AbstractField<Boolean> {
+public class CheckBox extends AbstractField<Boolean>
+ implements FieldEvents.BlurNotifier, FieldEvents.FocusNotifier {
private CheckBoxServerRpc rpc = new CheckBoxServerRpc() {
@@ -145,20 +148,30 @@ public class CheckBox extends AbstractField<Boolean> {
getState().checked = value;
}
- public void addBlurListener(BlurListener listener) {
+ @Override
+ public Registration addBlurListener(BlurListener listener) {
addListener(BlurEvent.EVENT_ID, BlurEvent.class, listener,
BlurListener.blurMethod);
+ return () -> removeListener(BlurEvent.EVENT_ID, BlurEvent.class,
+ listener);
}
+ @Override
+ @Deprecated
public void removeBlurListener(BlurListener listener) {
removeListener(BlurEvent.EVENT_ID, BlurEvent.class, listener);
}
- public void addFocusListener(FocusListener listener) {
+ @Override
+ public Registration addFocusListener(FocusListener listener) {
addListener(FocusEvent.EVENT_ID, FocusEvent.class, listener,
FocusListener.focusMethod);
+ return () -> removeListener(FocusEvent.EVENT_ID, FocusEvent.class,
+ listener);
}
+ @Override
+ @Deprecated
public void removeFocusListener(FocusListener listener) {
removeListener(FocusEvent.EVENT_ID, FocusEvent.class, listener);
}
diff --git a/server/src/main/java/com/vaadin/ui/ColorPickerArea.java b/server/src/main/java/com/vaadin/ui/ColorPickerArea.java
index c4f3971259..dc2adfed3a 100644
--- a/server/src/main/java/com/vaadin/ui/ColorPickerArea.java
+++ b/server/src/main/java/com/vaadin/ui/ColorPickerArea.java
@@ -73,5 +73,4 @@ public class ColorPickerArea extends AbstractColorPicker {
getState().width = "30px";
}
}
-
}
diff --git a/server/src/main/java/com/vaadin/ui/ComboBox.java b/server/src/main/java/com/vaadin/ui/ComboBox.java
index 5ed454d370..31dbb7da94 100644
--- a/server/src/main/java/com/vaadin/ui/ComboBox.java
+++ b/server/src/main/java/com/vaadin/ui/ComboBox.java
@@ -21,7 +21,6 @@ import java.util.Collection;
import java.util.Objects;
import java.util.function.BiFunction;
import java.util.function.Consumer;
-import java.util.function.Function;
import com.vaadin.data.HasValue;
import com.vaadin.event.FieldEvents;
@@ -288,23 +287,29 @@ public class ComboBox<T> extends AbstractSingleSelect<T> implements HasValue<T>,
}
@Override
- public void addBlurListener(BlurListener listener) {
+ public Registration addBlurListener(BlurListener listener) {
addListener(BlurEvent.EVENT_ID, BlurEvent.class, listener,
BlurListener.blurMethod);
+ return () -> removeListener(BlurEvent.EVENT_ID, BlurEvent.class,
+ listener);
}
@Override
+ @Deprecated
public void removeBlurListener(BlurListener listener) {
removeListener(BlurEvent.EVENT_ID, BlurEvent.class, listener);
}
@Override
- public void addFocusListener(FocusListener listener) {
+ public Registration addFocusListener(FocusListener listener) {
addListener(FocusEvent.EVENT_ID, FocusEvent.class, listener,
FocusListener.focusMethod);
+ return () -> removeListener(FocusEvent.EVENT_ID, FocusEvent.class,
+ listener);
}
@Override
+ @Deprecated
public void removeFocusListener(FocusListener listener) {
removeListener(FocusEvent.EVENT_ID, FocusEvent.class, listener);
}
diff --git a/server/src/main/java/com/vaadin/ui/Component.java b/server/src/main/java/com/vaadin/ui/Component.java
index 993d88d992..ffca8b808c 100644
--- a/server/src/main/java/com/vaadin/ui/Component.java
+++ b/server/src/main/java/com/vaadin/ui/Component.java
@@ -29,6 +29,7 @@ import com.vaadin.server.ErrorMessage;
import com.vaadin.server.Resource;
import com.vaadin.server.Sizeable;
import com.vaadin.server.VariableOwner;
+import com.vaadin.shared.Registration;
import com.vaadin.ui.declarative.DesignContext;
/**
@@ -972,10 +973,11 @@ public interface Component extends ClientConnector, Sizeable, Serializable {
*
* @param listener
* the new Listener to be registered.
+ * @return a registration object for removing this listener
* @see Component.Event
- * @see #removeListener(Listener)
+ * @see Registration
*/
- public void addListener(Component.Listener listener);
+ public Registration addListener(Component.Listener listener);
/**
* Removes a previously registered component event listener from this
@@ -984,7 +986,12 @@ public interface Component extends ClientConnector, Sizeable, Serializable {
* @param listener
* the listener to be removed.
* @see #addListener(Listener)
+ *
+ * @deprecated As of 8.0, replaced by {@link Registration#remove()} in the
+ * registration object returned from
+ * {@link #addListener(Component.Listener)}.
*/
+ @Deprecated
public void removeListener(Component.Listener listener);
/**
diff --git a/server/src/main/java/com/vaadin/ui/ComponentContainer.java b/server/src/main/java/com/vaadin/ui/ComponentContainer.java
index ba6594d10d..b11f2e9a69 100644
--- a/server/src/main/java/com/vaadin/ui/ComponentContainer.java
+++ b/server/src/main/java/com/vaadin/ui/ComponentContainer.java
@@ -111,33 +111,4 @@ public interface ComponentContainer
* moved to this container.
*/
public void moveComponentsFrom(ComponentContainer source);
-
- /**
- * @deprecated As of 7.0, replaced by
- * {@link #addComponentAttachListener(ComponentAttachListener)}
- **/
- @Deprecated
- public void addListener(ComponentAttachListener listener);
-
- /**
- * @deprecated As of 7.0, replaced by
- * {@link #removeComponentAttachListener(ComponentAttachListener)}
- **/
- @Deprecated
- public void removeListener(ComponentAttachListener listener);
-
- /**
- * @deprecated As of 7.0, replaced by
- * {@link #addComponentDetachListener(ComponentDetachListener)}
- **/
- @Deprecated
- public void addListener(ComponentDetachListener listener);
-
- /**
- * @deprecated As of 7.0, replaced by
- * {@link #removeComponentDetachListener(ComponentDetachListener)}
- **/
- @Deprecated
- public void removeListener(ComponentDetachListener listener);
-
}
diff --git a/server/src/main/java/com/vaadin/ui/CssLayout.java b/server/src/main/java/com/vaadin/ui/CssLayout.java
index 381e7aa463..d4daf67419 100644
--- a/server/src/main/java/com/vaadin/ui/CssLayout.java
+++ b/server/src/main/java/com/vaadin/ui/CssLayout.java
@@ -17,6 +17,7 @@ package com.vaadin.ui;
import java.util.Iterator;
import java.util.LinkedList;
+import java.util.Objects;
import org.jsoup.nodes.Element;
@@ -26,6 +27,7 @@ import com.vaadin.event.LayoutEvents.LayoutClickNotifier;
import com.vaadin.shared.Connector;
import com.vaadin.shared.EventId;
import com.vaadin.shared.MouseEventDetails;
+import com.vaadin.shared.Registration;
import com.vaadin.shared.ui.csslayout.CssLayoutServerRpc;
import com.vaadin.shared.ui.csslayout.CssLayoutState;
import com.vaadin.ui.declarative.DesignContext;
@@ -303,39 +305,22 @@ public class CssLayout extends AbstractLayout implements LayoutClickNotifier {
}
@Override
- public void addLayoutClickListener(LayoutClickListener listener) {
+ public Registration addLayoutClickListener(LayoutClickListener listener) {
addListener(EventId.LAYOUT_CLICK_EVENT_IDENTIFIER,
LayoutClickEvent.class, listener,
LayoutClickListener.clickMethod);
+ return () -> removeListener(EventId.LAYOUT_CLICK_EVENT_IDENTIFIER,
+ LayoutClickEvent.class, listener);
}
- /**
- * @deprecated As of 7.0, replaced by
- * {@link #addLayoutClickListener(LayoutClickListener)}
- **/
@Override
@Deprecated
- public void addListener(LayoutClickListener listener) {
- addLayoutClickListener(listener);
- }
-
- @Override
public void removeLayoutClickListener(LayoutClickListener listener) {
removeListener(EventId.LAYOUT_CLICK_EVENT_IDENTIFIER,
LayoutClickEvent.class, listener);
}
/**
- * @deprecated As of 7.0, replaced by
- * {@link #removeLayoutClickListener(LayoutClickListener)}
- **/
- @Override
- @Deprecated
- public void removeListener(LayoutClickListener listener) {
- removeLayoutClickListener(listener);
- }
-
- /**
* Returns the index of the given component.
*
* @param component
@@ -397,5 +382,4 @@ public class CssLayout extends AbstractLayout implements LayoutClickNotifier {
designElement.appendChild(childNode);
}
}
-
}
diff --git a/server/src/main/java/com/vaadin/ui/Embedded.java b/server/src/main/java/com/vaadin/ui/Embedded.java
index b0c7f1725b..e4dcee096f 100644
--- a/server/src/main/java/com/vaadin/ui/Embedded.java
+++ b/server/src/main/java/com/vaadin/ui/Embedded.java
@@ -27,6 +27,7 @@ import com.vaadin.server.PaintTarget;
import com.vaadin.server.Resource;
import com.vaadin.shared.EventId;
import com.vaadin.shared.MouseEventDetails;
+import com.vaadin.shared.Registration;
import com.vaadin.shared.ui.embedded.EmbeddedConstants;
import com.vaadin.shared.ui.embedded.EmbeddedServerRpc;
@@ -524,23 +525,17 @@ public class Embedded extends AbstractComponent implements LegacyComponent {
* the user clicks inside the component. Depending on the content the event
* may be blocked and in that case no event is fired.
*
- * Use {@link #removeListener(ClickListener)} to remove the listener.
+ * @see Registration
*
* @param listener
* The listener to add
+ * @return a registration object for removing the listener
*/
- public void addClickListener(ClickListener listener) {
+ public Registration addClickListener(ClickListener listener) {
addListener(EventId.CLICK_EVENT_IDENTIFIER, ClickEvent.class, listener,
ClickListener.clickMethod);
- }
-
- /**
- * @deprecated As of 7.0, replaced by
- * {@link #addClickListener(ClickListener)}
- **/
- @Deprecated
- public void addListener(ClickListener listener) {
- addClickListener(listener);
+ return () -> removeListener(EventId.CLICK_EVENT_IDENTIFIER,
+ ClickEvent.class, listener);
}
/**
@@ -549,21 +544,17 @@ public class Embedded extends AbstractComponent implements LegacyComponent {
*
* @param listener
* The listener to remove
+ *
+ * @deprecated As of 8.0, replaced by {@link Registration#remove()} in the
+ * registration object returned from
+ * {@link #addClickListener(ClickListener)}.
*/
+ @Deprecated
public void removeClickListener(ClickListener listener) {
removeListener(EventId.CLICK_EVENT_IDENTIFIER, ClickEvent.class,
listener);
}
- /**
- * @deprecated As of 7.0, replaced by
- * {@link #removeClickListener(ClickListener)}
- **/
- @Deprecated
- public void removeListener(ClickListener listener) {
- removeClickListener(listener);
- }
-
@Override
public void changeVariables(Object source, Map<String, Object> variables) {
// TODO Remove once LegacyComponent is no longer implemented
diff --git a/server/src/main/java/com/vaadin/ui/Grid.java b/server/src/main/java/com/vaadin/ui/Grid.java
index b1a2c64ec8..e2df8b437b 100644
--- a/server/src/main/java/com/vaadin/ui/Grid.java
+++ b/server/src/main/java/com/vaadin/ui/Grid.java
@@ -2020,7 +2020,6 @@ public class Grid<T> extends AbstractSingleSelect<T> implements HasComponents {
* @return a registration for the listener
*/
public Registration addColumnResizeListener(ColumnResizeListener listener) {
- Objects.requireNonNull(listener, "listener cannot be null");
addListener(ColumnResizeEvent.class, listener, COLUMN_RESIZE_METHOD);
return () -> removeListener(ColumnResizeEvent.class, listener,
COLUMN_RESIZE_METHOD);
@@ -2036,7 +2035,6 @@ public class Grid<T> extends AbstractSingleSelect<T> implements HasComponents {
*/
public Registration addItemClickListener(
ItemClickListener<? super T> listener) {
- Objects.requireNonNull(listener, "listener cannot be null");
addListener(GridConstants.ITEM_CLICK_EVENT_ID, ItemClick.class,
listener, ITEM_CLICK_METHOD);
return () -> removeListener(ItemClick.class, listener);
@@ -2051,7 +2049,6 @@ public class Grid<T> extends AbstractSingleSelect<T> implements HasComponents {
*/
public Registration addColumnVisibilityChangeListener(
ColumnVisibilityChangeListener listener) {
- Objects.requireNonNull(listener, "listener cannot be null");
addListener(ColumnVisibilityChangeEvent.class, listener,
COLUMN_VISIBILITY_METHOD);
return () -> removeListener(ColumnVisibilityChangeEvent.class, listener,
diff --git a/server/src/main/java/com/vaadin/ui/GridLayout.java b/server/src/main/java/com/vaadin/ui/GridLayout.java
index 6e74071f65..40b8575c36 100644
--- a/server/src/main/java/com/vaadin/ui/GridLayout.java
+++ b/server/src/main/java/com/vaadin/ui/GridLayout.java
@@ -27,6 +27,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Objects;
import java.util.Set;
import org.jsoup.nodes.Attributes;
@@ -39,6 +40,7 @@ import com.vaadin.event.LayoutEvents.LayoutClickNotifier;
import com.vaadin.shared.Connector;
import com.vaadin.shared.EventId;
import com.vaadin.shared.MouseEventDetails;
+import com.vaadin.shared.Registration;
import com.vaadin.shared.ui.MarginInfo;
import com.vaadin.shared.ui.gridlayout.GridLayoutServerRpc;
import com.vaadin.shared.ui.gridlayout.GridLayoutState;
@@ -445,6 +447,7 @@ public class GridLayout extends AbstractLayout
return components.size();
}
+ @Override
public void beforeClientResponse(boolean initial) {
super.beforeClientResponse(initial);
@@ -1163,38 +1166,21 @@ public class GridLayout extends AbstractLayout
}
@Override
- public void addLayoutClickListener(LayoutClickListener listener) {
+ public Registration addLayoutClickListener(LayoutClickListener listener) {
addListener(EventId.LAYOUT_CLICK_EVENT_IDENTIFIER,
LayoutClickEvent.class, listener,
LayoutClickListener.clickMethod);
+ return () -> removeListener(EventId.LAYOUT_CLICK_EVENT_IDENTIFIER,
+ LayoutClickEvent.class, listener);
}
- /**
- * @deprecated As of 7.0, replaced by
- * {@link #addLayoutClickListener(LayoutClickListener)}
- **/
@Override
@Deprecated
- public void addListener(LayoutClickListener listener) {
- addLayoutClickListener(listener);
- }
-
- @Override
public void removeLayoutClickListener(LayoutClickListener listener) {
removeListener(EventId.LAYOUT_CLICK_EVENT_IDENTIFIER,
LayoutClickEvent.class, listener);
}
- /**
- * @deprecated As of 7.0, replaced by
- * {@link #removeLayoutClickListener(LayoutClickListener)}
- **/
- @Override
- @Deprecated
- public void removeListener(LayoutClickListener listener) {
- removeLayoutClickListener(listener);
- }
-
/*
* (non-Javadoc)
*
diff --git a/server/src/main/java/com/vaadin/ui/HasComponents.java b/server/src/main/java/com/vaadin/ui/HasComponents.java
index e74eb6dd32..847a6fada2 100644
--- a/server/src/main/java/com/vaadin/ui/HasComponents.java
+++ b/server/src/main/java/com/vaadin/ui/HasComponents.java
@@ -19,6 +19,7 @@ import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.Iterator;
+import com.vaadin.shared.Registration;
import com.vaadin.util.ReflectTools;
/**
@@ -50,10 +51,13 @@ public interface HasComponents extends Component, Iterable<Component> {
/**
* Listens the component attach events.
*
+ * @see Registration
+ *
* @param listener
- * the listener to add.
+ * the listener to add, not null
+ * @return a registration object for removing the listener
*/
- public void addComponentAttachListener(
+ public Registration addComponentAttachListener(
ComponentAttachListener listener);
/**
@@ -61,19 +65,26 @@ public interface HasComponents extends Component, Iterable<Component> {
*
* @param listener
* the listener to removed.
+ *
+ * @deprecated As of 8.0, replaced by {@link Registration#remove()} in
+ * the registration object returned from
+ * {@link #addComponentAttachListener(ComponentAttachListener)}
+ * .
*/
+ @Deprecated
public void removeComponentAttachListener(
ComponentAttachListener listener);
/**
* Listens the component detach events.
*/
- public void addComponentDetachListener(
+ public Registration addComponentDetachListener(
ComponentDetachListener listener);
/**
* Stops the listening component detach events.
*/
+ @Deprecated
public void removeComponentDetachListener(
ComponentDetachListener listener);
}
diff --git a/server/src/main/java/com/vaadin/ui/Image.java b/server/src/main/java/com/vaadin/ui/Image.java
index af698ecc97..fca1bc7b8a 100644
--- a/server/src/main/java/com/vaadin/ui/Image.java
+++ b/server/src/main/java/com/vaadin/ui/Image.java
@@ -20,6 +20,7 @@ import com.vaadin.event.MouseEvents.ClickListener;
import com.vaadin.server.Resource;
import com.vaadin.shared.EventId;
import com.vaadin.shared.MouseEventDetails;
+import com.vaadin.shared.Registration;
import com.vaadin.shared.ui.image.ImageServerRpc;
import com.vaadin.shared.ui.image.ImageState;
@@ -76,36 +77,21 @@ public class Image extends AbstractEmbedded {
}
/**
- * @deprecated As of 7.0, use {@link #addClickListener(ClickListener)}
- * instead
- */
- @Deprecated
- public void addListener(ClickListener listener) {
- addClickListener(listener);
- }
-
- /**
* Add a click listener to the component. The listener is called whenever
* the user clicks inside the component. Depending on the content the event
* may be blocked and in that case no event is fired.
*
- * Use {@link #removeClickListener(ClickListener)} to remove the listener.
+ * @see Registration
*
* @param listener
- * The listener to add
+ * The listener to add, not null
+ * @return a registration object for removing the listener
*/
- public void addClickListener(ClickListener listener) {
+ public Registration addClickListener(ClickListener listener) {
addListener(EventId.CLICK_EVENT_IDENTIFIER, ClickEvent.class, listener,
ClickListener.clickMethod);
- }
-
- /**
- * @deprecated As of 7.0, use {@link #removeClickListener(ClickListener)}
- * instead
- */
- @Deprecated
- public void removeListener(ClickListener listener) {
- removeClickListener(listener);
+ return () -> removeListener(EventId.CLICK_EVENT_IDENTIFIER,
+ ClickEvent.class, listener);
}
/**
@@ -114,7 +100,12 @@ public class Image extends AbstractEmbedded {
*
* @param listener
* The listener to remove
+ *
+ * @deprecated As of 8.0, replaced by {@link Registration#remove()} in the
+ * registration object returned from
+ * {@link #addClickListener(ClickListener)}.
*/
+ @Deprecated
public void removeClickListener(ClickListener listener) {
removeListener(EventId.CLICK_EVENT_IDENTIFIER, ClickEvent.class,
listener);
diff --git a/server/src/main/java/com/vaadin/ui/LegacyWindow.java b/server/src/main/java/com/vaadin/ui/LegacyWindow.java
index a6771da379..2705d56486 100644
--- a/server/src/main/java/com/vaadin/ui/LegacyWindow.java
+++ b/server/src/main/java/com/vaadin/ui/LegacyWindow.java
@@ -329,7 +329,7 @@ public class LegacyWindow extends UI {
*/
@Deprecated
public void addListener(BrowserWindowResizeListener resizeListener) {
- getPage().addListener(resizeListener);
+ getPage().addBrowserWindowResizeListener(resizeListener);
}
/**
@@ -342,7 +342,7 @@ public class LegacyWindow extends UI {
*/
@Deprecated
public void removeListener(BrowserWindowResizeListener resizeListener) {
- getPage().removeListener(resizeListener);
+ getPage().removeBrowserWindowResizeListener(resizeListener);
}
/**
diff --git a/server/src/main/java/com/vaadin/ui/Panel.java b/server/src/main/java/com/vaadin/ui/Panel.java
index 1f7197a76c..7b1333d898 100644
--- a/server/src/main/java/com/vaadin/ui/Panel.java
+++ b/server/src/main/java/com/vaadin/ui/Panel.java
@@ -31,6 +31,7 @@ import com.vaadin.server.PaintTarget;
import com.vaadin.server.Scrollable;
import com.vaadin.shared.EventId;
import com.vaadin.shared.MouseEventDetails;
+import com.vaadin.shared.Registration;
import com.vaadin.shared.ui.panel.PanelServerRpc;
import com.vaadin.shared.ui.panel.PanelState;
import com.vaadin.ui.Component.Focusable;
@@ -268,23 +269,17 @@ public class Panel extends AbstractSingleComponentContainer
* inside the Panel, provided the targeted component does not prevent the
* click event from propagating.
*
- * Use {@link #removeListener(ClickListener)} to remove the listener.
+ * @see Registration
*
* @param listener
- * The listener to add
+ * The listener to add, not null
+ * @return a registration object for removing the listener
*/
- public void addClickListener(ClickListener listener) {
+ public Registration addClickListener(ClickListener listener) {
addListener(EventId.CLICK_EVENT_IDENTIFIER, ClickEvent.class, listener,
ClickListener.clickMethod);
- }
-
- /**
- * @deprecated As of 7.0, replaced by
- * {@link #addClickListener(ClickListener)}
- **/
- @Deprecated
- public void addListener(ClickListener listener) {
- addClickListener(listener);
+ return () -> removeListener(EventId.CLICK_EVENT_IDENTIFIER,
+ ClickEvent.class, listener);
}
/**
@@ -293,22 +288,17 @@ public class Panel extends AbstractSingleComponentContainer
*
* @param listener
* The listener to remove
+ * @deprecated As of 8.0, replaced by {@link Registration#remove()} in the
+ * registration object returned from
+ * {@link #addClickListener(ClickListener)}.
*/
+ @Deprecated
public void removeClickListener(ClickListener listener) {
removeListener(EventId.CLICK_EVENT_IDENTIFIER, ClickEvent.class,
listener);
}
/**
- * @deprecated As of 7.0, replaced by
- * {@link #removeClickListener(ClickListener)}
- **/
- @Deprecated
- public void removeListener(ClickListener listener) {
- removeClickListener(listener);
- }
-
- /**
* {@inheritDoc}
*/
@Override
diff --git a/server/src/main/java/com/vaadin/ui/PopupView.java b/server/src/main/java/com/vaadin/ui/PopupView.java
index ed540f149c..497e052f22 100644
--- a/server/src/main/java/com/vaadin/ui/PopupView.java
+++ b/server/src/main/java/com/vaadin/ui/PopupView.java
@@ -24,6 +24,7 @@ import org.jsoup.nodes.Element;
import org.jsoup.nodes.Node;
import org.jsoup.parser.Tag;
+import com.vaadin.shared.Registration;
import com.vaadin.shared.ui.popupview.PopupViewServerRpc;
import com.vaadin.shared.ui.popupview.PopupViewState;
import com.vaadin.ui.declarative.DesignContext;
@@ -334,25 +335,19 @@ public class PopupView extends AbstractComponent implements HasComponents {
* Add a listener that is called whenever the visibility of the popup is
* changed.
*
- * @param listener
- * the listener to add
* @see PopupVisibilityListener
* @see PopupVisibilityEvent
- * @see #removeListener(PopupVisibilityListener)
*
+ * @param listener
+ * the listener to add, not null
+ * @return a registration object for removing the listener
*/
- public void addPopupVisibilityListener(PopupVisibilityListener listener) {
+ public Registration addPopupVisibilityListener(
+ PopupVisibilityListener listener) {
addListener(PopupVisibilityEvent.class, listener,
POPUP_VISIBILITY_METHOD);
- }
-
- /**
- * @deprecated As of 7.0, replaced by
- * {@link #addPopupVisibilityListener(PopupVisibilityListener)}
- **/
- @Deprecated
- public void addListener(PopupVisibilityListener listener) {
- addPopupVisibilityListener(listener);
+ return () -> removeListener(PopupVisibilityEvent.class, listener,
+ POPUP_VISIBILITY_METHOD);
}
/**
@@ -363,7 +358,12 @@ public class PopupView extends AbstractComponent implements HasComponents {
* the listener to remove
* @see PopupVisibilityListener
* @see #addListener(PopupVisibilityListener)
+ *
+ * @deprecated As of 8.0, replaced by {@link Registration#remove()} in the
+ * registration object returned from
+ * {@link #addPopupVisibilityListener(PopupVisibilityListener)}.
*/
+ @Deprecated
public void removePopupVisibilityListener(
PopupVisibilityListener listener) {
removeListener(PopupVisibilityEvent.class, listener,
@@ -371,15 +371,6 @@ public class PopupView extends AbstractComponent implements HasComponents {
}
/**
- * @deprecated As of 7.0, replaced by
- * {@link #removePopupVisibilityListener(PopupVisibilityListener)}
- **/
- @Deprecated
- public void removeListener(PopupVisibilityListener listener) {
- removePopupVisibilityListener(listener);
- }
-
- /**
* This event is received by the PopupVisibilityListeners when the
* visibility of the popup changes. You can get the new visibility directly
* with {@link #isPopupVisible()}, or get the PopupView that produced the
diff --git a/server/src/main/java/com/vaadin/ui/TabSheet.java b/server/src/main/java/com/vaadin/ui/TabSheet.java
index a03b342ba0..79fe6227a1 100644
--- a/server/src/main/java/com/vaadin/ui/TabSheet.java
+++ b/server/src/main/java/com/vaadin/ui/TabSheet.java
@@ -39,6 +39,7 @@ import com.vaadin.server.ErrorMessage;
import com.vaadin.server.KeyMapper;
import com.vaadin.server.Resource;
import com.vaadin.shared.ComponentConstants;
+import com.vaadin.shared.Registration;
import com.vaadin.shared.ui.tabsheet.TabState;
import com.vaadin.shared.ui.tabsheet.TabsheetClientRpc;
import com.vaadin.shared.ui.tabsheet.TabsheetServerRpc;
@@ -843,32 +844,34 @@ public class TabSheet extends AbstractComponentContainer
}
/**
- * Adds a tab selection listener
+ * Adds a tab selection listener.
+ *
+ * @see Registration
*
* @param listener
- * the Listener to be added.
+ * the Listener to be added, not null
+ * @return a registration object for removing the listener
*/
- public void addSelectedTabChangeListener(
+ public Registration addSelectedTabChangeListener(
SelectedTabChangeListener listener) {
addListener(SelectedTabChangeEvent.class, listener,
SELECTED_TAB_CHANGE_METHOD);
+ return () -> removeListener(SelectedTabChangeEvent.class, listener,
+ SELECTED_TAB_CHANGE_METHOD);
}
/**
- * @deprecated As of 7.0, replaced by
- * {@link #addSelectedTabChangeListener(SelectedTabChangeListener)}
- **/
- @Deprecated
- public void addListener(SelectedTabChangeListener listener) {
- addSelectedTabChangeListener(listener);
- }
-
- /**
- * Removes a tab selection listener
+ * Removes a tab selection listener.
*
* @param listener
* the Listener to be removed.
+ *
+ * @deprecated As of 8.0, replaced by {@link Registration#remove()} in the
+ * registration object returned from
+ * {@link #removeSelectedTabChangeListener(SelectedTabChangeListener)}
+ * .
*/
+ @Deprecated
public void removeSelectedTabChangeListener(
SelectedTabChangeListener listener) {
removeListener(SelectedTabChangeEvent.class, listener,
@@ -876,15 +879,6 @@ public class TabSheet extends AbstractComponentContainer
}
/**
- * @deprecated As of 7.0, replaced by
- * {@link #removeSelectedTabChangeListener(SelectedTabChangeListener)}
- **/
- @Deprecated
- public void removeListener(SelectedTabChangeListener listener) {
- removeSelectedTabChangeListener(listener);
- }
-
- /**
* Sends an event that the currently selected tab has changed.
*/
protected void fireSelectedTabChange() {
@@ -1399,23 +1393,29 @@ public class TabSheet extends AbstractComponentContainer
}
@Override
- public void addBlurListener(BlurListener listener) {
+ public Registration addBlurListener(BlurListener listener) {
addListener(BlurEvent.EVENT_ID, BlurEvent.class, listener,
BlurListener.blurMethod);
+ return () -> removeListener(BlurEvent.EVENT_ID, BlurEvent.class,
+ listener);
}
@Override
+ @Deprecated
public void removeBlurListener(BlurListener listener) {
removeListener(BlurEvent.EVENT_ID, BlurEvent.class, listener);
}
@Override
- public void addFocusListener(FocusListener listener) {
+ public Registration addFocusListener(FocusListener listener) {
addListener(FocusEvent.EVENT_ID, FocusEvent.class, listener,
FocusListener.focusMethod);
+ return () -> removeListener(FocusEvent.EVENT_ID, FocusEvent.class,
+ listener);
}
@Override
+ @Deprecated
public void removeFocusListener(FocusListener listener) {
removeListener(FocusEvent.EVENT_ID, FocusEvent.class, listener);
}
diff --git a/server/src/main/java/com/vaadin/ui/UI.java b/server/src/main/java/com/vaadin/ui/UI.java
index 82bbea7039..34e9177e0c 100644
--- a/server/src/main/java/com/vaadin/ui/UI.java
+++ b/server/src/main/java/com/vaadin/ui/UI.java
@@ -60,6 +60,7 @@ import com.vaadin.server.communication.PushConnection;
import com.vaadin.shared.Connector;
import com.vaadin.shared.EventId;
import com.vaadin.shared.MouseEventDetails;
+import com.vaadin.shared.Registration;
import com.vaadin.shared.communication.PushMode;
import com.vaadin.shared.ui.ui.DebugWindowClientRpc;
import com.vaadin.shared.ui.ui.DebugWindowServerRpc;
@@ -909,23 +910,17 @@ public abstract class UI extends AbstractSingleComponentContainer
* UI, provided the targeted component does not prevent the click event from
* propagating.
*
- * Use {@link #removeListener(ClickListener)} to remove the listener.
+ * @see Registration
*
* @param listener
- * The listener to add
+ * The listener to add, not null
+ * @return a registration object for removing the listener
*/
- public void addClickListener(ClickListener listener) {
+ public Registration addClickListener(ClickListener listener) {
addListener(EventId.CLICK_EVENT_IDENTIFIER, ClickEvent.class, listener,
ClickListener.clickMethod);
- }
-
- /**
- * @deprecated As of 7.0, replaced by
- * {@link #addClickListener(ClickListener)}
- **/
- @Deprecated
- public void addListener(ClickListener listener) {
- addClickListener(listener);
+ return () -> removeListener(EventId.CLICK_EVENT_IDENTIFIER,
+ ClickEvent.class, listener);
}
/**
@@ -934,21 +929,17 @@ public abstract class UI extends AbstractSingleComponentContainer
*
* @param listener
* The listener to remove
+ *
+ * @deprecated As of 8.0, replaced by {@link Registration#remove()} in the
+ * registration object returned from
+ * {@link #removeClickListener(ClickListener)}.
*/
+ @Deprecated
public void removeClickListener(ClickListener listener) {
removeListener(EventId.CLICK_EVENT_IDENTIFIER, ClickEvent.class,
listener);
}
- /**
- * @deprecated As of 7.0, replaced by
- * {@link #removeClickListener(ClickListener)}
- **/
- @Deprecated
- public void removeListener(ClickListener listener) {
- removeClickListener(listener);
- }
-
@Override
public boolean isConnectorEnabled() {
// TODO How can a UI be invisible? What does it mean?
@@ -1629,12 +1620,14 @@ public abstract class UI extends AbstractSingleComponentContainer
}
@Override
- public void addPollListener(PollListener listener) {
+ public Registration addPollListener(PollListener listener) {
addListener(EventId.POLL, PollEvent.class, listener,
PollListener.POLL_METHOD);
+ return () -> removeListener(EventId.POLL, PollEvent.class, listener);
}
@Override
+ @Deprecated
public void removePollListener(PollListener listener) {
removeListener(EventId.POLL, PollEvent.class, listener);
}
diff --git a/server/src/main/java/com/vaadin/ui/Upload.java b/server/src/main/java/com/vaadin/ui/Upload.java
index 9077a35b95..5d2d4763e7 100644
--- a/server/src/main/java/com/vaadin/ui/Upload.java
+++ b/server/src/main/java/com/vaadin/ui/Upload.java
@@ -22,6 +22,7 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Map;
+import java.util.Objects;
import com.vaadin.server.NoInputStreamException;
import com.vaadin.server.NoOutputStreamException;
@@ -29,6 +30,7 @@ import com.vaadin.server.PaintException;
import com.vaadin.server.PaintTarget;
import com.vaadin.server.StreamVariable.StreamingProgressEvent;
import com.vaadin.shared.EventId;
+import com.vaadin.shared.Registration;
import com.vaadin.shared.ui.upload.UploadClientRpc;
import com.vaadin.shared.ui.upload.UploadServerRpc;
import com.vaadin.shared.ui.upload.UploadState;
@@ -65,9 +67,9 @@ import com.vaadin.util.ReflectTools;
* button.
*
* <p>
- * Note! Because of browser dependent implementations of <input type="file">
- * element, setting size for Upload component is not supported. For some
- * browsers setting size may work to some extend.
+ * Note! Because of browser dependent implementations of
+ * <input type="file"> element, setting size for Upload component is not
+ * supported. For some browsers setting size may work to some extend.
*
* @author Vaadin Ltd.
* @since 3.0
@@ -627,19 +629,12 @@ public class Upload extends AbstractComponent
* Adds the upload started event listener.
*
* @param listener
- * the Listener to be added.
+ * the Listener to be added, not null
*/
- public void addStartedListener(StartedListener listener) {
+ public Registration addStartedListener(StartedListener listener) {
addListener(StartedEvent.class, listener, UPLOAD_STARTED_METHOD);
- }
-
- /**
- * @deprecated As of 7.0, replaced by
- * {@link #addStartedListener(StartedListener)}
- **/
- @Deprecated
- public void addListener(StartedListener listener) {
- addStartedListener(listener);
+ return () -> removeListener(StartedEvent.class, listener,
+ UPLOAD_STARTED_METHOD);
}
/**
@@ -648,36 +643,21 @@ public class Upload extends AbstractComponent
* @param listener
* the Listener to be removed.
*/
+ @Deprecated
public void removeStartedListener(StartedListener listener) {
removeListener(StartedEvent.class, listener, UPLOAD_STARTED_METHOD);
}
/**
- * @deprecated As of 7.0, replaced by
- * {@link #removeStartedListener(StartedListener)}
- **/
- @Deprecated
- public void removeListener(StartedListener listener) {
- removeStartedListener(listener);
- }
-
- /**
* Adds the upload received event listener.
*
* @param listener
- * the Listener to be added.
+ * the Listener to be added, not null
*/
- public void addFinishedListener(FinishedListener listener) {
+ public Registration addFinishedListener(FinishedListener listener) {
addListener(FinishedEvent.class, listener, UPLOAD_FINISHED_METHOD);
- }
-
- /**
- * @deprecated As of 7.0, replaced by
- * {@link #addFinishedListener(FinishedListener)}
- **/
- @Deprecated
- public void addListener(FinishedListener listener) {
- addFinishedListener(listener);
+ return () -> removeListener(FinishedEvent.class, listener,
+ UPLOAD_FINISHED_METHOD);
}
/**
@@ -686,36 +666,21 @@ public class Upload extends AbstractComponent
* @param listener
* the Listener to be removed.
*/
+ @Deprecated
public void removeFinishedListener(FinishedListener listener) {
removeListener(FinishedEvent.class, listener, UPLOAD_FINISHED_METHOD);
}
/**
- * @deprecated As of 7.0, replaced by
- * {@link #removeFinishedListener(FinishedListener)}
- **/
- @Deprecated
- public void removeListener(FinishedListener listener) {
- removeFinishedListener(listener);
- }
-
- /**
* Adds the upload interrupted event listener.
*
* @param listener
- * the Listener to be added.
+ * the Listener to be added, not null
*/
- public void addFailedListener(FailedListener listener) {
+ public Registration addFailedListener(FailedListener listener) {
addListener(FailedEvent.class, listener, UPLOAD_FAILED_METHOD);
- }
-
- /**
- * @deprecated As of 7.0, replaced by
- * {@link #addFailedListener(FailedListener)}
- **/
- @Deprecated
- public void addListener(FailedListener listener) {
- addFailedListener(listener);
+ return () -> removeListener(FailedEvent.class, listener,
+ UPLOAD_FAILED_METHOD);
}
/**
@@ -724,36 +689,21 @@ public class Upload extends AbstractComponent
* @param listener
* the Listener to be removed.
*/
+ @Deprecated
public void removeFailedListener(FailedListener listener) {
removeListener(FailedEvent.class, listener, UPLOAD_FAILED_METHOD);
}
/**
- * @deprecated As of 7.0, replaced by
- * {@link #removeFailedListener(FailedListener)}
- **/
- @Deprecated
- public void removeListener(FailedListener listener) {
- removeFailedListener(listener);
- }
-
- /**
* Adds the upload success event listener.
*
* @param listener
- * the Listener to be added.
+ * the Listener to be added, not null
*/
- public void addSucceededListener(SucceededListener listener) {
+ public Registration addSucceededListener(SucceededListener listener) {
addListener(SucceededEvent.class, listener, UPLOAD_SUCCEEDED_METHOD);
- }
-
- /**
- * @deprecated As of 7.0, replaced by
- * {@link #addSucceededListener(SucceededListener)}
- **/
- @Deprecated
- public void addListener(SucceededListener listener) {
- addSucceededListener(listener);
+ return () -> removeListener(SucceededEvent.class, listener,
+ UPLOAD_SUCCEEDED_METHOD);
}
/**
@@ -762,39 +712,28 @@ public class Upload extends AbstractComponent
* @param listener
* the Listener to be removed.
*/
+ @Deprecated
public void removeSucceededListener(SucceededListener listener) {
removeListener(SucceededEvent.class, listener, UPLOAD_SUCCEEDED_METHOD);
}
/**
- * @deprecated As of 7.0, replaced by
- * {@link #removeSucceededListener(SucceededListener)}
- **/
- @Deprecated
- public void removeListener(SucceededListener listener) {
- removeSucceededListener(listener);
- }
-
- /**
* Adds the upload progress event listener.
*
* @param listener
* the progress listener to be added
*/
- public void addProgressListener(ProgressListener listener) {
+ public Registration addProgressListener(ProgressListener listener) {
+ Objects.requireNonNull(listener, "Listener must not be null.");
if (progressListeners == null) {
progressListeners = new LinkedHashSet<>();
}
progressListeners.add(listener);
- }
-
- /**
- * @deprecated As of 7.0, replaced by
- * {@link #addProgressListener(ProgressListener)}
- **/
- @Deprecated
- public void addListener(ProgressListener listener) {
- addProgressListener(listener);
+ return () -> {
+ if (progressListeners != null) {
+ progressListeners.remove(listener);
+ }
+ };
}
/**
@@ -803,6 +742,7 @@ public class Upload extends AbstractComponent
* @param listener
* the progress listener to be removed
*/
+ @Deprecated
public void removeProgressListener(ProgressListener listener) {
if (progressListeners != null) {
progressListeners.remove(listener);
@@ -813,11 +753,13 @@ public class Upload extends AbstractComponent
* Adds a filename change event listener
*
* @param listener
- * the Listener to add
+ * the Listener to add, not null
*/
- public void addChangeListener(ChangeListener listener) {
+ public Registration addChangeListener(ChangeListener listener) {
super.addListener(EventId.CHANGE, ChangeEvent.class, listener,
ChangeListener.FILENAME_CHANGED);
+ return () -> super.removeListener(EventId.CHANGE, ChangeEvent.class,
+ listener);
}
/**
@@ -826,20 +768,12 @@ public class Upload extends AbstractComponent
* @param listener
* the listener to be removed
*/
+ @Deprecated
public void removeChangeListener(ChangeListener listener) {
super.removeListener(EventId.CHANGE, ChangeEvent.class, listener);
}
/**
- * @deprecated As of 7.0, replaced by
- * {@link #removeProgressListener(ProgressListener)}
- **/
- @Deprecated
- public void removeListener(ProgressListener listener) {
- removeProgressListener(listener);
- }
-
- /**
* Emit upload received event.
*
* @param filename
diff --git a/server/src/main/java/com/vaadin/ui/Window.java b/server/src/main/java/com/vaadin/ui/Window.java
index c0eac75970..82acf0ee6f 100644
--- a/server/src/main/java/com/vaadin/ui/Window.java
+++ b/server/src/main/java/com/vaadin/ui/Window.java
@@ -43,6 +43,7 @@ import com.vaadin.server.PaintException;
import com.vaadin.server.PaintTarget;
import com.vaadin.shared.Connector;
import com.vaadin.shared.MouseEventDetails;
+import com.vaadin.shared.Registration;
import com.vaadin.shared.ui.window.WindowMode;
import com.vaadin.shared.ui.window.WindowRole;
import com.vaadin.shared.ui.window.WindowServerRpc;
@@ -106,8 +107,7 @@ public class Window extends Panel
/**
* Holds registered CloseShortcut instances for query and later removal
*/
- private List<CloseShortcut> closeShortcuts = new ArrayList<>(
- 4);
+ private List<CloseShortcut> closeShortcuts = new ArrayList<>(4);
/**
* Creates a new, empty window
@@ -406,19 +406,12 @@ public class Window extends Panel
* </p>
*
* @param listener
- * the CloseListener to add.
+ * the CloseListener to add, not null
*/
- public void addCloseListener(CloseListener listener) {
+ public Registration addCloseListener(CloseListener listener) {
addListener(CloseEvent.class, listener, WINDOW_CLOSE_METHOD);
- }
-
- /**
- * @deprecated As of 7.0, replaced by
- * {@link #addCloseListener(CloseListener)}
- **/
- @Deprecated
- public void addListener(CloseListener listener) {
- addCloseListener(listener);
+ return () -> removeListener(CloseEvent.class, listener,
+ WINDOW_CLOSE_METHOD);
}
/**
@@ -431,19 +424,11 @@ public class Window extends Panel
* @param listener
* the CloseListener to remove.
*/
+ @Deprecated
public void removeCloseListener(CloseListener listener) {
removeListener(CloseEvent.class, listener, WINDOW_CLOSE_METHOD);
}
- /**
- * @deprecated As of 7.0, replaced by
- * {@link #removeCloseListener(CloseListener)}
- **/
- @Deprecated
- public void removeListener(CloseListener listener) {
- removeCloseListener(listener);
- }
-
protected void fireClose() {
fireEvent(new Window.CloseEvent(this));
}
@@ -523,9 +508,12 @@ public class Window extends Panel
* @param listener
* the WindowModeChangeListener to add.
*/
- public void addWindowModeChangeListener(WindowModeChangeListener listener) {
+ public Registration addWindowModeChangeListener(
+ WindowModeChangeListener listener) {
addListener(WindowModeChangeEvent.class, listener,
WindowModeChangeListener.windowModeChangeMethod);
+ return () -> removeListener(WindowModeChangeEvent.class, listener,
+ WindowModeChangeListener.windowModeChangeMethod);
}
/**
@@ -534,6 +522,7 @@ public class Window extends Panel
* @param listener
* the WindowModeChangeListener to remove.
*/
+ @Deprecated
public void removeWindowModeChangeListener(
WindowModeChangeListener listener) {
removeListener(WindowModeChangeEvent.class, listener,
@@ -597,19 +586,15 @@ public class Window extends Panel
/**
* Add a resize listener.
*
+ * @see Registration
+ *
* @param listener
+ * the listener to add, not null
+ * @return a registration object for removing the listener
*/
- public void addResizeListener(ResizeListener listener) {
+ public Registration addResizeListener(ResizeListener listener) {
addListener(ResizeEvent.class, listener, WINDOW_RESIZE_METHOD);
- }
-
- /**
- * @deprecated As of 7.0, replaced by
- * {@link #addResizeListener(ResizeListener)}
- **/
- @Deprecated
- public void addListener(ResizeListener listener) {
- addResizeListener(listener);
+ return () -> removeListener(ResizeEvent.class, listener);
}
/**
@@ -617,20 +602,12 @@ public class Window extends Panel
*
* @param listener
*/
+ @Deprecated
public void removeResizeListener(ResizeListener listener) {
removeListener(ResizeEvent.class, listener);
}
/**
- * @deprecated As of 7.0, replaced by
- * {@link #removeResizeListener(ResizeListener)}
- **/
- @Deprecated
- public void removeListener(ResizeListener listener) {
- removeResizeListener(listener);
- }
-
- /**
* Fire the resize event.
*/
protected void fireResize() {
@@ -1085,12 +1062,15 @@ public class Window extends Panel
* .event.FieldEvents.FocusListener)
*/
@Override
- public void addFocusListener(FocusListener listener) {
+ public Registration addFocusListener(FocusListener listener) {
addListener(FocusEvent.EVENT_ID, FocusEvent.class, listener,
FocusListener.focusMethod);
+ return () -> removeListener(FocusEvent.EVENT_ID, FocusEvent.class,
+ listener);
}
@Override
+ @Deprecated
public void removeFocusListener(FocusListener listener) {
removeListener(FocusEvent.EVENT_ID, FocusEvent.class, listener);
}
@@ -1103,12 +1083,15 @@ public class Window extends Panel
* event.FieldEvents.BlurListener)
*/
@Override
- public void addBlurListener(BlurListener listener) {
+ public Registration addBlurListener(BlurListener listener) {
addListener(BlurEvent.EVENT_ID, BlurEvent.class, listener,
BlurListener.blurMethod);
+ return () -> removeListener(BlurEvent.EVENT_ID, BlurEvent.class,
+ listener);
}
@Override
+ @Deprecated
public void removeBlurListener(BlurListener listener) {
removeListener(BlurEvent.EVENT_ID, BlurEvent.class, listener);
}
diff --git a/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerGradient.java b/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerGradient.java
index cbb1ba9795..77b939e8b4 100644
--- a/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerGradient.java
+++ b/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerGradient.java
@@ -17,11 +17,12 @@ package com.vaadin.ui.components.colorpicker;
import java.lang.reflect.Method;
+import com.vaadin.shared.Registration;
import com.vaadin.shared.ui.colorpicker.Color;
import com.vaadin.shared.ui.colorpicker.ColorPickerGradientServerRpc;
import com.vaadin.shared.ui.colorpicker.ColorPickerGradientState;
-import com.vaadin.ui.AbstractComponent;
import com.vaadin.ui.AbstractColorPicker.Coordinates2Color;
+import com.vaadin.ui.AbstractComponent;
/**
* A component that represents a color gradient within a color picker.
@@ -103,11 +104,13 @@ public class ColorPickerGradient extends AbstractComponent
}
@Override
- public void addColorChangeListener(ColorChangeListener listener) {
+ public Registration addColorChangeListener(ColorChangeListener listener) {
addListener(ColorChangeEvent.class, listener, COLOR_CHANGE_METHOD);
+ return () -> removeListener(ColorChangeEvent.class, listener);
}
@Override
+ @Deprecated
public void removeColorChangeListener(ColorChangeListener listener) {
removeListener(ColorChangeEvent.class, listener);
}
diff --git a/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerGrid.java b/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerGrid.java
index 9e5580c719..544d6c9c9e 100644
--- a/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerGrid.java
+++ b/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerGrid.java
@@ -20,6 +20,7 @@ import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
+import com.vaadin.shared.Registration;
import com.vaadin.shared.ui.colorpicker.Color;
import com.vaadin.shared.ui.colorpicker.ColorPickerGridServerRpc;
import com.vaadin.shared.ui.colorpicker.ColorPickerGridState;
@@ -182,15 +183,10 @@ public class ColorPickerGrid extends AbstractComponent
markAsDirty();
}
- /**
- * Adds a color change listener
- *
- * @param listener
- * The color change listener
- */
@Override
- public void addColorChangeListener(ColorChangeListener listener) {
+ public Registration addColorChangeListener(ColorChangeListener listener) {
addListener(ColorChangeEvent.class, listener, COLOR_CHANGE_METHOD);
+ return () -> removeListener(ColorChangeEvent.class, listener);
}
@Override
@@ -198,13 +194,8 @@ public class ColorPickerGrid extends AbstractComponent
return colorGrid[x][y];
}
- /**
- * Removes a color change listener
- *
- * @param listener
- * The listener
- */
@Override
+ @Deprecated
public void removeColorChangeListener(ColorChangeListener listener) {
removeListener(ColorChangeEvent.class, listener);
}
diff --git a/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerHistory.java b/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerHistory.java
index 1173faf152..de0b1f4c52 100644
--- a/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerHistory.java
+++ b/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerHistory.java
@@ -23,6 +23,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
+import com.vaadin.shared.Registration;
import com.vaadin.shared.ui.colorpicker.Color;
import com.vaadin.ui.CustomComponent;
@@ -188,24 +189,14 @@ public class ColorPickerHistory extends CustomComponent
return getColorHistory().contains(c);
}
- /**
- * Adds a color change listener
- *
- * @param listener
- * The listener
- */
@Override
- public void addColorChangeListener(ColorChangeListener listener) {
+ public Registration addColorChangeListener(ColorChangeListener listener) {
addListener(ColorChangeEvent.class, listener, COLOR_CHANGE_METHOD);
+ return () -> removeListener(ColorChangeEvent.class, listener);
}
- /**
- * Removes a color change listener
- *
- * @param listener
- * The listener
- */
@Override
+ @Deprecated
public void removeColorChangeListener(ColorChangeListener listener) {
removeListener(ColorChangeEvent.class, listener);
}
diff --git a/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPopup.java b/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPopup.java
index 8876e4809d..59c7033775 100644
--- a/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPopup.java
+++ b/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPopup.java
@@ -25,8 +25,10 @@ import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
+import com.vaadin.shared.Registration;
import com.vaadin.shared.ui.MarginInfo;
import com.vaadin.shared.ui.colorpicker.Color;
+import com.vaadin.ui.AbstractColorPicker.Coordinates2Color;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
@@ -39,7 +41,6 @@ import com.vaadin.ui.Slider.ValueOutOfBoundsException;
import com.vaadin.ui.TabSheet;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;
-import com.vaadin.ui.AbstractColorPicker.Coordinates2Color;
/**
* A component that represents color selection popup within a color picker.
@@ -569,11 +570,13 @@ public class ColorPickerPopup extends Window
}
@Override
- public void addColorChangeListener(ColorChangeListener listener) {
+ public Registration addColorChangeListener(ColorChangeListener listener) {
addListener(ColorChangeEvent.class, listener, COLOR_CHANGE_METHOD);
+ return () -> removeListener(ColorChangeEvent.class, listener);
}
@Override
+ @Deprecated
public void removeColorChangeListener(ColorChangeListener listener) {
removeListener(ColorChangeEvent.class, listener);
}
diff --git a/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPreview.java b/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPreview.java
index e7d9395e06..c747002bde 100644
--- a/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPreview.java
+++ b/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPreview.java
@@ -112,11 +112,13 @@ public class ColorPickerPreview extends CssLayout implements ColorSelector {
}
@Override
- public void addColorChangeListener(ColorChangeListener listener) {
+ public Registration addColorChangeListener(ColorChangeListener listener) {
addListener(ColorChangeEvent.class, listener, COLOR_CHANGE_METHOD);
+ return () -> removeListener(ColorChangeEvent.class, listener);
}
@Override
+ @Deprecated
public void removeColorChangeListener(ColorChangeListener listener) {
removeListener(ColorChangeEvent.class, listener);
}
diff --git a/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerSelect.java b/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerSelect.java
index ac0da15fc5..fd37d3345a 100644
--- a/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerSelect.java
+++ b/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerSelect.java
@@ -18,6 +18,7 @@ package com.vaadin.ui.components.colorpicker;
import java.util.EnumSet;
import com.vaadin.data.HasValue.ValueChange;
+import com.vaadin.shared.Registration;
import com.vaadin.shared.ui.colorpicker.Color;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.CustomComponent;
@@ -200,11 +201,12 @@ public class ColorPickerSelect extends CustomComponent
}
@Override
- public void addColorChangeListener(ColorChangeListener listener) {
- grid.addColorChangeListener(listener);
+ public Registration addColorChangeListener(ColorChangeListener listener) {
+ return grid.addColorChangeListener(listener);
}
@Override
+ @Deprecated
public void removeColorChangeListener(ColorChangeListener listener) {
grid.removeColorChangeListener(listener);
}
diff --git a/server/src/main/java/com/vaadin/ui/components/colorpicker/HasColorChangeListener.java b/server/src/main/java/com/vaadin/ui/components/colorpicker/HasColorChangeListener.java
index 7980111e2b..505365ec63 100644
--- a/server/src/main/java/com/vaadin/ui/components/colorpicker/HasColorChangeListener.java
+++ b/server/src/main/java/com/vaadin/ui/components/colorpicker/HasColorChangeListener.java
@@ -17,20 +17,32 @@ package com.vaadin.ui.components.colorpicker;
import java.io.Serializable;
+import com.vaadin.shared.Registration;
+
public interface HasColorChangeListener extends Serializable {
/**
* Adds a {@link ColorChangeListener} to the component.
*
+ * @see Registration
+ *
* @param listener
+ * the listener to add, not null
+ * @return a registration object for removing the listener
*/
- void addColorChangeListener(ColorChangeListener listener);
+ Registration addColorChangeListener(ColorChangeListener listener);
/**
* Removes a {@link ColorChangeListener} from the component.
*
* @param listener
+ * the listener to remove
+ *
+ * @deprecated As of 8.0, replaced by {@link Registration#remove()} in the
+ * registration object returned from
+ * {@link #addColorChangeListener(ColorChangeListener)}.
*/
+ @Deprecated
void removeColorChangeListener(ColorChangeListener listener);
}
diff --git a/server/src/main/java/com/vaadin/ui/renderers/ClickableRenderer.java b/server/src/main/java/com/vaadin/ui/renderers/ClickableRenderer.java
index 2617827b77..87cdae84af 100644
--- a/server/src/main/java/com/vaadin/ui/renderers/ClickableRenderer.java
+++ b/server/src/main/java/com/vaadin/ui/renderers/ClickableRenderer.java
@@ -20,6 +20,7 @@ import java.lang.reflect.Method;
import com.vaadin.event.ConnectorEventListener;
import com.vaadin.event.MouseEvents.ClickEvent;
import com.vaadin.shared.MouseEventDetails;
+import com.vaadin.shared.Registration;
import com.vaadin.shared.ui.grid.renderers.RendererClickRpc;
import com.vaadin.ui.Grid;
import com.vaadin.ui.Grid.Column;
@@ -38,8 +39,7 @@ import com.vaadin.util.ReflectTools;
* @since 7.4
* @author Vaadin Ltd
*/
-public abstract class ClickableRenderer<T, V>
- extends AbstractRenderer<T, V> {
+public abstract class ClickableRenderer<T, V> extends AbstractRenderer<T, V> {
/**
* An interface for listening to {@link RendererClickEvent renderer click
@@ -147,11 +147,12 @@ public abstract class ClickableRenderer<T, V>
* every time one of the buttons rendered by this renderer is clicked.
*
* @param listener
- * the click listener to be added
+ * the click listener to be added, not null
*/
- public void addClickListener(RendererClickListener<T> listener) {
+ public Registration addClickListener(RendererClickListener<T> listener) {
addListener(RendererClickEvent.class, listener,
RendererClickListener.CLICK_METHOD);
+ return () -> removeListener(RendererClickEvent.class, listener);
}
/**
@@ -160,6 +161,7 @@ public abstract class ClickableRenderer<T, V>
* @param listener
* the click listener to be removed
*/
+ @Deprecated
public void removeClickListener(RendererClickListener<T> listener) {
removeListener(RendererClickEvent.class, listener);
}