]> source.dussan.org Git - vaadin-framework.git/commitdiff
Update ValueChange API to use Component and HasValue<>.
authorDenis Anisimov <denis@vaadin.com>
Thu, 20 Oct 2016 08:12:58 +0000 (11:12 +0300)
committerVaadin Code Review <review@vaadin.com>
Tue, 25 Oct 2016 06:46:17 +0000 (06:46 +0000)
Change-Id: I785aa82d925cadee42cc1b17d345a8923f6dc8cc

29 files changed:
compatibility-server/src/main/java/com/vaadin/v7/ui/Field.java
server/src/main/java/com/vaadin/data/HasValue.java
server/src/main/java/com/vaadin/event/selection/MultiSelectionEvent.java
server/src/main/java/com/vaadin/event/selection/MultiSelectionListener.java
server/src/main/java/com/vaadin/event/selection/SingleSelectionChange.java [deleted file]
server/src/main/java/com/vaadin/event/selection/SingleSelectionChangeEvent.java [new file with mode: 0644]
server/src/main/java/com/vaadin/event/selection/SingleSelectionListener.java
server/src/main/java/com/vaadin/ui/AbstractDateField.java
server/src/main/java/com/vaadin/ui/AbstractField.java
server/src/main/java/com/vaadin/ui/AbstractMultiSelect.java
server/src/main/java/com/vaadin/ui/AbstractSingleSelect.java
server/src/main/java/com/vaadin/ui/ComboBox.java
server/src/main/java/com/vaadin/ui/HasValueChangeMode.java
server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerGrid.java
server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerHistory.java
server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPopup.java
server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPreview.java
server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerSelect.java
server/src/test/java/com/vaadin/event/selection/SelectionEventTest.java
server/src/test/java/com/vaadin/ui/AbstractFieldTest.java
server/src/test/java/com/vaadin/ui/AbstractMultiSelectTest.java
server/src/test/java/com/vaadin/ui/AbstractSingleSelectTest.java
server/src/test/java/com/vaadin/ui/RadioButtonGroupTest.java
uitest/src/main/java/com/vaadin/tests/components/abstractfield/AbstractFieldTest.java
uitest/src/main/java/com/vaadin/tests/components/colorpicker/ColorPickerTestUI.java
uitest/src/main/java/com/vaadin/tests/components/datefield/CustomDateFormats.java
uitest/src/main/java/com/vaadin/tests/components/datefield/LenientMode.java
uitest/src/main/java/com/vaadin/tests/components/table/HeaderFooterClickLeftRightMiddle.java
uitest/src/main/java/com/vaadin/tests/components/textfield/TextFieldsValueChangeMode.java

index 79c685c71bfe1c9b91c67f3666a4ad64fb639283..d98153da293b2a77df154c57b6cac06596ab3b75 100644 (file)
@@ -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")
index 0ad3203b78b9b3452ad0f0ef779e8c22e8cd2a59..7a8bc7c296064459bd5bad37b5aec1eeec03064f 100644 (file)
@@ -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;
index c79b405523b7c654a1ada7f8427c61c6582d81d8..d63f26d680158f5ce3dbe36e8bc0041eb7786e63 100644 (file)
@@ -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
      */
index 44c317532da0cea42bff8c8645859fe33334f37e..c8de132341b8bae9aa30b9bdfbf1b16e6b80436c 100644 (file)
@@ -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/SingleSelectionChange.java
deleted file mode 100644 (file)
index 3f4323b..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright 2000-2016 Vaadin Ltd.
- * 
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- * 
- * http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.vaadin.event.selection;
-
-import java.util.Optional;
-
-import com.vaadin.data.HasValue.ValueChange;
-import com.vaadin.ui.AbstractListing;
-
-/**
- * Fired when the selection changes in a listing component.
- * 
- * @author Vaadin Ltd.
- *
- * @param <T>
- *            the type of the selected item
- * @since 8.0
- */
-public class SingleSelectionChange<T> extends ValueChange<T>
-        implements SelectionEvent<T> {
-
-    /**
-     * Creates a new selection change event.
-     * 
-     * @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,
-            boolean userOriginated) {
-        super(source, selectedItem, userOriginated);
-    }
-
-    /**
-     * Returns an optional of the item that was selected, or an empty optional
-     * if a previously selected item was deselected.
-     * 
-     * @return the selected item or an empty optional if deselected
-     *
-     * @see SelectionModel.Single#getSelectedItem()
-     */
-    public Optional<T> getSelectedItem() {
-        return Optional.ofNullable(getValue());
-    }
-
-    @Override
-    @SuppressWarnings("unchecked")
-    public AbstractListing<T, ?> getSource() {
-        return (AbstractListing<T, ?>) super.getSource();
-    }
-
-    @Override
-    public Optional<T> getFirstSelected() {
-        return getSelectedItem();
-    }
-}
diff --git a/server/src/main/java/com/vaadin/event/selection/SingleSelectionChangeEvent.java b/server/src/main/java/com/vaadin/event/selection/SingleSelectionChangeEvent.java
new file mode 100644 (file)
index 0000000..566facf
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.event.selection;
+
+import java.util.Optional;
+
+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.
+ * 
+ * @author Vaadin Ltd.
+ *
+ * @param <T>
+ *            the type of the selected item
+ * @since 8.0
+ */
+public class SingleSelectionChangeEvent<T> extends ValueChangeEvent<T>
+        implements SelectionEvent<T> {
+
+    /**
+     * Creates a new selection change event.
+     * 
+     * @param source
+     *            the listing that fired the event
+     * @param userOriginated
+     *            {@code true} if this event originates from the client,
+     *            {@code false} otherwise.
+     */
+    public SingleSelectionChangeEvent(AbstractSingleSelect<T> source,
+            boolean 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
+     *
+     * @see SelectionModel.Single#getSelectedItem()
+     */
+    public Optional<T> getSelectedItem() {
+        return Optional.ofNullable(getValue());
+    }
+
+    @Override
+    @SuppressWarnings("unchecked")
+    public AbstractListing<T, ?> getComponent() {
+        return (AbstractListing<T, ?>) super.getComponent();
+    }
+
+    @Override
+    public Optional<T> getFirstSelected() {
+        return getSelectedItem();
+    }
+}
index 04959fddd98d15c1306a99b26cb687a168b494b7..d36c3ceaf1d95206bc2dd82d3609789012850109 100644 (file)
@@ -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);
 }
index 6ac135b3540a3dbc1ebd62e55eeefc5045bd37a4..4735d155d91de3f78efd6742033573497b40c38d 100644 (file)
@@ -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);
             }
index 012a5df5a166a5da4f568fec63715d4790f328a1..7d87053a2242ba55bff43d3a6b85585010da9b20 100644 (file)
@@ -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
index 0ac647e3af72a0ceb53912b699e9b9efe0538d5d..5374b7d60824862ec4c3413b67bb2cb000ca6e1a 100644 (file)
@@ -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())));
     }
 
     /**
index d37c5352d58c983668e279e6c46525a2b158131b..c4405f06b12c5663fdc7480c69ed59a6bc4217f6 100644 (file)
@@ -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
index 31dbb7da9420057e6aeebb5f77ae15544300f6f1..9ebc035c122ce0a744fcbe319abd8e710bda2d03 100644 (file)
@@ -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()));
         });
     }
 
index 0d48a29a727f2aa075cf3a30e39f889887f8c5db..d877d4ec697b3195e3914e4f565e13a0a3869e81 100644 (file)
@@ -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();
index 566a24331ef74fa36bf880a12d041a8a55c01e10..c03c865d6d57d6dbeffde354f686a814d2c93ed3 100644 (file)
@@ -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
index c875df748239cac732ab2181c1bc152a5582b58c..a32378aeaf22df2ebc570559032d5d08f3737f93 100644 (file)
@@ -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;
index 4cb79b92494f8c2fabc18be23bad5b871c7d552f..4cf79d862d4b050ad6cb04480724957d12c3317d 100644 (file)
@@ -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;
index a76f19e0e21975c501ca656063262fe842a38aed..fd284b64b904c89370b86433feb18ef09b2e4efc 100644 (file)
@@ -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) {
index 9e8464021871b1b565616261569bb3e16bd31de1..20d68da0fa79906ddd0f4367d02df34a9a8d5987 100644 (file)
@@ -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;
         }
index 8ae15f5ad2690601acdf2a56aa1430b6a7add7a1..006025c197dee5331bbf326a7a9bd11d2853634a 100644 (file)
@@ -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"));
index bdd63caaa47ac208c5e605534e0f7259cd817efa..37036e1d2b95c3a979efb80380a7a29e29c6a060 100644 (file)
@@ -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());
     }
 }
index 644314c377c91b9416a986aeba3feeee671af268..e117d01b9e8fe2cd5712528e2af4d80e769d86dc 100644 (file)
@@ -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());
     }
index 82c7859207c997a61124c46a676e3c5482ccbcc4..258bf8d0bdf0b9665bb4d106392d3dcfe4efb31c 100644 (file)
@@ -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());
     }
index a03da685d85cc5d979a58e83b43ed4a73adf5c33..6bbd9a9438274554a55582ced207fb83aadbb29d 100644 (file)
  */
 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"));
index 7324f46d3c453e02199a205015a9e2528da30acc..ced0d796e444a3cfcfa99e44a7dfd00023107f4b 100644 (file)
@@ -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()));
             }
index e8b99258f7c7816b9ef122d64956d0861f955887..c4b8bc289c909ffef8019b0534574cd1a68a2b7f 100644 (file)
@@ -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) {
index 8403f60ce6ba686e6d011a4d1fe4677832751eef..ad87c80e4b7f288267f0a392585b126ac0b5b2ef 100644 (file)
@@ -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);
index ea503f42841e0cbaffc4e38e17245adce2bf5975..9cd829ec896b2f54f5c6b9b5b1763a813580ef4a 100644 (file)
@@ -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());
     }
 
index 52554e26a4f4a6314073787158272e4b47f259e6..a784a458141a6f8552c34db0ef2f65d84a6ef46d 100644 (file)
@@ -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);
index c989d49c8ffdc01f8a9892f696662bee1df4cb8d..6c86b16dda9b37b8421b92a51051c39fb523e186 100644 (file)
@@ -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) {