summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis Anisimov <denis@vaadin.com>2016-10-20 11:12:58 +0300
committerVaadin Code Review <review@vaadin.com>2016-10-25 06:46:17 +0000
commit862270140d287aba33dce03dc963db4421ebeb1a (patch)
tree2da2634f4dbec1814c1d6d7e01f44d6e12a36c91
parent0decd87411d98cf0d03db35fb6e5d70637ff864c (diff)
downloadvaadin-framework-862270140d287aba33dce03dc963db4421ebeb1a.tar.gz
vaadin-framework-862270140d287aba33dce03dc963db4421ebeb1a.zip
Update ValueChange API to use Component and HasValue<>.
Change-Id: I785aa82d925cadee42cc1b17d345a8923f6dc8cc
-rw-r--r--compatibility-server/src/main/java/com/vaadin/v7/ui/Field.java4
-rw-r--r--server/src/main/java/com/vaadin/data/HasValue.java81
-rw-r--r--server/src/main/java/com/vaadin/event/selection/MultiSelectionEvent.java23
-rw-r--r--server/src/main/java/com/vaadin/event/selection/MultiSelectionListener.java5
-rw-r--r--server/src/main/java/com/vaadin/event/selection/SingleSelectionChangeEvent.java (renamed from server/src/main/java/com/vaadin/event/selection/SingleSelectionChange.java)21
-rw-r--r--server/src/main/java/com/vaadin/event/selection/SingleSelectionListener.java11
-rw-r--r--server/src/main/java/com/vaadin/ui/AbstractDateField.java2
-rw-r--r--server/src/main/java/com/vaadin/ui/AbstractField.java12
-rw-r--r--server/src/main/java/com/vaadin/ui/AbstractMultiSelect.java9
-rw-r--r--server/src/main/java/com/vaadin/ui/AbstractSingleSelect.java23
-rw-r--r--server/src/main/java/com/vaadin/ui/ComboBox.java8
-rw-r--r--server/src/main/java/com/vaadin/ui/HasValueChangeMode.java12
-rw-r--r--server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerGrid.java3
-rw-r--r--server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerHistory.java2
-rw-r--r--server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPopup.java10
-rw-r--r--server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPreview.java11
-rw-r--r--server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerSelect.java2
-rw-r--r--server/src/test/java/com/vaadin/event/selection/SelectionEventTest.java3
-rw-r--r--server/src/test/java/com/vaadin/ui/AbstractFieldTest.java8
-rw-r--r--server/src/test/java/com/vaadin/ui/AbstractMultiSelectTest.java19
-rw-r--r--server/src/test/java/com/vaadin/ui/AbstractSingleSelectTest.java17
-rw-r--r--server/src/test/java/com/vaadin/ui/RadioButtonGroupTest.java18
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/abstractfield/AbstractFieldTest.java6
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/colorpicker/ColorPickerTestUI.java4
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/datefield/CustomDateFormats.java2
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/datefield/LenientMode.java4
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/table/HeaderFooterClickLeftRightMiddle.java6
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/textfield/TextFieldsValueChangeMode.java6
28 files changed, 182 insertions, 150 deletions
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<T> extends Component, BufferedValidatable, Property<T>,
* @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<V> extends Serializable {
* @param <V>
* the value type
*/
- public class ValueChange<V> extends ConnectorEvent {
+ public class ValueChangeEvent<V> 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 <CONNECTOR>
- * the type of the source connector
- * @param source
- * the source connector bearing the value, not null
+ * @param <COMPONENT>
+ * 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 <CONNECTOR extends ClientConnector & HasValue<V>> ValueChange(
- CONNECTOR source, boolean userOriginated) {
- this(source, source.getValue(), userOriginated);
+ public <COMPONENT extends Component & HasValue<V>> 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<V> 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.
+ * <p>
+ * 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<V> 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<V> getSource() {
+ return (HasValue<V>) super.getSource();
+ }
}
/**
@@ -115,17 +135,17 @@ public interface HasValue<V> extends Serializable {
* @param <V>
* the value type
*
- * @see ValueChange
+ * @see ValueChangeEvent
* @see Registration
*/
@FunctionalInterface
public interface ValueChangeListener<V>
- extends EventListener<ValueChange<V>> {
+ extends Consumer<ValueChangeEvent<V>>, 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<V> extends Serializable {
* the received event, not null
*/
@Override
- public void accept(ValueChange<V> event);
+ public void accept(ValueChangeEvent<V> event);
}
/**
@@ -171,8 +191,7 @@ public interface HasValue<V> extends Serializable {
* the value change listener, not null
* @return a registration for the listener
*/
- public Registration addValueChangeListener(
- ValueChangeListener<? super V> listener);
+ public Registration addValueChangeListener(ValueChangeListener<V> listener);
/**
* Returns the value that represents an empty value.
@@ -181,7 +200,7 @@ public interface HasValue<V> 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 <T>
* the data type of the selection model
*/
-public class MultiSelectionEvent<T> extends ValueChange<Set<T>>
+public class MultiSelectionEvent<T> extends ValueChangeEvent<Set<T>>
implements SelectionEvent<T> {
private final Set<T> oldSelection;
@@ -46,22 +45,24 @@ public class MultiSelectionEvent<T> extends ValueChange<Set<T>>
* 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<T, SelectionModel.Multi<T>> source,
- Set<T> oldSelection, Set<T> newSelection, boolean userOriginated) {
- super(source, Collections.unmodifiableSet(newSelection),
- userOriginated);
+ public MultiSelectionEvent(AbstractMultiSelect<T> source,
+ Set<T> oldSelection, boolean userOriginated) {
+ super(source, userOriginated);
this.oldSelection = oldSelection;
}
/**
* Gets the new selection.
+ * <p>
+ * 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<T>
- extends EventListener<MultiSelectionEvent<T>> {
+ extends Consumer<MultiSelectionEvent<T>>, Serializable {
@Override
// Explicitly defined to make reflection logic happy
void accept(MultiSelectionEvent<T> 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
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<T> extends ValueChange<T>
+public class SingleSelectionChangeEvent<T> extends ValueChangeEvent<T>
implements SelectionEvent<T> {
/**
@@ -37,20 +38,24 @@ public class SingleSelectionChange<T> extends ValueChange<T>
*
* @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<T, ?> source, T selectedItem,
+ public SingleSelectionChangeEvent(AbstractSingleSelect<T> 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.
+ * <p>
+ * 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<T> extends ValueChange<T>
@Override
@SuppressWarnings("unchecked")
- public AbstractListing<T, ?> getSource() {
- return (AbstractListing<T, ?>) super.getSource();
+ public AbstractListing<T, ?> getComponent() {
+ return (AbstractListing<T, ?>) 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 <T>
* the type of the selected item
*
- * @see SingleSelectionChange
+ * @see SingleSelectionChangeEvent
*
* @since 8.0
*/
@FunctionalInterface
-public interface SingleSelectionListener<T> extends
- EventListener<SingleSelectionChange<T>> {
+public interface SingleSelectionListener<T>
+ extends Consumer<SingleSelectionChangeEvent<T>>, Serializable {
@Override
- public void accept(SingleSelectionChange<T> event);
+ public void accept(SingleSelectionChangeEvent<T> 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<LocalDate>
@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<T> 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<T> extends AbstractComponent
@Override
public Registration addValueChangeListener(
- ValueChangeListener<? super T> listener) {
- addListener(ValueChange.class, listener, VALUE_CHANGE_METHOD);
- return () -> removeListener(ValueChange.class, listener);
+ ValueChangeListener<T> listener) {
+ addListener(ValueChangeEvent.class, listener, VALUE_CHANGE_METHOD);
+ return () -> removeListener(ValueChangeEvent.class, listener);
}
@Override
@@ -183,8 +183,8 @@ public abstract class AbstractField<T> extends AbstractComponent
* {@code false} otherwise.
* @return the new event
*/
- protected ValueChange<T> createValueChange(boolean userOriginated) {
- return new ValueChange<>(this, userOriginated);
+ protected ValueChangeEvent<T> 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<T>
LinkedHashSet<T> newSelection = new LinkedHashSet<>(selection);
fireEvent(new MultiSelectionEvent<>(AbstractMultiSelect.this,
- oldSelection, newSelection, userOriginated));
+ oldSelection, userOriginated));
getDataCommunicator().reset();
}
@@ -397,10 +397,9 @@ public abstract class AbstractMultiSelect<T>
*/
@Override
public Registration addValueChangeListener(
- HasValue.ValueChangeListener<? super Set<T>> listener) {
- return addSelectionListener(
- event -> listener.accept(new ValueChange<>(event.getConnector(),
- event.getValue(), event.isUserOriginated())));
+ HasValue.ValueChangeListener<Set<T>> 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<T> 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<T> extends
}
doSetSelectedKey(key);
- fireEvent(new SingleSelectionChange<>(AbstractSingleSelect.this,
- item, false));
+ fireEvent(new SingleSelectionChangeEvent<>(
+ AbstractSingleSelect.this, false));
}
/**
@@ -229,7 +229,7 @@ public abstract class AbstractSingleSelect<T> 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<T> extends
*/
public Registration addSelectionListener(
SingleSelectionListener<T> 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<T> extends
@Override
public Registration addValueChangeListener(
- HasValue.ValueChangeListener<? super T> listener) {
- return addSelectionListener(
- event -> listener.accept(new ValueChange<>(event.getConnector(),
- event.getValue(), event.isUserOriginated())));
+ HasValue.ValueChangeListener<T> 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<T> extends AbstractSingleSelect<T> implements HasValue<T>,
return getSelectionModel().getSelectedItem().orElse(null);
}
- @SuppressWarnings("unchecked")
@Override
public Registration addValueChangeListener(
- HasValue.ValueChangeListener<? super T> listener) {
+ HasValue.ValueChangeListener<T> listener) {
return addSelectionListener(event -> {
- ((ValueChangeListener<T>) 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<Color> {
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<Color> {
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<Color> {
}
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<Color> {
@Override
public Registration addValueChangeListener(
- ValueChangeListener<? super Color> listener) {
+ ValueChangeListener<Color> 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<Color> {
return Collections.unmodifiableList(history.getHistory());
}
- private void colorChanged(ValueChange<Color> event) {
+ private void colorChanged(ValueChangeEvent<Color> 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<Color> {
@Override
public Registration addValueChangeListener(
- ValueChangeListener<? super Color> listener) {
+ ValueChangeListener<Color> 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<String> event) {
+ private void valueChange(ValueChangeEvent<String> event) {
String value = event.getValue();
try {
if (value != null) {
@@ -160,8 +160,7 @@ public class ColorPickerPreview extends CssLayout implements HasValue<Color> {
}
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<Color> {
return colors;
}
- private void valueChange(ValueChange<ColorRange> event) {
+ private void valueChange(ValueChangeEvent<ColorRange> 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<String> l;
- Capture<ValueChange<String>> capture;
+ Capture<ValueChangeEvent<String>> capture;
@Before
public void setUp() {
@@ -112,11 +112,11 @@ public class AbstractFieldTest extends EasyMockSupport {
return createStrictMock(ValueChangeListener.class);
}
- private void assertEventEquals(ValueChange<String> e, String value,
+ private void assertEventEquals(ValueChangeEvent<String> 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<MultiSelectionListener<String>> selectionListener = new AtomicReference<>();
Registration registration = Mockito.mock(Registration.class);
+ Set<String> set = new HashSet<>();
+ set.add("foo");
+ set.add("bar");
AbstractMultiSelect<String> select = new AbstractMultiSelect<String>() {
@Override
public Registration addSelectionListener(
@@ -306,9 +309,14 @@ public class AbstractMultiSelectTest {
selectionListener.set(listener);
return registration;
}
+
+ @Override
+ public Set<String> getValue() {
+ return set;
+ }
};
- AtomicReference<ValueChange<?>> event = new AtomicReference<>();
+ AtomicReference<ValueChangeEvent<?>> 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<String> 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<SingleSelectionListener<String>> selectionListener = new AtomicReference<>();
Registration registration = Mockito.mock(Registration.class);
+ String value = "foo";
AbstractSingleSelect<String> select = new AbstractSingleSelect<String>() {
@Override
public Registration addSelectionListener(
@@ -244,20 +245,24 @@ public class AbstractSingleSelectTest {
selectionListener.set(listener);
return registration;
}
+
+ @Override
+ public String getValue() {
+ return value;
+ }
};
- AtomicReference<ValueChange<?>> event = new AtomicReference<>();
+ AtomicReference<ValueChangeEvent<?>> 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<String> 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<T extends AbstractField<V>, V>
protected Command<T, Boolean> valueChangeListenerCommand = new Command<T, Boolean>() {
- private ValueChangeListener<Object> valueChangeListener = new ValueChangeListener<Object>() {
+ private ValueChangeListener<V> valueChangeListener = new ValueChangeListener<V>() {
@Override
- public void accept(ValueChange<Object> event) {
+ public void accept(ValueChangeEvent<V> 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<Color> event) {
+ private void colorChanged(ValueChangeEvent<Color> 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<LocalDate> event) {
+ public void accept(ValueChangeEvent<LocalDate> 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<Boolean> event) {
+ public void accept(ValueChangeEvent<Boolean> event) {
if (table.getListeners(HeaderClickEvent.class)
.isEmpty()) {
table.addHeaderClickListener(headerClickListener);
@@ -80,7 +80,7 @@ public class HeaderFooterClickLeftRightMiddle extends AbstractTestUIWithLog {
};
@Override
- public void accept(ValueChange<Boolean> event) {
+ public void accept(ValueChangeEvent<Boolean> 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<String> listener) {
+ private void logValueChange(ValueChangeEvent<String> listener) {
AbstractField<String> field = (AbstractField<String>) listener
- .getConnector();
+ .getComponent();
String msg = "Value change event for " + field.getCaption()
+ ", new value: '" + listener.getValue() + "'";
if (field instanceof AbstractTextField) {