From 862270140d287aba33dce03dc963db4421ebeb1a Mon Sep 17 00:00:00 2001 From: Denis Anisimov Date: Thu, 20 Oct 2016 11:12:58 +0300 Subject: [PATCH] Update ValueChange API to use Component and HasValue<>. Change-Id: I785aa82d925cadee42cc1b17d345a8923f6dc8cc --- .../src/main/java/com/vaadin/v7/ui/Field.java | 4 +- .../main/java/com/vaadin/data/HasValue.java | 81 ++++++++++++------- .../event/selection/MultiSelectionEvent.java | 23 +++--- .../selection/MultiSelectionListener.java | 5 +- ...e.java => SingleSelectionChangeEvent.java} | 21 +++-- .../selection/SingleSelectionListener.java | 11 +-- .../java/com/vaadin/ui/AbstractDateField.java | 2 +- .../java/com/vaadin/ui/AbstractField.java | 12 +-- .../com/vaadin/ui/AbstractMultiSelect.java | 9 +-- .../com/vaadin/ui/AbstractSingleSelect.java | 23 +++--- .../src/main/java/com/vaadin/ui/ComboBox.java | 8 +- .../com/vaadin/ui/HasValueChangeMode.java | 12 +-- .../colorpicker/ColorPickerGrid.java | 3 +- .../colorpicker/ColorPickerHistory.java | 2 +- .../colorpicker/ColorPickerPopup.java | 10 +-- .../colorpicker/ColorPickerPreview.java | 11 ++- .../colorpicker/ColorPickerSelect.java | 2 +- .../event/selection/SelectionEventTest.java | 3 +- .../java/com/vaadin/ui/AbstractFieldTest.java | 8 +- .../vaadin/ui/AbstractMultiSelectTest.java | 19 +++-- .../vaadin/ui/AbstractSingleSelectTest.java | 17 ++-- .../com/vaadin/ui/RadioButtonGroupTest.java | 18 ++--- .../abstractfield/AbstractFieldTest.java | 6 +- .../colorpicker/ColorPickerTestUI.java | 4 +- .../datefield/CustomDateFormats.java | 2 +- .../components/datefield/LenientMode.java | 4 +- .../HeaderFooterClickLeftRightMiddle.java | 6 +- .../textfield/TextFieldsValueChangeMode.java | 6 +- 28 files changed, 182 insertions(+), 150 deletions(-) rename server/src/main/java/com/vaadin/event/selection/{SingleSelectionChange.java => SingleSelectionChangeEvent.java} (73%) diff --git a/compatibility-server/src/main/java/com/vaadin/v7/ui/Field.java b/compatibility-server/src/main/java/com/vaadin/v7/ui/Field.java index 79c685c71b..d98153da29 100644 --- a/compatibility-server/src/main/java/com/vaadin/v7/ui/Field.java +++ b/compatibility-server/src/main/java/com/vaadin/v7/ui/Field.java @@ -17,7 +17,7 @@ package com.vaadin.v7.ui; import com.vaadin.data.HasRequired; -import com.vaadin.data.HasValue.ValueChange; +import com.vaadin.data.HasValue.ValueChangeEvent; import com.vaadin.ui.Component; import com.vaadin.ui.Component.Focusable; import com.vaadin.v7.data.BufferedValidatable; @@ -96,7 +96,7 @@ public interface Field extends Component, BufferedValidatable, Property, * @author Vaadin Ltd. * @since 3.0 * - * @deprecated As of 8.0, replaced by {@link ValueChange}. + * @deprecated As of 8.0, replaced by {@link ValueChangeEvent}. */ @Deprecated @SuppressWarnings("serial") diff --git a/server/src/main/java/com/vaadin/data/HasValue.java b/server/src/main/java/com/vaadin/data/HasValue.java index 0ad3203b78..7a8bc7c296 100644 --- a/server/src/main/java/com/vaadin/data/HasValue.java +++ b/server/src/main/java/com/vaadin/data/HasValue.java @@ -17,14 +17,13 @@ package com.vaadin.data; import java.io.Serializable; import java.lang.reflect.Method; +import java.util.EventObject; import java.util.Objects; import java.util.function.BiConsumer; -import java.util.function.Function; +import java.util.function.Consumer; -import com.vaadin.event.ConnectorEvent; -import com.vaadin.event.EventListener; -import com.vaadin.server.ClientConnector; import com.vaadin.shared.Registration; +import com.vaadin.ui.Component; import com.vaadin.util.ReflectTools; /** @@ -47,54 +46,60 @@ public interface HasValue extends Serializable { * @param * the value type */ - public class ValueChange extends ConnectorEvent { + public class ValueChangeEvent extends EventObject { - private final V value; private final boolean userOriginated; + private final Component component; /** * Creates a new {@code ValueChange} event containing the current value - * of the given value-bearing source connector. + * of the given value-bearing source component. * - * @param - * the type of the source connector - * @param source - * the source connector bearing the value, not null + * @param + * the type of the source component + * @param component + * the source component bearing the value, not null * @param userOriginated * {@code true} if this event originates from the client, * {@code false} otherwise. */ - public > ValueChange( - CONNECTOR source, boolean userOriginated) { - this(source, source.getValue(), userOriginated); + public > ValueChangeEvent( + COMPONENT component, boolean userOriginated) { + this(component, component, userOriginated); } /** * Creates a new {@code ValueChange} event containing the given value, - * originating from the given source connector. + * originating from the given source component. * - * @param source - * the source connector, not null - * @param value - * the new value, may be null + * @param component + * the component, not null + * @param hasValue + * the HasValue instance bearing the value, not null * @param userOriginated * {@code true} if this event originates from the client, * {@code false} otherwise. */ - public ValueChange(ClientConnector source, V value, + public ValueChangeEvent(Component component, HasValue hasValue, boolean userOriginated) { - super(source); - this.value = value; + super(hasValue); this.userOriginated = userOriginated; + this.component = component; } /** - * Returns the new value of the source connector. + * Returns the new value of the event source. + *

+ * This a shorthand method for {@link HasValue#getValue()} for the event + * source {@link #getSource()}. Thus the value is always the most recent + * one, even if has been changed after the firing of this event. + * + * @see HasValue#getValue() * * @return the new value */ public V getValue() { - return value; + return getSource().getValue(); } /** @@ -107,6 +112,21 @@ public interface HasValue extends Serializable { public boolean isUserOriginated() { return userOriginated; } + + /** + * Returns the component. + * + * @return the component, not null + */ + public Component getComponent() { + return component; + } + + @SuppressWarnings("unchecked") + @Override + public HasValue getSource() { + return (HasValue) super.getSource(); + } } /** @@ -115,17 +135,17 @@ public interface HasValue extends Serializable { * @param * the value type * - * @see ValueChange + * @see ValueChangeEvent * @see Registration */ @FunctionalInterface public interface ValueChangeListener - extends EventListener> { + extends Consumer>, Serializable { @Deprecated public static final Method VALUE_CHANGE_METHOD = ReflectTools .findMethod(ValueChangeListener.class, "accept", - ValueChange.class); + ValueChangeEvent.class); /** * Invoked when this listener receives a value change event from an @@ -135,7 +155,7 @@ public interface HasValue extends Serializable { * the received event, not null */ @Override - public void accept(ValueChange event); + public void accept(ValueChangeEvent event); } /** @@ -171,8 +191,7 @@ public interface HasValue extends Serializable { * the value change listener, not null * @return a registration for the listener */ - public Registration addValueChangeListener( - ValueChangeListener listener); + public Registration addValueChangeListener(ValueChangeListener listener); /** * Returns the value that represents an empty value. @@ -181,7 +200,7 @@ public interface HasValue extends Serializable { * values. Specific implementations might not support this. * * @return empty value - * @see Binder#bind(HasValue, Function, BiConsumer) + * @see Binder#bind(HasValue, java.util.function.Function, BiConsumer) */ public default V getEmptyValue() { return null; diff --git a/server/src/main/java/com/vaadin/event/selection/MultiSelectionEvent.java b/server/src/main/java/com/vaadin/event/selection/MultiSelectionEvent.java index c79b405523..d63f26d680 100644 --- a/server/src/main/java/com/vaadin/event/selection/MultiSelectionEvent.java +++ b/server/src/main/java/com/vaadin/event/selection/MultiSelectionEvent.java @@ -19,9 +19,8 @@ import java.util.Collections; import java.util.Optional; import java.util.Set; -import com.vaadin.data.HasValue.ValueChange; -import com.vaadin.shared.data.selection.SelectionModel; -import com.vaadin.ui.AbstractListing; +import com.vaadin.data.HasValue.ValueChangeEvent; +import com.vaadin.ui.AbstractMultiSelect; /** * Event fired when the the selection changes in a @@ -34,7 +33,7 @@ import com.vaadin.ui.AbstractListing; * @param * the data type of the selection model */ -public class MultiSelectionEvent extends ValueChange> +public class MultiSelectionEvent extends ValueChangeEvent> implements SelectionEvent { private final Set oldSelection; @@ -46,22 +45,24 @@ public class MultiSelectionEvent extends ValueChange> * the listing component in which the selection changed * @param oldSelection * the old set of selected items - * @param newSelection - * the new set of selected items * @param userOriginated * {@code true} if this event originates from the client, * {@code false} otherwise. */ - public MultiSelectionEvent( - AbstractListing> source, - Set oldSelection, Set newSelection, boolean userOriginated) { - super(source, Collections.unmodifiableSet(newSelection), - userOriginated); + public MultiSelectionEvent(AbstractMultiSelect source, + Set oldSelection, boolean userOriginated) { + super(source, userOriginated); this.oldSelection = oldSelection; } /** * Gets the new selection. + *

+ * The result is the current selection of the source + * {@link AbstractMultiSelect} object. So it's always exactly the same as + * {@link AbstractMultiSelect#getValue()} + * + * @see #getValue() * * @return a set of items selected after the selection was changed */ diff --git a/server/src/main/java/com/vaadin/event/selection/MultiSelectionListener.java b/server/src/main/java/com/vaadin/event/selection/MultiSelectionListener.java index 44c317532d..c8de132341 100644 --- a/server/src/main/java/com/vaadin/event/selection/MultiSelectionListener.java +++ b/server/src/main/java/com/vaadin/event/selection/MultiSelectionListener.java @@ -15,7 +15,8 @@ */ package com.vaadin.event.selection; -import com.vaadin.event.EventListener; +import java.io.Serializable; +import java.util.function.Consumer; /** * Listens to changes from a @@ -29,7 +30,7 @@ import com.vaadin.event.EventListener; * the data type of the selection model */ public interface MultiSelectionListener - extends EventListener> { + extends Consumer>, Serializable { @Override // Explicitly defined to make reflection logic happy void accept(MultiSelectionEvent event); diff --git a/server/src/main/java/com/vaadin/event/selection/SingleSelectionChange.java b/server/src/main/java/com/vaadin/event/selection/SingleSelectionChangeEvent.java similarity index 73% rename from server/src/main/java/com/vaadin/event/selection/SingleSelectionChange.java rename to server/src/main/java/com/vaadin/event/selection/SingleSelectionChangeEvent.java index 3f4323b9ac..566facfd9c 100644 --- a/server/src/main/java/com/vaadin/event/selection/SingleSelectionChange.java +++ b/server/src/main/java/com/vaadin/event/selection/SingleSelectionChangeEvent.java @@ -17,8 +17,9 @@ package com.vaadin.event.selection; import java.util.Optional; -import com.vaadin.data.HasValue.ValueChange; +import com.vaadin.data.HasValue.ValueChangeEvent; import com.vaadin.ui.AbstractListing; +import com.vaadin.ui.AbstractSingleSelect; /** * Fired when the selection changes in a listing component. @@ -29,7 +30,7 @@ import com.vaadin.ui.AbstractListing; * the type of the selected item * @since 8.0 */ -public class SingleSelectionChange extends ValueChange +public class SingleSelectionChangeEvent extends ValueChangeEvent implements SelectionEvent { /** @@ -37,20 +38,24 @@ public class SingleSelectionChange extends ValueChange * * @param source * the listing that fired the event - * @param selectedItem - * the selected item or {@code null} if deselected * @param userOriginated * {@code true} if this event originates from the client, * {@code false} otherwise. */ - public SingleSelectionChange(AbstractListing source, T selectedItem, + public SingleSelectionChangeEvent(AbstractSingleSelect source, boolean userOriginated) { - super(source, selectedItem, userOriginated); + super(source, userOriginated); } /** * Returns an optional of the item that was selected, or an empty optional * if a previously selected item was deselected. + *

+ * The result is the current selection of the source + * {@link AbstractSingleSelect} object. So it's always exactly the same as + * optional describing {@link AbstractSingleSelect#getValue()}. + * + * @see #getValue() * * @return the selected item or an empty optional if deselected * @@ -62,8 +67,8 @@ public class SingleSelectionChange extends ValueChange @Override @SuppressWarnings("unchecked") - public AbstractListing getSource() { - return (AbstractListing) super.getSource(); + public AbstractListing getComponent() { + return (AbstractListing) super.getComponent(); } @Override diff --git a/server/src/main/java/com/vaadin/event/selection/SingleSelectionListener.java b/server/src/main/java/com/vaadin/event/selection/SingleSelectionListener.java index 04959fddd9..d36c3ceaf1 100644 --- a/server/src/main/java/com/vaadin/event/selection/SingleSelectionListener.java +++ b/server/src/main/java/com/vaadin/event/selection/SingleSelectionListener.java @@ -15,7 +15,8 @@ */ package com.vaadin.event.selection; -import com.vaadin.event.EventListener; +import java.io.Serializable; +import java.util.function.Consumer; /** * A listener for {@code SingleSelectionChange} events. @@ -25,14 +26,14 @@ import com.vaadin.event.EventListener; * @param * the type of the selected item * - * @see SingleSelectionChange + * @see SingleSelectionChangeEvent * * @since 8.0 */ @FunctionalInterface -public interface SingleSelectionListener extends - EventListener> { +public interface SingleSelectionListener + extends Consumer>, Serializable { @Override - public void accept(SingleSelectionChange event); + public void accept(SingleSelectionChangeEvent event); } diff --git a/server/src/main/java/com/vaadin/ui/AbstractDateField.java b/server/src/main/java/com/vaadin/ui/AbstractDateField.java index 6ac135b354..4735d155d9 100644 --- a/server/src/main/java/com/vaadin/ui/AbstractDateField.java +++ b/server/src/main/java/com/vaadin/ui/AbstractDateField.java @@ -612,7 +612,7 @@ public abstract class AbstractDateField extends AbstractField @Override protected void fireEvent(EventObject event) { - if (event instanceof ValueChange) { + if (event instanceof ValueChangeEvent) { if (!preventValueChangeEvent) { super.fireEvent(event); } diff --git a/server/src/main/java/com/vaadin/ui/AbstractField.java b/server/src/main/java/com/vaadin/ui/AbstractField.java index 012a5df5a1..7d87053a22 100644 --- a/server/src/main/java/com/vaadin/ui/AbstractField.java +++ b/server/src/main/java/com/vaadin/ui/AbstractField.java @@ -53,7 +53,7 @@ public abstract class AbstractField extends AbstractComponent @Deprecated private static final Method VALUE_CHANGE_METHOD = ReflectTools - .findMethod(ValueChangeListener.class, "accept", ValueChange.class); + .findMethod(ValueChangeListener.class, "accept", ValueChangeEvent.class); @Override public void setValue(T value) { @@ -100,9 +100,9 @@ public abstract class AbstractField extends AbstractComponent @Override public Registration addValueChangeListener( - ValueChangeListener listener) { - addListener(ValueChange.class, listener, VALUE_CHANGE_METHOD); - return () -> removeListener(ValueChange.class, listener); + ValueChangeListener listener) { + addListener(ValueChangeEvent.class, listener, VALUE_CHANGE_METHOD); + return () -> removeListener(ValueChangeEvent.class, listener); } @Override @@ -183,8 +183,8 @@ public abstract class AbstractField extends AbstractComponent * {@code false} otherwise. * @return the new event */ - protected ValueChange createValueChange(boolean userOriginated) { - return new ValueChange<>(this, userOriginated); + protected ValueChangeEvent createValueChange(boolean userOriginated) { + return new ValueChangeEvent<>(this, userOriginated); } @Override diff --git a/server/src/main/java/com/vaadin/ui/AbstractMultiSelect.java b/server/src/main/java/com/vaadin/ui/AbstractMultiSelect.java index 0ac647e3af..5374b7d608 100644 --- a/server/src/main/java/com/vaadin/ui/AbstractMultiSelect.java +++ b/server/src/main/java/com/vaadin/ui/AbstractMultiSelect.java @@ -187,7 +187,7 @@ public abstract class AbstractMultiSelect LinkedHashSet newSelection = new LinkedHashSet<>(selection); fireEvent(new MultiSelectionEvent<>(AbstractMultiSelect.this, - oldSelection, newSelection, userOriginated)); + oldSelection, userOriginated)); getDataCommunicator().reset(); } @@ -397,10 +397,9 @@ public abstract class AbstractMultiSelect */ @Override public Registration addValueChangeListener( - HasValue.ValueChangeListener> listener) { - return addSelectionListener( - event -> listener.accept(new ValueChange<>(event.getConnector(), - event.getValue(), event.isUserOriginated()))); + HasValue.ValueChangeListener> listener) { + return addSelectionListener(event -> listener.accept( + new ValueChangeEvent<>(this, event.isUserOriginated()))); } /** diff --git a/server/src/main/java/com/vaadin/ui/AbstractSingleSelect.java b/server/src/main/java/com/vaadin/ui/AbstractSingleSelect.java index d37c5352d5..c4405f06b1 100644 --- a/server/src/main/java/com/vaadin/ui/AbstractSingleSelect.java +++ b/server/src/main/java/com/vaadin/ui/AbstractSingleSelect.java @@ -20,7 +20,7 @@ import java.util.Objects; import java.util.Optional; import com.vaadin.data.HasValue; -import com.vaadin.event.selection.SingleSelectionChange; +import com.vaadin.event.selection.SingleSelectionChangeEvent; import com.vaadin.event.selection.SingleSelectionListener; import com.vaadin.server.data.DataCommunicator; import com.vaadin.shared.Registration; @@ -127,8 +127,8 @@ public abstract class AbstractSingleSelect extends } doSetSelectedKey(key); - fireEvent(new SingleSelectionChange<>(AbstractSingleSelect.this, - getSelectedItem().orElse(null), true)); + fireEvent(new SingleSelectionChangeEvent<>( + AbstractSingleSelect.this, true)); } /** @@ -148,8 +148,8 @@ public abstract class AbstractSingleSelect extends } doSetSelectedKey(key); - fireEvent(new SingleSelectionChange<>(AbstractSingleSelect.this, - item, false)); + fireEvent(new SingleSelectionChangeEvent<>( + AbstractSingleSelect.this, false)); } /** @@ -229,7 +229,7 @@ public abstract class AbstractSingleSelect extends @Deprecated private static final Method SELECTION_CHANGE_METHOD = ReflectTools .findMethod(SingleSelectionListener.class, "accept", - SingleSelectionChange.class); + SingleSelectionChangeEvent.class); /** * Creates a new {@code AbstractListing} with a default data communicator. @@ -272,9 +272,9 @@ public abstract class AbstractSingleSelect extends */ public Registration addSelectionListener( SingleSelectionListener listener) { - addListener(SingleSelectionChange.class, listener, + addListener(SingleSelectionChangeEvent.class, listener, SELECTION_CHANGE_METHOD); - return () -> removeListener(SingleSelectionChange.class, listener); + return () -> removeListener(SingleSelectionChangeEvent.class, listener); } /** @@ -335,10 +335,9 @@ public abstract class AbstractSingleSelect extends @Override public Registration addValueChangeListener( - HasValue.ValueChangeListener listener) { - return addSelectionListener( - event -> listener.accept(new ValueChange<>(event.getConnector(), - event.getValue(), event.isUserOriginated()))); + HasValue.ValueChangeListener listener) { + return addSelectionListener(event -> listener.accept( + new ValueChangeEvent<>(this, event.isUserOriginated()))); } @Override diff --git a/server/src/main/java/com/vaadin/ui/ComboBox.java b/server/src/main/java/com/vaadin/ui/ComboBox.java index 31dbb7da94..9ebc035c12 100644 --- a/server/src/main/java/com/vaadin/ui/ComboBox.java +++ b/server/src/main/java/com/vaadin/ui/ComboBox.java @@ -559,14 +559,12 @@ public class ComboBox extends AbstractSingleSelect implements HasValue, return getSelectionModel().getSelectedItem().orElse(null); } - @SuppressWarnings("unchecked") @Override public Registration addValueChangeListener( - HasValue.ValueChangeListener listener) { + HasValue.ValueChangeListener listener) { return addSelectionListener(event -> { - ((ValueChangeListener) listener) - .accept(new ValueChange<>(event.getConnector(), - event.getValue(), event.isUserOriginated())); + listener.accept(new ValueChangeEvent<>(event.getComponent(), this, + event.isUserOriginated())); }); } diff --git a/server/src/main/java/com/vaadin/ui/HasValueChangeMode.java b/server/src/main/java/com/vaadin/ui/HasValueChangeMode.java index 0d48a29a72..d877d4ec69 100644 --- a/server/src/main/java/com/vaadin/ui/HasValueChangeMode.java +++ b/server/src/main/java/com/vaadin/ui/HasValueChangeMode.java @@ -15,7 +15,7 @@ */ package com.vaadin.ui; -import com.vaadin.data.HasValue.ValueChange; +import com.vaadin.data.HasValue.ValueChangeEvent; import com.vaadin.shared.ui.ValueChangeMode; /** @@ -23,7 +23,7 @@ import com.vaadin.shared.ui.ValueChangeMode; */ public interface HasValueChangeMode extends Component { /** - * Sets the mode how the TextField triggers {@link ValueChange}s. + * Sets the mode how the TextField triggers {@link ValueChangeEvent}s. * * @param valueChangeMode * the new mode @@ -35,14 +35,14 @@ public interface HasValueChangeMode extends Component { /** * Returns the currently set {@link ValueChangeMode}. * - * @return the mode used to trigger {@link ValueChange}s. + * @return the mode used to trigger {@link ValueChangeEvent}s. * * @see ValueChangeMode */ public ValueChangeMode getValueChangeMode(); /** - * Sets how often {@link ValueChange}s are triggered when the + * Sets how often {@link ValueChangeEvent}s are triggered when the * {@link ValueChangeMode} is set to either {@link ValueChangeMode#LAZY} or * {@link ValueChangeMode#TIMEOUT}. * @@ -57,11 +57,11 @@ public interface HasValueChangeMode extends Component { /** * Returns the currently set timeout, in milliseconds, for how often - * {@link ValueChange}s are triggered if the current {@link ValueChangeMode} + * {@link ValueChangeEvent}s are triggered if the current {@link ValueChangeMode} * is set to either {@link ValueChangeMode#LAZY} or * {@link ValueChangeMode#TIMEOUT}. * - * @return the timeout in milliseconds of how often {@link ValueChange}s are + * @return the timeout in milliseconds of how often {@link ValueChangeEvent}s are * triggered. */ public int getValueChangeTimeout(); diff --git a/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerGrid.java b/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerGrid.java index 566a24331e..c03c865d6d 100644 --- a/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerGrid.java +++ b/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerGrid.java @@ -39,8 +39,7 @@ public class ColorPickerGrid extends AbstractField { public void select(int x, int y) { ColorPickerGrid.this.x = x; ColorPickerGrid.this.y = y; - fireEvent(new ValueChange<>(ColorPickerGrid.this, - colorGrid[y][x], true)); + fireEvent(new ValueChangeEvent<>(ColorPickerGrid.this, true)); } @Override diff --git a/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerHistory.java b/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerHistory.java index c875df7482..a32378aeaf 100644 --- a/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerHistory.java +++ b/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerHistory.java @@ -50,7 +50,7 @@ public class ColorPickerHistory extends CustomField { ColorPickerGrid grid = new ColorPickerGrid(ROWS, COLUMNS); grid.setWidth("100%"); grid.setPosition(0, 0); - grid.addValueChangeListener(event -> fireEvent(new ValueChange<>(this, + grid.addValueChangeListener(event -> fireEvent(new ValueChangeEvent<>(this, event.isUserOriginated()))); return grid; diff --git a/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPopup.java b/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPopup.java index 4cb79b9249..4cf79d862d 100644 --- a/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPopup.java +++ b/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPopup.java @@ -441,7 +441,7 @@ public class ColorPickerPopup extends Window implements HasValue { } private void okButtonClick(ClickEvent event) { - fireEvent(new ValueChange<>(this, true)); + fireEvent(new ValueChangeEvent<>(this, true)); close(); } @@ -482,11 +482,11 @@ public class ColorPickerPopup extends Window implements HasValue { @Override public Registration addValueChangeListener( - ValueChangeListener listener) { + ValueChangeListener listener) { Objects.requireNonNull(listener, "listener cannot be null"); - addListener(ValueChange.class, listener, + addListener(ValueChangeEvent.class, listener, ValueChangeListener.VALUE_CHANGE_METHOD); - return () -> removeListener(ValueChange.class, listener); + return () -> removeListener(ValueChangeEvent.class, listener); } /** @@ -498,7 +498,7 @@ public class ColorPickerPopup extends Window implements HasValue { return Collections.unmodifiableList(history.getHistory()); } - private void colorChanged(ValueChange event) { + private void colorChanged(ValueChangeEvent event) { setValue(event.getValue()); updatingColors = true; diff --git a/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPreview.java b/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPreview.java index a76f19e0e2..fd284b64b9 100644 --- a/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPreview.java +++ b/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPreview.java @@ -99,14 +99,14 @@ public class ColorPickerPreview extends CssLayout implements HasValue { @Override public Registration addValueChangeListener( - ValueChangeListener listener) { + ValueChangeListener listener) { Objects.requireNonNull(listener, "listener cannot be null"); - addListener(ValueChange.class, listener, + addListener(ValueChangeEvent.class, listener, ValueChangeListener.VALUE_CHANGE_METHOD); - return () -> removeListener(ValueChange.class, listener); + return () -> removeListener(ValueChangeEvent.class, listener); } - private void valueChange(ValueChange event) { + private void valueChange(ValueChangeEvent event) { String value = event.getValue(); try { if (value != null) { @@ -160,8 +160,7 @@ public class ColorPickerPreview extends CssLayout implements HasValue { } oldValue = value; - fireEvent(new ValueChange<>((Component) field.getData(), color, - event.isUserOriginated())); + fireEvent(new ValueChangeEvent<>(this, event.isUserOriginated())); } } catch (NumberFormatException nfe) { diff --git a/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerSelect.java b/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerSelect.java index 9e84640218..20d68da0fa 100644 --- a/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerSelect.java +++ b/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerSelect.java @@ -168,7 +168,7 @@ public class ColorPickerSelect extends CustomField { return colors; } - private void valueChange(ValueChange event) { + private void valueChange(ValueChangeEvent event) { if (grid == null) { return; } diff --git a/server/src/test/java/com/vaadin/event/selection/SelectionEventTest.java b/server/src/test/java/com/vaadin/event/selection/SelectionEventTest.java index 8ae15f5ad2..006025c197 100644 --- a/server/src/test/java/com/vaadin/event/selection/SelectionEventTest.java +++ b/server/src/test/java/com/vaadin/event/selection/SelectionEventTest.java @@ -51,7 +51,8 @@ public class SelectionEventTest { @SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void getFirstSelected_singleSelectEvent() { - SingleSelectionChange event = Mockito.mock(SingleSelectionChange.class); + SingleSelectionChangeEvent event = Mockito + .mock(SingleSelectionChangeEvent.class); Mockito.doCallRealMethod().when(event).getFirstSelected(); Mockito.when(event.getSelectedItem()).thenReturn(Optional.of("foo")); diff --git a/server/src/test/java/com/vaadin/ui/AbstractFieldTest.java b/server/src/test/java/com/vaadin/ui/AbstractFieldTest.java index bdd63caaa4..37036e1d2b 100644 --- a/server/src/test/java/com/vaadin/ui/AbstractFieldTest.java +++ b/server/src/test/java/com/vaadin/ui/AbstractFieldTest.java @@ -9,7 +9,7 @@ import org.easymock.EasyMockSupport; import org.junit.Before; import org.junit.Test; -import com.vaadin.data.HasValue.ValueChange; +import com.vaadin.data.HasValue.ValueChangeEvent; import com.vaadin.data.HasValue.ValueChangeListener; import com.vaadin.server.ClientConnector; @@ -33,7 +33,7 @@ public class AbstractFieldTest extends EasyMockSupport { TextField field; ValueChangeListener l; - Capture> capture; + Capture> capture; @Before public void setUp() { @@ -112,11 +112,11 @@ public class AbstractFieldTest extends EasyMockSupport { return createStrictMock(ValueChangeListener.class); } - private void assertEventEquals(ValueChange e, String value, + private void assertEventEquals(ValueChangeEvent e, String value, ClientConnector source, boolean userOriginated) { assertEquals("event value", value, e.getValue()); assertSame("event source", source, e.getSource()); - assertSame("event source connector", source, e.getConnector()); + assertSame("event source connector", source, e.getSource()); assertEquals("event from user", userOriginated, e.isUserOriginated()); } } diff --git a/server/src/test/java/com/vaadin/ui/AbstractMultiSelectTest.java b/server/src/test/java/com/vaadin/ui/AbstractMultiSelectTest.java index 644314c377..e117d01b9e 100644 --- a/server/src/test/java/com/vaadin/ui/AbstractMultiSelectTest.java +++ b/server/src/test/java/com/vaadin/ui/AbstractMultiSelectTest.java @@ -36,7 +36,7 @@ import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; import org.mockito.Mockito; -import com.vaadin.data.HasValue.ValueChange; +import com.vaadin.data.HasValue.ValueChangeEvent; import com.vaadin.event.selection.MultiSelectionEvent; import com.vaadin.event.selection.MultiSelectionListener; import com.vaadin.server.data.DataSource; @@ -299,6 +299,9 @@ public class AbstractMultiSelectTest { public void addValueChangeListener() { AtomicReference> selectionListener = new AtomicReference<>(); Registration registration = Mockito.mock(Registration.class); + Set set = new HashSet<>(); + set.add("foo"); + set.add("bar"); AbstractMultiSelect select = new AbstractMultiSelect() { @Override public Registration addSelectionListener( @@ -306,9 +309,14 @@ public class AbstractMultiSelectTest { selectionListener.set(listener); return registration; } + + @Override + public Set getValue() { + return set; + } }; - AtomicReference> event = new AtomicReference<>(); + AtomicReference> event = new AtomicReference<>(); Registration actualRegistration = select.addValueChangeListener(evt -> { Assert.assertNull(event.get()); event.set(evt); @@ -316,13 +324,10 @@ public class AbstractMultiSelectTest { Assert.assertSame(registration, actualRegistration); - Set set = new HashSet<>(); - set.add("foo"); - set.add("bar"); selectionListener.get().accept(new MultiSelectionEvent<>(select, - Mockito.mock(Set.class), set, true)); + Mockito.mock(Set.class), true)); - Assert.assertEquals(select, event.get().getConnector()); + Assert.assertEquals(select, event.get().getComponent()); Assert.assertEquals(set, event.get().getValue()); Assert.assertTrue(event.get().isUserOriginated()); } diff --git a/server/src/test/java/com/vaadin/ui/AbstractSingleSelectTest.java b/server/src/test/java/com/vaadin/ui/AbstractSingleSelectTest.java index 82c7859207..258bf8d0bd 100644 --- a/server/src/test/java/com/vaadin/ui/AbstractSingleSelectTest.java +++ b/server/src/test/java/com/vaadin/ui/AbstractSingleSelectTest.java @@ -33,8 +33,8 @@ import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; -import com.vaadin.data.HasValue.ValueChange; -import com.vaadin.event.selection.SingleSelectionChange; +import com.vaadin.data.HasValue.ValueChangeEvent; +import com.vaadin.event.selection.SingleSelectionChangeEvent; import com.vaadin.event.selection.SingleSelectionListener; import com.vaadin.server.data.datasource.bov.Person; import com.vaadin.shared.Registration; @@ -237,6 +237,7 @@ public class AbstractSingleSelectTest { public void addValueChangeListener() { AtomicReference> selectionListener = new AtomicReference<>(); Registration registration = Mockito.mock(Registration.class); + String value = "foo"; AbstractSingleSelect select = new AbstractSingleSelect() { @Override public Registration addSelectionListener( @@ -244,20 +245,24 @@ public class AbstractSingleSelectTest { selectionListener.set(listener); return registration; } + + @Override + public String getValue() { + return value; + } }; - AtomicReference> event = new AtomicReference<>(); + AtomicReference> event = new AtomicReference<>(); Registration actualRegistration = select.addValueChangeListener(evt -> { Assert.assertNull(event.get()); event.set(evt); }); Assert.assertSame(registration, actualRegistration); - String value = "foo"; selectionListener.get() - .accept(new SingleSelectionChange<>(select, value, true)); + .accept(new SingleSelectionChangeEvent<>(select, true)); - Assert.assertEquals(select, event.get().getConnector()); + Assert.assertEquals(select, event.get().getComponent()); Assert.assertEquals(value, event.get().getValue()); Assert.assertTrue(event.get().isUserOriginated()); } diff --git a/server/src/test/java/com/vaadin/ui/RadioButtonGroupTest.java b/server/src/test/java/com/vaadin/ui/RadioButtonGroupTest.java index a03da685d8..6bbd9a9438 100644 --- a/server/src/test/java/com/vaadin/ui/RadioButtonGroupTest.java +++ b/server/src/test/java/com/vaadin/ui/RadioButtonGroupTest.java @@ -15,17 +15,18 @@ */ package com.vaadin.ui; -import com.vaadin.server.data.DataSource; -import com.vaadin.shared.data.selection.SelectionModel; -import com.vaadin.shared.data.selection.SelectionModel.Multi; -import com.vaadin.shared.data.selection.SelectionServerRpc; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.concurrent.atomic.AtomicInteger; + import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.concurrent.atomic.AtomicInteger; +import com.vaadin.server.data.DataSource; +import com.vaadin.shared.data.selection.SelectionModel; +import com.vaadin.shared.data.selection.SelectionModel.Multi; +import com.vaadin.shared.data.selection.SelectionServerRpc; public class RadioButtonGroupTest { private RadioButtonGroup radioButtonGroup; @@ -40,7 +41,6 @@ public class RadioButtonGroupTest { selectionModel = radioButtonGroup.getSelectionModel(); } - @Test public void apiSelectionChange_notUserOriginated() { AtomicInteger listenerCount = new AtomicInteger(0); @@ -69,7 +69,7 @@ public class RadioButtonGroupTest { }); SelectionServerRpc rpc = ComponentTest.getRpcProxy(radioButtonGroup, - SelectionServerRpc.class); + SelectionServerRpc.class); rpc.select(getItemKey("First")); rpc.select(getItemKey("Second")); diff --git a/uitest/src/main/java/com/vaadin/tests/components/abstractfield/AbstractFieldTest.java b/uitest/src/main/java/com/vaadin/tests/components/abstractfield/AbstractFieldTest.java index 7324f46d3c..ced0d796e4 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/abstractfield/AbstractFieldTest.java +++ b/uitest/src/main/java/com/vaadin/tests/components/abstractfield/AbstractFieldTest.java @@ -7,7 +7,7 @@ import java.util.Collection; import java.util.Collections; import java.util.Locale; -import com.vaadin.data.HasValue.ValueChange; +import com.vaadin.data.HasValue.ValueChangeEvent; import com.vaadin.data.HasValue.ValueChangeListener; import com.vaadin.shared.Registration; import com.vaadin.tests.components.AbstractComponentTest; @@ -85,10 +85,10 @@ public abstract class AbstractFieldTest, V> protected Command valueChangeListenerCommand = new Command() { - private ValueChangeListener valueChangeListener = new ValueChangeListener() { + private ValueChangeListener valueChangeListener = new ValueChangeListener() { @Override - public void accept(ValueChange event) { + public void accept(ValueChangeEvent event) { log(event.getClass().getSimpleName() + ", new value: " + formatValue(event.getValue())); } diff --git a/uitest/src/main/java/com/vaadin/tests/components/colorpicker/ColorPickerTestUI.java b/uitest/src/main/java/com/vaadin/tests/components/colorpicker/ColorPickerTestUI.java index e8b99258f7..c4b8bc289c 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/colorpicker/ColorPickerTestUI.java +++ b/uitest/src/main/java/com/vaadin/tests/components/colorpicker/ColorPickerTestUI.java @@ -27,7 +27,7 @@ import java.util.Date; import javax.imageio.ImageIO; import com.vaadin.annotations.Widgetset; -import com.vaadin.data.HasValue.ValueChange; +import com.vaadin.data.HasValue.ValueChangeEvent; import com.vaadin.server.StreamResource; import com.vaadin.server.VaadinRequest; import com.vaadin.shared.ui.colorpicker.Color; @@ -446,7 +446,7 @@ public class ColorPickerTestUI extends AbstractReindeerTestUI { display.setSource(imageresource); } - private void colorChanged(ValueChange event) { + private void colorChanged(ValueChangeEvent event) { if (event.getSource() == colorpicker1 || event.getSource() == colorpicker3 || event.getSource() == colorpicker5) { diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/CustomDateFormats.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/CustomDateFormats.java index 8403f60ce6..ad87c80e4b 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/CustomDateFormats.java +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/CustomDateFormats.java @@ -157,7 +157,7 @@ public class CustomDateFormats extends TestBase { df.setData(new Data(serversideValueLabel, pattern)); df.setValue(LocalDate.of(2010, 2, 1)); df.addValueChangeListener(event -> updateServerSideLabel( - (AbstractDateField) event.getConnector())); + (AbstractDateField) event.getComponent())); Label patternLabel = new Label(pattern); patternLabel.setWidth(null); diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/LenientMode.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/LenientMode.java index ea503f4284..9cd829ec89 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/LenientMode.java +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/LenientMode.java @@ -3,7 +3,7 @@ package com.vaadin.tests.components.datefield; import java.time.LocalDate; import java.util.Locale; -import com.vaadin.data.HasValue.ValueChange; +import com.vaadin.data.HasValue.ValueChangeEvent; import com.vaadin.data.HasValue.ValueChangeListener; import com.vaadin.shared.ui.datefield.Resolution; import com.vaadin.tests.components.TestBase; @@ -72,7 +72,7 @@ public class LenientMode extends TestBase } @Override - public void accept(ValueChange event) { + public void accept(ValueChangeEvent event) { getMainWindow().showNotification("New value" + event.getValue()); } diff --git a/uitest/src/main/java/com/vaadin/tests/components/table/HeaderFooterClickLeftRightMiddle.java b/uitest/src/main/java/com/vaadin/tests/components/table/HeaderFooterClickLeftRightMiddle.java index 52554e26a4..a784a45814 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/table/HeaderFooterClickLeftRightMiddle.java +++ b/uitest/src/main/java/com/vaadin/tests/components/table/HeaderFooterClickLeftRightMiddle.java @@ -1,7 +1,7 @@ package com.vaadin.tests.components.table; import com.vaadin.data.HasValue; -import com.vaadin.data.HasValue.ValueChange; +import com.vaadin.data.HasValue.ValueChangeEvent; import com.vaadin.server.VaadinRequest; import com.vaadin.tests.components.AbstractTestUIWithLog; import com.vaadin.ui.CheckBox; @@ -50,7 +50,7 @@ public class HeaderFooterClickLeftRightMiddle extends AbstractTestUIWithLog { }; @Override - public void accept(ValueChange event) { + public void accept(ValueChangeEvent event) { if (table.getListeners(HeaderClickEvent.class) .isEmpty()) { table.addHeaderClickListener(headerClickListener); @@ -80,7 +80,7 @@ public class HeaderFooterClickLeftRightMiddle extends AbstractTestUIWithLog { }; @Override - public void accept(ValueChange event) { + public void accept(ValueChangeEvent event) { if (table.getListeners(FooterClickEvent.class) .isEmpty()) { table.addFooterClickListener(footerClickListener); diff --git a/uitest/src/main/java/com/vaadin/tests/components/textfield/TextFieldsValueChangeMode.java b/uitest/src/main/java/com/vaadin/tests/components/textfield/TextFieldsValueChangeMode.java index c989d49c8f..6c86b16dda 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/textfield/TextFieldsValueChangeMode.java +++ b/uitest/src/main/java/com/vaadin/tests/components/textfield/TextFieldsValueChangeMode.java @@ -1,6 +1,6 @@ package com.vaadin.tests.components.textfield; -import com.vaadin.data.HasValue.ValueChange; +import com.vaadin.data.HasValue.ValueChangeEvent; import com.vaadin.server.VaadinRequest; import com.vaadin.shared.ui.ValueChangeMode; import com.vaadin.tests.components.AbstractTestUIWithLog; @@ -72,9 +72,9 @@ public class TextFieldsValueChangeMode extends AbstractTestUIWithLog { return vl; } - private void logValueChange(ValueChange listener) { + private void logValueChange(ValueChangeEvent listener) { AbstractField field = (AbstractField) listener - .getConnector(); + .getComponent(); String msg = "Value change event for " + field.getCaption() + ", new value: '" + listener.getValue() + "'"; if (field instanceof AbstractTextField) { -- 2.39.5