import java.lang.reflect.Method;
import com.vaadin.event.ConnectorEventListener;
+import com.vaadin.event.FieldEvents.BlurEvent;
+import com.vaadin.event.FieldEvents.BlurListener;
+import com.vaadin.event.FieldEvents.FocusListener;
import com.vaadin.ui.Component;
import com.vaadin.util.ReflectTools;
import com.vaadin.v7.ui.Field;
@Deprecated
public interface FieldEvents {
+ /**
+ * The interface for adding and removing <code>FocusEvent</code> listeners.
+ * By implementing this interface a class explicitly announces that it will
+ * generate a <code>FocusEvent</code> when it receives keyboard focus.
+ *
+ * @since 6.2
+ * @see FocusListener
+ * @see FocusEvent
+ */
+ @Deprecated
+ public interface FocusNotifier extends Serializable {
+ /**
+ * Adds a <code>FocusListener</code> to the Component which gets fired
+ * when a <code>Field</code> receives keyboard focus.
+ *
+ * @param listener
+ * @see FocusListener
+ * @since 6.2
+ */
+ public void addFocusListener(FocusListener listener);
+
+ /**
+ * Removes a <code>FocusListener</code> from the Component.
+ *
+ * @param listener
+ * @see FocusListener
+ * @since 6.2
+ */
+ public void removeFocusListener(FocusListener listener);
+ }
+
+ /**
+ * The interface for adding and removing <code>BlurEvent</code> listeners.
+ * By implementing this interface a class explicitly announces that it will
+ * generate a <code>BlurEvent</code> when it loses keyboard focus.
+ *
+ * @since 6.2
+ * @see BlurListener
+ * @see BlurEvent
+ */
+ @Deprecated
+ public interface BlurNotifier extends Serializable {
+ /**
+ * 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
+ */
+ public void addBlurListener(BlurListener listener);
+
+ /**
+ * Removes a <code>BlurListener</code> from the Component.
+ *
+ * @param listener
+ * @see BlurListener
+ * @since 6.2
+ */
+ public void removeBlurListener(BlurListener listener);
+ }
+
/**
* TextChangeEvents are fired when the user is editing the text content of a
* field. Most commonly text change events are triggered by typing text with
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.ui.LegacyComponent;
import com.vaadin.ui.declarative.DesignAttributeHandler;
import com.vaadin.ui.declarative.DesignContext;
+import com.vaadin.v7.event.FieldEvents.BlurNotifier;
+import com.vaadin.v7.event.FieldEvents.FocusNotifier;
import com.vaadin.v7.event.FieldEvents.TextChangeEvent;
import com.vaadin.v7.event.FieldEvents.TextChangeListener;
import com.vaadin.v7.event.FieldEvents.TextChangeNotifier;
import java.util.List;
import java.util.Map;
-import com.vaadin.event.FieldEvents;
import com.vaadin.event.FieldEvents.BlurEvent;
import com.vaadin.event.FieldEvents.BlurListener;
import com.vaadin.event.FieldEvents.FocusEvent;
import com.vaadin.server.Resource;
import com.vaadin.v7.data.Container;
import com.vaadin.v7.data.util.filter.SimpleStringFilter;
+import com.vaadin.v7.event.FieldEvents;
import com.vaadin.v7.shared.ui.combobox.ComboBoxConstants;
import com.vaadin.v7.shared.ui.combobox.ComboBoxState;
import com.vaadin.v7.shared.ui.combobox.FilteringMode;
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.FocusEvent;
import com.vaadin.v7.data.Validator.InvalidValueException;
import com.vaadin.v7.data.util.converter.Converter;
import com.vaadin.v7.data.validator.DateRangeValidator;
+import com.vaadin.v7.event.FieldEvents;
import com.vaadin.v7.shared.ui.datefield.DateFieldConstants;
import com.vaadin.v7.shared.ui.datefield.TextualDateFieldState;
/**
* Resolution identifier: seconds.
- *
+ *
* @deprecated As of 7.0, use {@link Resolution#SECOND}
*/
@Deprecated
import java.util.Collection;
-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.v7.data.Container;
+import com.vaadin.v7.event.FieldEvents;
/**
* This is a simple drop-down select without, for instance, support for
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.FocusEvent;
import com.vaadin.ui.declarative.DesignContext;
import com.vaadin.ui.declarative.DesignFormatter;
import com.vaadin.v7.data.Container;
+import com.vaadin.v7.event.FieldEvents;
import com.vaadin.v7.shared.ui.optiongroup.OptionGroupConstants;
import com.vaadin.v7.shared.ui.optiongroup.OptionGroupState;
--- /dev/null
+package com.vaadin.tests.server.component;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.easymock.EasyMock;
+import org.junit.Assert;
+
+import com.vaadin.tests.VaadinClasses;
+import com.vaadin.ui.Component;
+
+public abstract class AbstractListenerMethodsTestBase {
+
+ public static void main(String[] args) {
+ findAllListenerMethods();
+ }
+
+ private static void findAllListenerMethods() {
+ Set<Class<?>> classes = new HashSet<>();
+ for (Class<?> c : VaadinClasses.getAllServerSideClasses()) {
+ while (c != null && c.getName().startsWith("com.vaadin.")) {
+ classes.add(c);
+ c = c.getSuperclass();
+ }
+ }
+
+ for (Class<?> c : classes) {
+ boolean found = false;
+ for (Method m : c.getDeclaredMethods()) {
+ String methodName = m.getName();
+ if (methodName.startsWith("add")
+ && methodName.endsWith("Listener")
+ && !"addListener".equals(methodName)) {
+ if (m.getParameterTypes().length != 1) {
+ continue;
+ }
+ String packageName = "com.vaadin.tests.server";
+ if (Component.class.isAssignableFrom(c)) {
+ packageName += ".component."
+ + c.getSimpleName().toLowerCase();
+ continue;
+ }
+
+ if (!found) {
+ found = true;
+ System.out.println("package " + packageName + ";");
+
+ System.out.println("import "
+ + AbstractListenerMethodsTestBase.class
+ .getName()
+ + ";");
+ System.out.println("import " + c.getName() + ";");
+ System.out
+ .println(
+ "public class " + c.getSimpleName()
+ + "Listeners extends "
+ + AbstractListenerMethodsTestBase.class
+ .getSimpleName()
+ + " {");
+ }
+
+ String listenerClassName = m.getParameterTypes()[0]
+ .getSimpleName();
+ String eventClassName = listenerClassName
+ .replaceFirst("Listener$", "Event");
+ System.out.println("public void test" + listenerClassName
+ + "() throws Exception {");
+ System.out.println(" testListener(" + c.getSimpleName()
+ + ".class, " + eventClassName + ".class, "
+ + listenerClassName + ".class);");
+ System.out.println("}");
+ }
+ }
+ if (found) {
+ System.out.println("}");
+ System.out.println();
+ }
+ }
+ }
+
+ protected void testListenerAddGetRemove(Class<?> testClass,
+ Class<?> eventClass, Class<?> listenerClass) throws Exception {
+ // Create a component for testing
+ Object c = testClass.newInstance();
+ testListenerAddGetRemove(testClass, eventClass, listenerClass, c);
+
+ }
+
+ protected void testListenerAddGetRemove(Class<?> cls, Class<?> eventClass,
+ Class<?> listenerClass, Object c) throws Exception {
+
+ Object mockListener1 = EasyMock.createMock(listenerClass);
+ Object mockListener2 = EasyMock.createMock(listenerClass);
+
+ // Verify we start from no listeners
+ verifyListeners(c, eventClass);
+
+ // Add one listener and verify
+ addListener(c, mockListener1, listenerClass);
+ verifyListeners(c, eventClass, mockListener1);
+
+ // Add another listener and verify
+ addListener(c, mockListener2, listenerClass);
+ verifyListeners(c, eventClass, mockListener1, mockListener2);
+
+ // Ensure we can fetch using parent class also
+ if (eventClass.getSuperclass() != null) {
+ verifyListeners(c, eventClass.getSuperclass(), mockListener1,
+ mockListener2);
+ }
+
+ // Remove the first and verify
+ removeListener(c, mockListener1, listenerClass);
+ verifyListeners(c, eventClass, mockListener2);
+
+ // Remove the remaining and verify
+ removeListener(c, mockListener2, listenerClass);
+ verifyListeners(c, eventClass);
+
+ }
+
+ private void removeListener(Object c, Object listener,
+ Class<?> listenerClass) throws IllegalArgumentException,
+ IllegalAccessException, InvocationTargetException,
+ SecurityException, NoSuchMethodException {
+ Method method = getRemoveListenerMethod(c.getClass(), listenerClass);
+ method.invoke(c, listener);
+
+ }
+
+ private void addListener(Object c, Object listener1, Class<?> listenerClass)
+ throws IllegalArgumentException, IllegalAccessException,
+ InvocationTargetException, SecurityException,
+ NoSuchMethodException {
+ Method method = getAddListenerMethod(c.getClass(), listenerClass);
+ method.invoke(c, listener1);
+ }
+
+ private Collection<?> getListeners(Object c, Class<?> eventType)
+ throws IllegalArgumentException, IllegalAccessException,
+ InvocationTargetException, SecurityException,
+ NoSuchMethodException {
+ Method method = getGetListenersMethod(c.getClass());
+ return (Collection<?>) method.invoke(c, eventType);
+ }
+
+ private Method getGetListenersMethod(Class<? extends Object> cls)
+ throws SecurityException, NoSuchMethodException {
+ return cls.getMethod("getListeners", Class.class);
+ }
+
+ private Method getAddListenerMethod(Class<?> cls, Class<?> listenerClass)
+ throws SecurityException, NoSuchMethodException {
+ return cls.getMethod("add" + listenerClass.getSimpleName(),
+ listenerClass);
+
+ }
+
+ private Method getRemoveListenerMethod(Class<?> cls, Class<?> listenerClass)
+ throws SecurityException, NoSuchMethodException {
+ return cls.getMethod("remove" + listenerClass.getSimpleName(),
+ listenerClass);
+
+ }
+
+ private void verifyListeners(Object c, Class<?> eventClass,
+ Object... expectedListeners) throws IllegalArgumentException,
+ SecurityException, IllegalAccessException,
+ InvocationTargetException, NoSuchMethodException {
+ Collection<?> registeredListeners = getListeners(c, eventClass);
+ Assert.assertEquals("Number of listeners", expectedListeners.length,
+ registeredListeners.size());
+
+ Assert.assertArrayEquals(expectedListeners,
+ registeredListeners.toArray());
+
+ }
+}
\ No newline at end of file
import java.io.Serializable;
import com.vaadin.server.Resource;
+import com.vaadin.shared.Registration;
/**
* Implements the action framework. This class contains subinterfaces for action
}
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);
}
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;
* 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
*
* @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);
}
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;
*/
@Override
public void addListener(Class<?> eventType, Object object, Method method) {
+ Objects.requireNonNull(object, "Listener must not be null.");
if (listenerList == null) {
listenerList = new LinkedHashSet<>();
}
@Override
public void addListener(Class<?> eventType, Object object,
String methodName) {
+ Objects.requireNonNull(object, "Listener must not be null.");
if (listenerList == null) {
listenerList = new LinkedHashSet<>();
}
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;
* 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);
-
}
/**
* 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);
-
}
/**
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;
* 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);
}
/**
* @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);
* @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);
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;
*
* @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.
* @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);
}
// 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;
}
// 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);
}
}
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;
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
}
@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
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;
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);
/**
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;
}
@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) {
}
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;
*
* @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);
}
/**
* 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,
URI_FRAGMENT_CHANGED_METHOD);
}
- /**
- * @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}.
*
* @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);
+ };
}
/**
*
* @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,
&& eventRouter.hasListeners(BrowserWindowResizeEvent.class);
}
- /**
- * @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.
@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);
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;
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;
}
@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)
*
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;
}
@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);
}
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;
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;
* 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);
}
}
} 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);
* 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");
}
- 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);
}
}
@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.
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);
import java.util.LinkedList;
import com.vaadin.server.ComponentSizeValidator;
+import com.vaadin.shared.Registration;
/**
* Extension to {@link AbstractComponent} that defines the default
/* 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,
ComponentDetachListener.detachMethod);
}
- /**
- * @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
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;
*
*/
public abstract class AbstractDateField extends AbstractField<Date>
- implements LegacyComponent {
+ implements LegacyComponent, FocusNotifier, BlurNotifier {
/**
* Value of the field.
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);
}
@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);
}
*/
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;
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;
}
@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);
}
*/
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);
this.itemEnabledProvider = itemEnabledProvider;
}
-}
\ No newline at end of file
+}
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;
}
@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.
*
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;
/* 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,
/* 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,
*/
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);
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;
}
- 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.
*
* @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);
}
/**
* @param listener
* SplitPositionChangeListener to be removed.
*/
+ @Deprecated
public void removeSplitPositionChangeListener(
SplitPositionChangeListener listener) {
removeListener(SplitPositionChangeEvent.class, listener);
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;
*/
public Button(String caption, ClickListener listener) {
this(caption);
- addListener(listener);
+ addClickListener(listener);
}
/**
/**
* 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);
}
/**
*
* @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.
*
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() {
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);
}
getState().width = "30px";
}
}
-
}
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;
}
@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);
}
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;
/**
*
* @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
* @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);
/**
* 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);
-
}
import java.util.Iterator;
import java.util.LinkedList;
+import java.util.Objects;
import org.jsoup.nodes.Element;
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;
}
@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.
*
designElement.appendChild(childNode);
}
}
-
}
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;
* 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);
}
/**
*
* @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
* @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);
*/
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);
*/
public Registration addColumnVisibilityChangeListener(
ColumnVisibilityChangeListener listener) {
- Objects.requireNonNull(listener, "listener cannot be null");
addListener(ColumnVisibilityChangeEvent.class, listener,
COLUMN_VISIBILITY_METHOD);
return () -> removeListener(ColumnVisibilityChangeEvent.class, listener,
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;
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;
return components.size();
}
+ @Override
public void beforeClientResponse(boolean initial) {
super.beforeClientResponse(initial);
}
@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)
*
import java.lang.reflect.Method;
import java.util.Iterator;
+import com.vaadin.shared.Registration;
import com.vaadin.util.ReflectTools;
/**
/**
* 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);
/**
*
* @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);
}
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;
return (ImageState) super.getState();
}
- /**
- * @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);
}
/**
*
* @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
public void addListener(BrowserWindowResizeListener resizeListener) {
- getPage().addListener(resizeListener);
+ getPage().addBrowserWindowResizeListener(resizeListener);
}
/**
*/
@Deprecated
public void removeListener(BrowserWindowResizeListener resizeListener) {
- getPage().removeListener(resizeListener);
+ getPage().removeBrowserWindowResizeListener(resizeListener);
}
/**
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;
* 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);
}
/**
*
* @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}
*/
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;
* 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);
}
/**
* 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,
POPUP_VISIBILITY_METHOD);
}
- /**
- * @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
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;
}
/**
- * 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,
SELECTED_TAB_CHANGE_METHOD);
}
- /**
- * @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.
*/
}
@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);
}
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;
* 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);
}
/**
*
* @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?
}
@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);
}
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;
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;
* 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
* 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);
}
/**
* @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);
}
/**
* @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);
}
/**
* @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);
}
/**
* @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);
+ }
+ };
}
/**
* @param listener
* the progress listener to be removed
*/
+ @Deprecated
public void removeProgressListener(ProgressListener listener) {
if (progressListeners != null) {
progressListeners.remove(listener);
* 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);
}
/**
* @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.
*
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;
/**
* 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
* </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);
}
/**
* @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));
}
* @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);
}
/**
* @param listener
* the WindowModeChangeListener to remove.
*/
+ @Deprecated
public void removeWindowModeChangeListener(
WindowModeChangeListener listener) {
removeListener(WindowModeChangeEvent.class, listener,
/**
* 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);
}
/**
*
* @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.
*/
* .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);
}
* 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);
}
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.
}
@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);
}
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;
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
return colorGrid[x][y];
}
- /**
- * Removes a color change listener
- *
- * @param listener
- * The listener
- */
@Override
+ @Deprecated
public void removeColorChangeListener(ColorChangeListener listener) {
removeListener(ColorChangeEvent.class, listener);
}
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;
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);
}
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;
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.
}
@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);
}
}
@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);
}
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;
}
@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);
}
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);
}
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;
* @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
* 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);
}
/**
* @param listener
* the click listener to be removed
*/
+ @Deprecated
public void removeClickListener(RendererClickListener<T> listener) {
removeListener(RendererClickEvent.class, listener);
}
--- /dev/null
+package com.vaadin.server;
+
+import java.lang.reflect.Method;
+import java.util.regex.Pattern;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.vaadin.tests.VaadinClasses;
+
+public class RemoveListenersDeprecatedTest {
+
+ @Test
+ public void allRemoveListenerMethodsMarkedAsDeprecated() {
+ Pattern methodPattern = Pattern.compile("remove.*Listener");
+ for (Class<? extends Object> serverClass : VaadinClasses
+ .getComponents()) {
+ for (Method method : serverClass.getMethods()) {
+ if (methodPattern.matcher(method.getName()).matches()) {
+ Assert.assertNotNull(
+ "Method " + method.getName() + " in class "
+ + serverClass.getSimpleName()
+ + " has not been marked as deprecated.",
+ method.getAnnotation(Deprecated.class));
+ }
+ }
+ }
+ }
+}
import org.easymock.EasyMock;
import org.junit.Assert;
+import com.vaadin.shared.Registration;
import com.vaadin.tests.VaadinClasses;
import com.vaadin.ui.Component;
verifyListeners(c, eventClass);
// Add one listener and verify
- addListener(c, mockListener1, listenerClass);
+ Registration listener1Registration = addListener(c, mockListener1,
+ listenerClass);
verifyListeners(c, eventClass, mockListener1);
// Add another listener and verify
- addListener(c, mockListener2, listenerClass);
+ Registration listener2Registration = addListener(c, mockListener2,
+ listenerClass);
verifyListeners(c, eventClass, mockListener1, mockListener2);
// Ensure we can fetch using parent class also
}
// Remove the first and verify
- removeListener(c, mockListener1, listenerClass);
+ listener1Registration.remove();
verifyListeners(c, eventClass, mockListener2);
// Remove the remaining and verify
- removeListener(c, mockListener2, listenerClass);
+ listener2Registration.remove();
verifyListeners(c, eventClass);
}
- private void removeListener(Object c, Object listener,
+ private Registration addListener(Object c, Object listener1,
Class<?> listenerClass) throws IllegalArgumentException,
IllegalAccessException, InvocationTargetException,
SecurityException, NoSuchMethodException {
- Method method = getRemoveListenerMethod(c.getClass(), listenerClass);
- method.invoke(c, listener);
-
- }
-
- private void addListener(Object c, Object listener1, Class<?> listenerClass)
- throws IllegalArgumentException, IllegalAccessException,
- InvocationTargetException, SecurityException,
- NoSuchMethodException {
Method method = getAddListenerMethod(c.getClass(), listenerClass);
- method.invoke(c, listener1);
+ return (Registration) method.invoke(c, listener1);
}
private Collection<?> getListeners(Object c, Class<?> eventType)
private Method getAddListenerMethod(Class<?> cls, Class<?> listenerClass)
throws SecurityException, NoSuchMethodException {
- return cls.getMethod("add" + listenerClass.getSimpleName(),
- listenerClass);
-
- }
-
- private Method getRemoveListenerMethod(Class<?> cls, Class<?> listenerClass)
- throws SecurityException, NoSuchMethodException {
- return cls.getMethod("remove" + listenerClass.getSimpleName(),
- listenerClass);
-
+ Method addListenerMethod = cls.getMethod(
+ "add" + listenerClass.getSimpleName(), listenerClass);
+ if (addListenerMethod.getReturnType() != Registration.class) {
+ throw new NoSuchMethodException(
+ cls.getSimpleName() + ".add" + listenerClass.getSimpleName()
+ + " has wrong return type, expected Registration");
+ }
+ return addListenerMethod;
}
private void verifyListeners(Object c, Class<?> eventClass,
import org.junit.Before;
import org.junit.Test;
+import com.vaadin.shared.Registration;
import com.vaadin.ui.LegacyWindow;
import com.vaadin.ui.Window;
import com.vaadin.ui.Window.CloseEvent;
EasyMock.replay(cl);
// Add listener and send a close event -> should end up in listener once
- window.addListener(cl);
+ Registration windowCloseListenerRegistration = window
+ .addCloseListener(cl);
sendClose(window);
// Ensure listener was called once
// Remove the listener and send close event -> should not end up in
// listener
- window.removeListener(cl);
+ windowCloseListenerRegistration.remove();
sendClose(window);
// Ensure listener still has been called only once
// Add listener and send a resize event -> should end up in listener
// once
- window.addListener(rl);
+ Registration windowResizeListenerRegistration = window
+ .addResizeListener(rl);
sendResize(window);
// Ensure listener was called once
// Remove the listener and send close event -> should not end up in
// listener
- window.removeListener(rl);
+ windowResizeListenerRegistration.remove();
sendResize(window);
// Ensure listener still has been called only once
import com.vaadin.server.Page;
import com.vaadin.server.Page.UriFragmentChangedEvent;
import com.vaadin.server.VaadinRequest;
+import com.vaadin.shared.Registration;
import com.vaadin.tests.server.navigator.ClassBasedViewProviderTest.TestView;
import com.vaadin.tests.server.navigator.ClassBasedViewProviderTest.TestView2;
import com.vaadin.ui.Component;
}
@Override
- public void addUriFragmentChangedListener(
+ public Registration addUriFragmentChangedListener(
UriFragmentChangedListener listener) {
addUriFragmentCalled = true;
+ return () -> removeUriFragmentCalled = true;
}
@Override
import com.vaadin.navigator.Navigator.UriFragmentManager;
import com.vaadin.server.Page;
import com.vaadin.server.Page.UriFragmentChangedEvent;
+import com.vaadin.shared.Registration;
public class UriFragmentManagerTest {
@Test
public void testListener() {
// create mocks
- IMocksControl control = EasyMock.createControl();
+ IMocksControl control = EasyMock.createNiceControl();
Navigator navigator = control.createMock(Navigator.class);
Page page = control.createMock(Page.class);
UriFragmentManager manager = new UriFragmentManager(page);
manager.setNavigator(navigator);
+ control.resetToNice();
EasyMock.expect(page.getUriFragment()).andReturn("!test");
navigator.navigateTo("test");
}
@Override
- public void addUriFragmentChangedListener(
+ public Registration addUriFragmentChangedListener(
UriFragmentChangedListener listener) {
addUriFragmentCalled = true;
+ return () -> removeUriFragmentCalled = true;
}
@Override
}
Button focus = new Button("focus");
- focus.addListener(new Button.ClickListener() {
+ focus.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
f.focus();
MyClickListener mutualListener = new MyClickListener("mutual1");
addListeners(b1, 1);
- b1.addListener(mutualListener);
- b1.addListener(mutualListener);
- b1.addListener(this);
- b1.addListener(mutualListener);
+ b1.addClickListener(mutualListener);
+ b1.addClickListener(mutualListener);
+ b1.addClickListener(this);
+ b1.addClickListener(mutualListener);
Button.ClickListener b1Listener = addListeners(b1, 3);
- b1.addListener(mutualListener);
- b1.addListener(this);
+ b1.addClickListener(mutualListener);
+ b1.addClickListener(this);
// b1.addListener((ValueChangeListener) this);
- b1.addListener(mutualListener);
- b1.removeListener(b1Listener);
+ b1.addClickListener(mutualListener);
+ b1.removeClickListener(b1Listener);
// remove non-existing listener
- b1.removeListener(new Button.ClickListener() {
+ b1.removeClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
}
Button.ClickListener listener = null;
for (int i = 0; i < count; i++) {
listener = new MyClickListener(name);
- b.addListener(listener);
+ b.addClickListener(listener);
}
// return last listener added
return listener;
-/*
+/*
* Copyright 2000-2016 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
// Main window button
final Button b = new Button("Test Button in main window");
- b.addListener(this);
+ b.addClickListener(this);
b.setTabIndex(2);
main.addComponent(b);
reopen = new Button("Open modal subwindow");
- reopen.addListener(this);
+ reopen.addClickListener(this);
reopen.setTabIndex(3);
main.addComponent(reopen);
// Modal window button
final Button b = new Button("Test Button in modal window");
b.setTabIndex(5);
- b.addListener(this);
+ b.addClickListener(this);
layout.addComponent(b);
}
}
-/*
+/*
* Copyright 2000-2016 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
ol.setId(name.replaceAll(" ", ""));
ol.addComponent(new Label(name));
up = new Button("up");
- up.addListener(new Button.ClickListener() {
+ up.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
int newIndex = order.indexOf(MyComponent.this) - 1;
ol.addComponent(up);
down = new Button("down");
- down.addListener(new Button.ClickListener() {
+ down.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
int newIndex = order.indexOf(MyComponent.this) + 1;
-/*
+/*
* Copyright 2000-2016 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
VerticalLayout lo = new VerticalLayout();
lo.addComponent(menu);
- mainWindow.getPage().addListener(new Page.UriFragmentChangedListener() {
- @Override
- public void uriFragmentChanged(UriFragmentChangedEvent source) {
- String fragment = source.getUriFragment();
- if (fragment != null && !"".equals(fragment)) {
- // try to find a proper test class
-
- // exact match
- Iterator<?> iterator = menu.getItemIds().iterator();
- while (iterator.hasNext()) {
- Object next = iterator.next();
- if (next instanceof Class) {
- Class<?> c = (Class<?>) next;
- String string = c.getName();
- if (string.equals(fragment)) {
- menu.setValue(c);
- mainLayout.setSplitPosition(0);
- return;
+ mainWindow.getPage().addUriFragmentChangedListener(
+ new Page.UriFragmentChangedListener() {
+ @Override
+ public void uriFragmentChanged(
+ UriFragmentChangedEvent source) {
+ String fragment = source.getUriFragment();
+ if (fragment != null && !"".equals(fragment)) {
+ // try to find a proper test class
+
+ // exact match
+ Iterator<?> iterator = menu.getItemIds().iterator();
+ while (iterator.hasNext()) {
+ Object next = iterator.next();
+ if (next instanceof Class) {
+ Class<?> c = (Class<?>) next;
+ String string = c.getName();
+ if (string.equals(fragment)) {
+ menu.setValue(c);
+ mainLayout.setSplitPosition(0);
+ return;
+ }
+ }
}
- }
- }
- // simple name match
- iterator = menu.getItemIds().iterator();
- while (iterator.hasNext()) {
- Object next = iterator.next();
- if (next instanceof Class) {
- Class<?> c = (Class<?>) next;
- String string = c.getSimpleName();
- if (string.equals(fragment)) {
- menu.setValue(c);
- mainLayout.setSplitPosition(0);
- return;
+ // simple name match
+ iterator = menu.getItemIds().iterator();
+ while (iterator.hasNext()) {
+ Object next = iterator.next();
+ if (next instanceof Class) {
+ Class<?> c = (Class<?>) next;
+ String string = c.getSimpleName();
+ if (string.equals(fragment)) {
+ menu.setValue(c);
+ mainLayout.setSplitPosition(0);
+ return;
+ }
+ }
}
- }
- }
- // ticket match
- iterator = menu.getItemIds().iterator();
- while (iterator.hasNext()) {
- Object next = iterator.next();
- if (next instanceof Class) {
- Class<?> c = (Class<?>) next;
- String string = c.getSimpleName();
- if (string.startsWith("Ticket" + fragment)) {
- menu.setValue(c);
- mainLayout.setSplitPosition(0);
- return;
+ // ticket match
+ iterator = menu.getItemIds().iterator();
+ while (iterator.hasNext()) {
+ Object next = iterator.next();
+ if (next instanceof Class) {
+ Class<?> c = (Class<?>) next;
+ String string = c.getSimpleName();
+ if (string
+ .startsWith("Ticket" + fragment)) {
+ menu.setValue(c);
+ mainLayout.setSplitPosition(0);
+ return;
+ }
+ }
}
- }
- }
- // just partly mach lowercase
- iterator = menu.getItemIds().iterator();
- while (iterator.hasNext()) {
- Object next = iterator.next();
- if (next instanceof Class) {
- Class<?> c = (Class<?>) next;
- String string = c.getSimpleName();
- if (string.toLowerCase()
- .contains(fragment.toLowerCase())) {
- menu.setValue(c);
- mainLayout.setSplitPosition(0);
- return;
+ // just partly mach lowercase
+ iterator = menu.getItemIds().iterator();
+ while (iterator.hasNext()) {
+ Object next = iterator.next();
+ if (next instanceof Class) {
+ Class<?> c = (Class<?>) next;
+ String string = c.getSimpleName();
+ if (string.toLowerCase()
+ .contains(fragment.toLowerCase())) {
+ menu.setValue(c);
+ mainLayout.setSplitPosition(0);
+ return;
+ }
+ }
}
- }
- }
- getMainWindow().showNotification(
- "No potential matc for #" + fragment);
+ getMainWindow().showNotification(
+ "No potential matc for #" + fragment);
- }
+ }
- }
- });
+ }
+ });
mainLayout.addComponent(lo);
-/*
+/*
* Copyright 2000-2016 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
df.setIcon(res);
super.attach();
}
-
}
-/*
+/*
* Copyright 2000-2016 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
t.setContainerDataSource(ic);
// Handler
- filterButton.addListener(new Button.ClickListener() {
+ filterButton.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
ic.removeAllContainerFilters();
-/*
+/*
* Copyright 2000-2016 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
import com.vaadin.ui.Upload.FailedEvent;
import com.vaadin.ui.Upload.FailedListener;
import com.vaadin.ui.Upload.FinishedEvent;
-import com.vaadin.ui.Upload.FinishedListener;
import com.vaadin.ui.Upload.StartedEvent;
import com.vaadin.ui.Upload.StartedListener;
import com.vaadin.ui.Upload.SucceededEvent;
up = new Upload(null, buffer);
up.setButtonCaption("Select file");
up.setImmediate(true);
- up.addListener((FinishedListener) this);
- up.addListener((FailedListener) this);
- up.addListener((SucceededListener) this);
- up.addListener((StartedListener) this);
+ up.addFinishedListener(this);
+ up.addFailedListener(this);
+ up.addSucceededListener(this);
+ up.addStartedListener(this);
- up.addListener(new Upload.ProgressListener() {
+ up.addProgressListener(new Upload.ProgressListener() {
@Override
public void updateProgress(long readBytes, long contentLenght) {
main.addComponent(status);
Button cancel = new Button("Cancel current upload");
- cancel.addListener(new Button.ClickListener() {
+ cancel.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
buffer.cancel();
main.addComponent(cancel);
final Button restart = new Button("Restart demo application");
- restart.addListener(new Button.ClickListener() {
+ restart.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
TestForTabSheet() {
setCompositionRoot(tabsheet);
- tabsheet.addListener(this);
+ tabsheet.addSelectedTabChangeListener(this);
/* Listen for button click events. */
- tab1_root.addListener(this);
+ tab1_root.addClickListener(this);
tabsheet.addTab(tab1_root, "First Tab", null);
/* A tab that is initially disabled. */
-/*
+/*
* Copyright 2000-2016 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
}
});
- up.addListener(new StartedListener() {
+ up.addStartedListener(new StartedListener() {
private static final long serialVersionUID = 5508883803861085154L;
@Override
}
});
- up.addListener(new Upload.FinishedListener() {
+ up.addFinishedListener(new Upload.FinishedListener() {
private static final long serialVersionUID = -3773034195991947371L;
@Override
}
});
- up.addListener(new Upload.ProgressListener() {
+ up.addProgressListener(new Upload.ProgressListener() {
@Override
public void updateProgress(long readBytes, long contentLenght) {
main.addComponent(beSluggish);
main.addComponent(throwExecption);
main.addComponent(interrupt);
- interrupt.addListener(new Button.ClickListener() {
+ interrupt.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
up.interruptUpload();
main.addComponent(status);
final Button restart = new Button("R");
- restart.addListener(new Button.ClickListener() {
+ restart.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
-/*
+/*
* Copyright 2000-2016 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
selectPanel(selectedPanel);
- buttonNextPanel.addListener(new ClickListener() {
+ buttonNextPanel.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
selectedPanel++;
-/*
+/*
* Copyright 2000-2016 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
select.setWidth("400px");
prev = new Button("<<-|");
- prev.addListener(new Button.ClickListener() {
+ prev.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
Object cur = select.getValue();
}
});
next = new Button("|->>");
- next.addListener(new Button.ClickListener() {
+ next.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
Object cur = select.getValue();
formLayout.addComponent(login);
mainWindow.setContent(formLayout);
- login.addListener(new ClickListener() {
+ login.addClickListener(new ClickListener() {
@Override
public void buttonClick(final ClickEvent event) {
String username = userField.getValue();
title.addStyleName("header-title");
header.addComponent(title);
Button logout = new Button("Logout");
- logout.addListener(new ClickListener() {
+ logout.addClickListener(new ClickListener() {
@Override
public void buttonClick(final ClickEvent event) {
user = null;
import com.vaadin.ui.AbstractComponentContainer;
import com.vaadin.ui.Button;
import com.vaadin.ui.Component;
-import com.vaadin.ui.HasComponents.ComponentAttachEvent;
+import com.vaadin.ui.DateField;
import com.vaadin.ui.HasComponents.ComponentAttachListener;
-import com.vaadin.ui.HasComponents.ComponentDetachEvent;
import com.vaadin.ui.HasComponents.ComponentDetachListener;
import com.vaadin.ui.HorizontalSplitPanel;
import com.vaadin.ui.InlineDateField;
import com.vaadin.ui.NativeButton;
-import com.vaadin.ui.DateField;
+import com.vaadin.ui.RichTextArea;
import com.vaadin.ui.TabSheet;
import com.vaadin.ui.VerticalSplitPanel;
-import com.vaadin.ui.RichTextArea;
import com.vaadin.v7.ui.Table;
import com.vaadin.v7.ui.TextArea;
import com.vaadin.v7.ui.TextField;
@Override
public void execute(T c, Boolean value, Object data) {
if (value) {
- c.addListener(
- (ComponentAttachListener) AbstractComponentContainerTest.this);
+ c.addComponentAttachListener(
+ AbstractComponentContainerTest.this);
} else {
- c.removeListener(
- (ComponentAttachListener) AbstractComponentContainerTest.this);
+ c.removeComponentAttachListener(
+ AbstractComponentContainerTest.this);
}
}
};
@Override
public void execute(T c, Boolean value, Object data) {
if (value) {
- c.addListener(
- (ComponentDetachListener) AbstractComponentContainerTest.this);
+ c.addComponentDetachListener(
+ AbstractComponentContainerTest.this);
} else {
- c.removeListener(
- (ComponentDetachListener) AbstractComponentContainerTest.this);
+ c.removeComponentDetachListener(
+ AbstractComponentContainerTest.this);
}
}
};
@Override
public void execute(T c, Boolean value, Object data) {
if (value) {
- c.addListener(
- (LayoutClickListener) AbstractOrderedLayoutTest.this);
+ c.addLayoutClickListener(AbstractOrderedLayoutTest.this);
} else {
}
import com.vaadin.ui.Label;
import com.vaadin.ui.Layout;
import com.vaadin.ui.NativeButton;
+import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.v7.ui.OptionGroup;
-import com.vaadin.v7.ui.TextField;
public class FocusAndBlurListeners extends TestBase {
Label msg = new Label(new Date() + " Blurred "
+ event.getComponent().getCaption());
messages.addComponentAsFirst(msg);
-
}
};
private VerticalLayout messages = new VerticalLayout();
ogm.setMultiSelect(true);
l.addComponent(ogm);
- btn.addListener(new ClickListener() {
+ btn.addClickListener(new ClickListener() {
private int i;
final Table table = new Table();
Button button = new Button("Toggle lazyloading");
- button.addListener(new Button.ClickListener() {
+ button.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
if (table.getCacheRate() == 100) {
cssLayout.addComponent(button);
button = new Button("Toggle selectable");
- button.addListener(new Button.ClickListener() {
+ button.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
table.setSelectable(!table.isSelectable());
@Override
protected void setup() {
Button b = new Button("Click for error");
- b.addListener(new ClickListener() {
+ b.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
throw new NullPointerException();
addComponent(b);
final Button swapButton = new Button("<i>Swap button<i>");
- swapButton.addListener(new Button.ClickListener() {
+ swapButton.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
final VerticalLayout layout = new VerticalLayout();
Button offset = new Button("Drag me");
- offset.addListener(new ClickListener() {
+ offset.addClickListener(new ClickListener() {
@Override
public void buttonClick(com.vaadin.ui.Button.ClickEvent event) {
Notification.show("Button clicked!");
@Override
public void execute(T c, Boolean value, Object data) {
if (value) {
- c.addListener((Button.ClickListener) Buttons2.this);
+ c.addClickListener(Buttons2.this);
} else {
- c.removeListener((Button.ClickListener) Buttons2.this);
+ c.removeClickListener(Buttons2.this);
}
}
Button button1 = new Button("b1 (CTRL-C)");
Button button2 = new Button("b2 (CTRL-V)");
- button1.addListener(this);
- button2.addListener(this);
+ button1.addClickListener(this);
+ button2.addClickListener(this);
button1.setClickShortcut(KeyCode.C, ModifierKey.CTRL);
button2.setClickShortcut(KeyCode.V, ModifierKey.CTRL);
buttonEnabled.setDescription("Tooltip for enabled");
buttonDisabled.setDescription("Tooltip for disabled");
- buttonDisabled.addListener(new Button.ClickListener() {
+ buttonDisabled.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
});
- buttonEnabled.addListener(new Button.ClickListener() {
+ buttonEnabled.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
Button aButton = new Button("Show Value");
aButton.setClickShortcut(KeyCode.ENTER);
- aButton.addListener(new Button.ClickListener() {
+ aButton.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
state.addComponent(t);
Button b = new Button("Use ds1");
- b.addListener(new Button.ClickListener() {
+ b.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
state.addComponent(t);
b = new Button("Use ds2");
- b.addListener(new Button.ClickListener() {
+ b.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
final ComboBox cb2 = new ComboBox();
cb2.setWidth("260px");
PopupView pv2 = new PopupView("<u>2. focused (click)</u>", cb2);
- pv2.addListener(new PopupVisibilityListener() {
+ pv2.addPopupVisibilityListener(new PopupVisibilityListener() {
@Override
public void popupVisibilityChange(PopupVisibilityEvent event) {
}
Button fill = new Button("fill it");
- fill.addListener(new Button.ClickListener() {
+ fill.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
t.removeAllItems();
Button btClear = new Button("Clear button");
btClear.setImmediate(true);
- btClear.addListener(new Button.ClickListener() {
+ btClear.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
cc.setWidth("500px");
cc.setHeight("500px");
- nb.addListener(new ClickListener() {
+ nb.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
checkEmpty();
Button b = new Button("Clear date");
b.setId("clear");
- b.addListener(new ClickListener() {
+ b.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
b = new Button("Set date to 4.5.1990");
b.setId("set4.5.1990");
- b.addListener(new ClickListener() {
+ b.addClickListener(new ClickListener() {
@Override
@SuppressWarnings("deprecation")
addComponent(b);
b = new Button("Set date to 5.6.2000 using a property data source");
- b.addListener(new ClickListener() {
+ b.addClickListener(new ClickListener() {
@Override
@SuppressWarnings("deprecation")
b = new Button(
"Set date to 27.8.2005 by changing a new property data source from null, ds attached before value setting.");
b.setId("set-via-ds");
- b.addListener(new ClickListener() {
+ b.addClickListener(new ClickListener() {
@Override
@SuppressWarnings("deprecation")
b = new Button("Check value");
b.setId("check-value");
- b.addListener(new ClickListener() {
+ b.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
log.log("Checking state");
addComponent(timeField);
Button b = new Button("Switch read-only");
- b.addListener(new ClickListener() {
+ b.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
xLabel.setId("x");
final Label yLabel = new Label();
yLabel.setId("y");
- e.addListener(new ClickListener() {
+ e.addClickListener(new ClickListener() {
@Override
public void click(ClickEvent event) {
// The button requests repainting the embedded.
Button button = new Button("refr");
- button.addListener(new Button.ClickListener() {
+ button.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
embedded.markAsDirty();
});
addComponent(button);
button = new Button("refr name");
- button.addListener(new Button.ClickListener() {
+ button.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
((StreamResource) embedded.getSource())
});
addComponent(button);
button = new Button("200x200");
- button.addListener(new Button.ClickListener() {
+ button.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
embedded.setWidth("200px");
});
addComponent(button);
button = new Button("undef");
- button.addListener(new Button.ClickListener() {
+ button.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
embedded.setSizeUndefined();
final GridLayout layout = new GridLayout(1, 2);
layout.addComponent(new Label("some row"), 0, 0);
Button newRowButton = new Button("Insert Row");
- newRowButton.addListener(new Button.ClickListener() {
+ newRowButton.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
layout.insertRow(1);
final Label longLabel = new Label(longString);
Button changeLength = new Button("Change length");
- changeLength.addListener(new Button.ClickListener() {
+ changeLength.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
if (longLabel.getValue().equals(longString)) {
addComponent(b);
final NativeButton swapButton = new NativeButton("<i>Swap button<i>");
- swapButton.addListener(new Button.ClickListener() {
+ swapButton.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
Notification.TYPE_WARNING_MESSAGE);
Button b = new Button("Button");
- b.addListener(new Button.ClickListener() {
+ b.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
Window w = new Window("This is a window");
l.addComponent(label);
l.addComponent(new Button("Component 2"));
- l.addListener(new LayoutClickListener() {
+ l.addLayoutClickListener(new LayoutClickListener() {
@Override
public void layoutClick(LayoutClickEvent event) {
if (event.getChildComponent() == null
layout.addComponent(nestedLayout);
// Listen for layout click events
- layout.addListener(new LayoutClickListener() {
+ layout.addLayoutClickListener(new LayoutClickListener() {
@Override
public void layoutClick(LayoutClickEvent event) {
outer.setMargin(true);
Button changer = new Button("ReplaceComponent");
- changer.addListener(new Button.ClickListener() {
+ changer.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
getLayout().replaceComponent(button, outer);
VerticalLayout panelLayout = new VerticalLayout();
panelLayout.setMargin(true);
Panel panel = new Panel("Panel's caption", panelLayout);
- panel.addListener(new ClickListener() {
+ panel.addClickListener(new ClickListener() {
@Override
public void click(ClickEvent event) {
p.setHeight("600px");
pl.addComponent(foo());
addMore = new Button("Add");
- addMore.addListener(new ClickListener() {
+ addMore.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
pl.removeComponent(addMore);
populate(comboBox);
Button b = new Button("add item (^N)");
- b.addListener(new ClickListener() {
+ b.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
addItem(comboBox);
package com.vaadin.tests.components.splitpanel;
import com.vaadin.server.Sizeable;
-import com.vaadin.server.Sizeable.Unit;
import com.vaadin.tests.components.AbstractComponentContainerTest;
import com.vaadin.ui.AbstractSplitPanel;
import com.vaadin.ui.AbstractSplitPanel.SplitterClickEvent;
@Override
public void execute(T c, Boolean value, Object data) {
if (value) {
- c.addListener(
- (SplitterClickListener) AbstractSplitPanelTest.this);
+ c.addSplitterClickListener(AbstractSplitPanelTest.this);
} else {
- c.removeListener(
- (SplitterClickListener) AbstractSplitPanelTest.this);
+ c.removeSplitterClickListener(AbstractSplitPanelTest.this);
}
}
private Button createButton(String height) {
Button b = new NativeButton("A BIG button");
b.setHeight(height);
- b.addListener(this);
+ b.addClickListener(this);
return b;
}
hsplit.setSizeFull();
hsplit.setImmediate(true);
hsplit.setSplitPosition(100, Sizeable.UNITS_PIXELS, hsplitReversed);
- hsplit.addListener(new HorizontalSplitPanel.SplitterClickListener() {
- @Override
- public void splitterClick(SplitterClickEvent event) {
- getMainWindow().showNotification("Horizontal Splitter Clicked");
- }
- });
+ hsplit.addSplitterClickListener(
+ new HorizontalSplitPanel.SplitterClickListener() {
+ @Override
+ public void splitterClick(SplitterClickEvent event) {
+ getMainWindow().showNotification(
+ "Horizontal Splitter Clicked");
+ }
+ });
TextArea area = new TextArea("");
area.setSizeFull();
vsplit.setSizeFull();
vsplit.setImmediate(true);
vsplit.setSplitPosition(10, Sizeable.UNITS_PERCENTAGE, vsplitReversed);
- vsplit.addListener(new SplitterClickListener() {
+ vsplit.addSplitterClickListener(new SplitterClickListener() {
@Override
public void splitterClick(SplitterClickEvent event) {
getMainWindow().showNotification("Vertical Splitter Clicked");
}
Button addrowButton = new Button("Add row");
- addrowButton.addListener(new ClickListener() {
+ addrowButton.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent pEvent) {
addRow();
public TableTestComponent() {
Button switchContainerButton = new Button("switch container");
- switchContainerButton.addListener(new ClickListener() {
+ switchContainerButton.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
if (testTable.getContainerDataSource() == containerA) {
this.addComponent(switchContainerButton);
Button clearButton = new Button("clear (click twice)");
- clearButton.addListener(new ClickListener() {
+ clearButton.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
try {
addComponent(table);
Button showButton = new Button("Show selection");
- showButton.addListener(new Button.ClickListener() {
+ showButton.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(Button.ClickEvent clickEvent) {
Collection<?> selection = (Collection<?>) table.getValue();
addComponent(showButton);
Button removeButton = new Button("Remove selection");
- removeButton.addListener(new Button.ClickListener() {
+ removeButton.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(Button.ClickEvent clickEvent) {
Collection<?> selection = (Collection<?>) table.getValue();
mainLayout.addComponent(firstLayout);
mainLayout.setExpandRatio(firstLayout, 1);
- first.addListener(new Button.ClickListener() {
+ first.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
}
}
});
- second.addListener(new Button.ClickListener() {
+ second.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
}
Button addrowButton = new Button("Add row");
- addrowButton.addListener(new ClickListener() {
+ addrowButton.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent pEvent) {
Object id = addRow();
VerticalLayout layout = new VerticalLayout();
layout.addComponent(new TextField());
- layout.addListener(new LayoutClickListener() {
+ layout.addLayoutClickListener(new LayoutClickListener() {
@Override
public void layoutClick(LayoutClickEvent event) {
}
t.addItem(row).getItemProperty("name").setValue("Row" + row);
- btn.addListener(new ClickListener() {
+ btn.addClickListener(new ClickListener() {
Integer row = 2;
@Override
final Label label = new Label();
addComponent(label);
Button button = new Button("Click");
- button.addListener(new Button.ClickListener() {
+ button.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
try {
});
addComponent(button);
Button button2 = new Button("Filter");
- button2.addListener(new Button.ClickListener() {
+ button2.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
try {
setCaption("- " + table.getCaption());
- addListener(new ClickListener() {
+ addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
getLayout().addComponent(tabsheet);
closeCurrent = new Button("Close current tab");
- closeCurrent.addListener(new Button.ClickListener() {
+ closeCurrent.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
closeCurrentTab();
});
closeCurrentWithTab = new Button("Close current tab with Tab");
- closeCurrentWithTab.addListener(new Button.ClickListener() {
+ closeCurrentWithTab.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
closeCurrentTabWithTab();
});
closeFirst = new Button("close first tab");
- closeFirst.addListener(new Button.ClickListener() {
+ closeFirst.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
closeFirstTab();
});
closeLast = new Button("close last tab");
- closeLast.addListener(new Button.ClickListener() {
+ closeLast.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
closeLastTab();
});
reorderTabs = new Button("reorder");
- reorderTabs.addListener(new Button.ClickListener() {
+ reorderTabs.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
reorder();
@Override
public void execute(T c, Boolean value, Object data) {
if (value) {
- c.addListener((SelectedTabChangeListener) TabSheetTest.this);
+ c.addSelectedTabChangeListener(TabSheetTest.this);
} else {
- c.removeListener((SelectedTabChangeListener) TabSheetTest.this);
+ c.removeSelectedTabChangeListener(TabSheetTest.this);
}
}
layout.addComponent(tabSheet);
Button btn = new Button("Enable and activate tab");
- btn.addListener(this);
+ btn.addClickListener(this);
layout.addComponent(btn);
return layout;
}
+ "ds\n" + "fds\n" + "fds\nfs");
addComponent(textArea);
Button button = new Button("Scroll");
- button.addListener(new ClickListener() {
+ button.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
}
});
Button wrap = new Button("Set wrap");
- wrap.addListener(new ClickListener() {
+ wrap.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
});
Button toBegin = new Button("To begin");
- toBegin.addListener(new ClickListener() {
+ toBegin.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
});
Button toMiddle = new Button("To middle");
- toMiddle.addListener(new ClickListener() {
+ toMiddle.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
});
Button toEnd = new Button("To end");
- toEnd.addListener(new ClickListener() {
+ toEnd.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
Button b = new Button(
"Set BAR to underlaying property (should propagate to UI)");
- b.addListener(new ClickListener() {
+ b.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
op.setValue("BAR");
Button b = new Button(
"Sync (typing 12345.6789 and clicking this should format field)");
- b.addListener(new ClickListener() {
+ b.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
}
});
addComponent(b);
b = new Button("Set '12345.6789' to textfield on the server side");
- b.addListener(new ClickListener() {
+ b.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
tf1.setValue("12345.6789");
state.addComponent(t);
Button b = new Button("Use ds1");
- b.addListener(new Button.ClickListener() {
+ b.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
state.addComponent(t);
b = new Button("Use ds2");
- b.addListener(new Button.ClickListener() {
+ b.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
setupContainer(tt, 20);
addComponent(tt);
Button page1 = new Button("Set new data source (20 items)");
- page1.addListener(new Button.ClickListener() {
+ page1.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
setupContainer(tt, 20);
}
});
Button page2 = new Button("Set new data source (10 items)");
- page2.addListener(new Button.ClickListener() {
+ page2.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
setupContainer(tt, 10);
}
});
Button addButton = new Button("Add item");
- addButton.addListener(new Button.ClickListener() {
+ addButton.addClickListener(new Button.ClickListener() {
private int i = 1;
@Override
-/*
+/*
* Copyright 2000-2016 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
addComponent(treeLayout);
Button cleanUp = new Button("clear");
- cleanUp.addListener(new ClickListener() {
+ cleanUp.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
treeContainer.removeAllItems();
addComponent(cleanUp);
Button refresh = new Button("fill");
- refresh.addListener(new ClickListener() {
+ refresh.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
fill();
Button refresh = new Button("Add two elements");
addComponent(refresh);
- refresh.addListener(new ClickListener() {
+ refresh.addClickListener(new ClickListener() {
public void buttonClick(ClickEvent event) {
addTwoElements();
}
Button reset = new Button("Reset");
addComponent(reset);
- reset.addListener(new ClickListener() {
+ reset.addClickListener(new ClickListener() {
public void buttonClick(ClickEvent event) {
container.removeAllItems();
}
Button refresh5 = new Button("Add five elements");
addComponent(refresh5);
- refresh5.addListener(new ClickListener() {
+ refresh5.addClickListener(new ClickListener() {
public void buttonClick(ClickEvent event) {
container.addBean(new User("John", "Doe"));
container.addBean(new User("Mark", "Twain"));
fragmentLabel.setId("fragmentLabel");
addComponent(fragmentLabel);
updateLabel();
- getPage().addListener(new Page.UriFragmentChangedListener() {
- @Override
- public void uriFragmentChanged(UriFragmentChangedEvent event) {
- updateLabel();
- }
- });
+ getPage().addUriFragmentChangedListener(
+ new Page.UriFragmentChangedListener() {
+ @Override
+ public void uriFragmentChanged(
+ UriFragmentChangedEvent event) {
+ updateLabel();
+ }
+ });
addComponent(createButton("test", "Navigate to #test", "test"));
addComponent(createButton("empty", "Navigate to #", ""));
addComponent(u);
- u.addListener(new Upload.FinishedListener() {
+ u.addFinishedListener(new Upload.FinishedListener() {
@Override
public void uploadFinished(FinishedEvent event) {
String filename = event.getFilename();
}
});
- u.addListener(new Upload.FailedListener() {
+ u.addFailedListener(new Upload.FailedListener() {
@Override
public void uploadFailed(FailedEvent event) {
getMainWindow().showNotification("Failed. No file selected?");
}
});
- u.addListener(new Upload.StartedListener() {
+ u.addStartedListener(new Upload.StartedListener() {
@Override
public void uploadStarted(StartedEvent event) {
getMainWindow().showNotification(
Button button = new Button(
"I'm an external button (not the uploads builtin), hit me to start upload.");
- button.addListener(new ClickListener() {
+ button.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
u.submitUpload();
addComponent(upload);
addComponent(result);
- upload.addListener(new Upload.FinishedListener() {
+ upload.addFinishedListener(new Upload.FinishedListener() {
@Override
public void uploadFinished(FinishedEvent event) {
result.setValue("Got file (should not contain path): "
log(this);
}
};
- okButton.addListener(new ClickListener() {
+ okButton.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
private Button createScriptButton(final String script) {
Button b = new Button(script);
- b.addListener(new Button.ClickListener() {
+ b.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
resizeListenerCheckBox.setImmediate(true);
resizeListenerCheckBox.addValueChangeListener(event -> {
if (resizeListenerCheckBox.getValue()) {
- subWindow.addListener(resizeListener);
+ subWindow.addResizeListener(resizeListener);
mainWindow.addListener(browserWindowResizeListener);
} else {
- subWindow.removeListener(resizeListener);
+ subWindow.removeResizeListener(resizeListener);
mainWindow.removeListener(browserWindowResizeListener);
}
});
addComponent(winSel);
addComponent(bf);
addComponent(toggleModality);
- bf.addListener(this);
- toggleModality.addListener(this);
+ bf.addClickListener(this);
+ toggleModality.addClickListener(this);
}
@Override
final TabSheet tabsheet = new TabSheet();
tabsheet.addComponent(tabButton);
tabsheet.addComponent(table);
- tabsheet.addListener(new TabSheet.SelectedTabChangeListener() {
- @Override
- public void selectedTabChange(
- TabSheet.SelectedTabChangeEvent event) {
- if (tabsheet.getSelectedTab() == tabButton) {
- tabsheet.setSizeUndefined();
- layout.setSizeUndefined();
- subwindow.setSizeUndefined();
- } else if (tabsheet.getSelectedTab() == table) {
- subwindow.setWidth("500px");
- subwindow.setHeight("500px");
- layout.setSizeFull();
- tabsheet.setSizeFull();
- }
- }
- });
+ tabsheet.addSelectedTabChangeListener(
+ new TabSheet.SelectedTabChangeListener() {
+ @Override
+ public void selectedTabChange(
+ TabSheet.SelectedTabChangeEvent event) {
+ if (tabsheet.getSelectedTab() == tabButton) {
+ tabsheet.setSizeUndefined();
+ layout.setSizeUndefined();
+ subwindow.setSizeUndefined();
+ } else if (tabsheet.getSelectedTab() == table) {
+ subwindow.setWidth("500px");
+ subwindow.setHeight("500px");
+ layout.setSizeFull();
+ tabsheet.setSizeFull();
+ }
+ }
+ });
layout.addComponent(tabsheet);
Button button = new Button("click me", new Button.ClickListener() {
private Component createRemoveButton() {
Button b = new Button("Remove");
- b.addListener(new ClickListener() {
+ b.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
@Override
protected void setup() {
VerticalLayout layout = new VerticalLayout();
- layout.addListener(new LayoutClickListener() {
+ layout.addLayoutClickListener(new LayoutClickListener() {
@Override
public void layoutClick(LayoutClickEvent event) {
WindowClickEvents.this.click("Sub window layout", event);
});
((VerticalLayout) getMainWindow().getContent())
- .addListener(new LayoutClickListener() {
+ .addLayoutClickListener(new LayoutClickListener() {
@Override
public void layoutClick(LayoutClickEvent event) {
WindowClickEvents.this.click("Main window layout",
});
layout.setMargin(true);
Window centered = new Window("A window with a click listener", layout);
- centered.addListener(new ClickListener() {
+ centered.addClickListener(new ClickListener() {
@Override
public void click(ClickEvent event) {
l.setSizeUndefined();
Button b = new Button(
"Clicking here should not produce a layout click event");
- b.addListener(new Button.ClickListener() {
+ b.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(com.vaadin.ui.Button.ClickEvent event) {
getMainWindow().addWindow(centered);
log = new Log(5);
addComponent(log);
- getMainWindow().addListener(new ClickListener() {
+ getMainWindow().addClickListener(new ClickListener() {
@Override
public void click(ClickEvent event) {
hl.addComponent(new Label("Current size: "));
hl.addComponent(sizeLabel);
- addListener(new ResizeListener() {
+ addResizeListener(new ResizeListener() {
@Override
public void windowResized(ResizeEvent e) {
updateLabel();
table.setPageLength(50);
final Button up = new Button("up");
- up.addListener(new Button.ClickListener() {
+ up.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
public void init() {
setMainWindow(new LegacyWindow("SQLContainer Test", buildLayout()));
- process.addListener(new Button.ClickListener() {
+ process.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
MassInsert mi = new MassInsert();
l.addComponent(new Embedded(null, icon2));
l.addComponent(new Label(name));
- l.addListener(new LayoutClickListener() {
+ l.addLayoutClickListener(new LayoutClickListener() {
@Override
@SuppressWarnings("static-access")
public void layoutClick(LayoutClickEvent event) {
protected Button getCommitButton() {
if (commitButton == null) {
commitButton = new Button("Commit");
- commitButton.addListener(new ClickListener() {
+ commitButton.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
private Component addCaptionText() {
Button b = new Button("Add caption text");
- b.addListener(new ClickListener() {
+ b.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
private Component addCaptionText() {
Button b = new Button("Add caption text");
- b.addListener(new ClickListener() {
+ b.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
gl.addComponent(b2, 0, 2);
b1.setWidth(270, Sizeable.UNITS_PIXELS);
b2.setWidth(270, Sizeable.UNITS_PIXELS);
- b1.addListener(new Button.ClickListener() {
+ b1.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(Button.ClickEvent event) {
cols++;
mainLayout.setExpandRatio(gl, 100);
Button restart = new Button("restart");
mainLayout.addComponent(restart);
- restart.addListener(new Button.ClickListener() {
+ restart.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(Button.ClickEvent event) {
close();
private Button createButton(String string) {
NativeButton button = new NativeButton(string);
css.put(button, string);
- button.addListener(this);
+ button.addClickListener(this);
return button;
}
sp.addComponent(cssLayout);
Button button = new Button("b");
- button.addListener(new ClickListener() {
+ button.addClickListener(new ClickListener() {
boolean bool = true;
@Override
root.setWidth("600px");
root.setHeight("200px");
final Button b = new Button("Go try your luck with " + i + " layouts!");
- b.addListener(new Button.ClickListener() {
+ b.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
lo.addComponent(b);
lo.addComponent(b2);
- b.addListener(new Button.ClickListener() {
+ b.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(Button.ClickEvent event) {
});
- b2.addListener(new Button.ClickListener() {
+ b2.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
"A visible text field");
tfHidden.setVisible(false);
Button b = new Button("Move hidden textfield to other layout");
- b.addListener(new ClickListener() {
+ b.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
Button b = new Button("Render component");
- b.addListener(new Button.ClickListener() {
+ b.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
Button b = new Button(
"Click to set bar visible. Button should stay visible.");
- b.addListener(new ClickListener() {
+ b.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
-/*
+/*
* Copyright 2000-2016 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
layout.addComponent(label);
// React to fragment changes
- getPage().addListener(new UriFragmentChangedListener() {
- @Override
- public void uriFragmentChanged(UriFragmentChangedEvent source) {
- handleFragment(source.getUriFragment());
- }
- });
+ getPage().addUriFragmentChangedListener(
+ new UriFragmentChangedListener() {
+ @Override
+ public void uriFragmentChanged(
+ UriFragmentChangedEvent source) {
+ handleFragment(source.getUriFragment());
+ }
+ });
// Handle the fragment received in the initial request
handleFragment(getPage().getUriFragment());
private Button createButton(final String filename) {
Button b = new Button("Download " + filename);
- b.addListener(new Button.ClickListener() {
+ b.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {