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;
* @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")
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;
/**
* @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();
}
/**
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();
+ }
}
/**
* @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
* the received event, not null
*/
@Override
- public void accept(ValueChange<V> event);
+ public void accept(ValueChangeEvent<V> event);
}
/**
* 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.
* 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;
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
* @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;
* 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
*/
*/
package com.vaadin.event.selection;
-import com.vaadin.event.EventListener;
+import java.io.Serializable;
+import java.util.function.Consumer;
/**
* Listens to changes from a
* 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);
+++ /dev/null
-/*
- * 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();
- }
-}
--- /dev/null
+/*
+ * 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();
+ }
+}
*/
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.
* @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);
}
@Override
protected void fireEvent(EventObject event) {
- if (event instanceof ValueChange) {
+ if (event instanceof ValueChangeEvent) {
if (!preventValueChangeEvent) {
super.fireEvent(event);
}
@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) {
@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
* {@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
LinkedHashSet<T> newSelection = new LinkedHashSet<>(selection);
fireEvent(new MultiSelectionEvent<>(AbstractMultiSelect.this,
- oldSelection, newSelection, userOriginated));
+ oldSelection, userOriginated));
getDataCommunicator().reset();
}
*/
@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())));
}
/**
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;
}
doSetSelectedKey(key);
- fireEvent(new SingleSelectionChange<>(AbstractSingleSelect.this,
- getSelectedItem().orElse(null), true));
+ fireEvent(new SingleSelectionChangeEvent<>(
+ AbstractSingleSelect.this, true));
}
/**
}
doSetSelectedKey(key);
- fireEvent(new SingleSelectionChange<>(AbstractSingleSelect.this,
- item, false));
+ fireEvent(new SingleSelectionChangeEvent<>(
+ AbstractSingleSelect.this, false));
}
/**
@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.
*/
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);
}
/**
@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
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()));
});
}
*/
package com.vaadin.ui;
-import com.vaadin.data.HasValue.ValueChange;
+import com.vaadin.data.HasValue.ValueChangeEvent;
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
/**
* 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}.
*
/**
* 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();
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
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;
}
private void okButtonClick(ClickEvent event) {
- fireEvent(new ValueChange<>(this, true));
+ fireEvent(new ValueChangeEvent<>(this, true));
close();
}
@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);
}
/**
return Collections.unmodifiableList(history.getHistory());
}
- private void colorChanged(ValueChange<Color> event) {
+ private void colorChanged(ValueChangeEvent<Color> event) {
setValue(event.getValue());
updatingColors = true;
@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) {
}
oldValue = value;
- fireEvent(new ValueChange<>((Component) field.getData(), color,
- event.isUserOriginated()));
+ fireEvent(new ValueChangeEvent<>(this, event.isUserOriginated()));
}
} catch (NumberFormatException nfe) {
return colors;
}
- private void valueChange(ValueChange<ColorRange> event) {
+ private void valueChange(ValueChangeEvent<ColorRange> event) {
if (grid == null) {
return;
}
@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"));
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;
TextField field;
ValueChangeListener<String> l;
- Capture<ValueChange<String>> capture;
+ Capture<ValueChangeEvent<String>> capture;
@Before
public void setUp() {
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());
}
}
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;
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(
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);
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());
}
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;
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(
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());
}
*/
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;
selectionModel = radioButtonGroup.getSelectionModel();
}
-
@Test
public void apiSelectionChange_notUserOriginated() {
AtomicInteger listenerCount = new AtomicInteger(0);
});
SelectionServerRpc rpc = ComponentTest.getRpcProxy(radioButtonGroup,
- SelectionServerRpc.class);
+ SelectionServerRpc.class);
rpc.select(getItemKey("First"));
rpc.select(getItemKey("Second"));
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;
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()));
}
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;
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) {
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);
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;
}
@Override
- public void accept(ValueChange<LocalDate> event) {
+ public void accept(ValueChangeEvent<LocalDate> event) {
getMainWindow().showNotification("New value" + event.getValue());
}
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;
};
@Override
- public void accept(ValueChange<Boolean> event) {
+ public void accept(ValueChangeEvent<Boolean> event) {
if (table.getListeners(HeaderClickEvent.class)
.isEmpty()) {
table.addHeaderClickListener(headerClickListener);
};
@Override
- public void accept(ValueChange<Boolean> event) {
+ public void accept(ValueChangeEvent<Boolean> event) {
if (table.getListeners(FooterClickEvent.class)
.isEmpty()) {
table.addFooterClickListener(footerClickListener);
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;
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) {