@@ -160,7 +160,7 @@ public class BeanBinder<BEAN> extends Binder<BEAN> { | |||
* @throws IllegalArgumentException | |||
* if the property has no accessible getter | |||
* | |||
* @see BindingBuilder#bind(SerializableFunction, | |||
* @see BindingBuilder#bind(ValueProvider, | |||
* SerializableBiConsumer) | |||
*/ | |||
public Binding<BEAN, TARGET> bind(String propertyName); | |||
@@ -361,7 +361,7 @@ public class BeanBinder<BEAN> extends Binder<BEAN> { | |||
* @throws IllegalArgumentException | |||
* if the property has no accessible getter | |||
* | |||
* @see #bind(HasValue, SerializableFunction, SerializableBiConsumer) | |||
* @see #bind(HasValue, ValueProvider, SerializableBiConsumer) | |||
*/ | |||
public <FIELDVALUE> Binding<BEAN, FIELDVALUE> bind( | |||
HasValue<FIELDVALUE> field, String propertyName) { |
@@ -172,7 +172,7 @@ public class Binder<BEAN> implements Serializable { | |||
* if {@code bind} has already been called on this binding | |||
*/ | |||
public Binding<BEAN, TARGET> bind( | |||
SerializableFunction<BEAN, TARGET> getter, | |||
ValueProvider<BEAN, TARGET> getter, | |||
com.vaadin.server.SerializableBiConsumer<BEAN, TARGET> setter); | |||
/** | |||
@@ -255,7 +255,7 @@ public class Binder<BEAN> implements Serializable { | |||
* which must match the current target data type of the binding, and a | |||
* model type, which can be any data type and becomes the new target | |||
* type of the binding. When invoking | |||
* {@link #bind(SerializableFunction, SerializableBiConsumer)}, the | |||
* {@link #bind(ValueProvider, SerializableBiConsumer)}, the | |||
* target type of the binding must match the getter/setter types. | |||
* <p> | |||
* For instance, a {@code TextField} can be bound to an integer-typed | |||
@@ -281,7 +281,7 @@ public class Binder<BEAN> implements Serializable { | |||
* type, which must match the current target data type of the binding, | |||
* and a model type, which can be any data type and becomes the new | |||
* target type of the binding. When invoking | |||
* {@link #bind(SerializableFunction, SerializableBiConsumer)}, the | |||
* {@link #bind(ValueProvider, SerializableBiConsumer)}, the | |||
* target type of the binding must match the getter/setter types. | |||
* <p> | |||
* For instance, a {@code TextField} can be bound to an integer-typed | |||
@@ -316,7 +316,7 @@ public class Binder<BEAN> implements Serializable { | |||
* type, which must match the current target data type of the binding, | |||
* and a model type, which can be any data type and becomes the new | |||
* target type of the binding. When invoking | |||
* {@link #bind(SerializableFunction, SerializableBiConsumer)}, the | |||
* {@link #bind(ValueProvider, SerializableBiConsumer)}, the | |||
* target type of the binding must match the getter/setter types. | |||
* <p> | |||
* For instance, a {@code TextField} can be bound to an integer-typed | |||
@@ -533,7 +533,7 @@ public class Binder<BEAN> implements Serializable { | |||
@Override | |||
public Binding<BEAN, TARGET> bind( | |||
SerializableFunction<BEAN, TARGET> getter, | |||
ValueProvider<BEAN, TARGET> getter, | |||
SerializableBiConsumer<BEAN, TARGET> setter) { | |||
checkUnbound(); | |||
Objects.requireNonNull(getter, "getter cannot be null"); | |||
@@ -976,7 +976,7 @@ public class Binder<BEAN> implements Serializable { | |||
/** | |||
* Creates a new binding for the given field. The returned builder may be | |||
* further configured before invoking | |||
* {@link BindingBuilder#bind(SerializableFunction, SerializableBiConsumer)} | |||
* {@link BindingBuilder#bind(ValueProvider, SerializableBiConsumer)} | |||
* which completes the binding. Until {@code Binding.bind} is called, the | |||
* binding has no effect. | |||
* <p> | |||
@@ -993,7 +993,7 @@ public class Binder<BEAN> implements Serializable { | |||
* the field to be bound, not null | |||
* @return the new binding | |||
* | |||
* @see #bind(HasValue, SerializableFunction, SerializableBiConsumer) | |||
* @see #bind(HasValue, ValueProvider, SerializableBiConsumer) | |||
*/ | |||
public <FIELDVALUE> BindingBuilder<BEAN, FIELDVALUE> forField( | |||
HasValue<FIELDVALUE> field) { | |||
@@ -1060,7 +1060,7 @@ public class Binder<BEAN> implements Serializable { | |||
*/ | |||
public <FIELDVALUE> Binding<BEAN, FIELDVALUE> bind( | |||
HasValue<FIELDVALUE> field, | |||
SerializableFunction<BEAN, FIELDVALUE> getter, | |||
ValueProvider<BEAN, FIELDVALUE> getter, | |||
SerializableBiConsumer<BEAN, FIELDVALUE> setter) { | |||
return forField(field).bind(getter, setter); | |||
} | |||
@@ -1473,7 +1473,7 @@ public class Binder<BEAN> implements Serializable { | |||
* <li>{@link #setBean(Object)} is called | |||
* <li>{@link #removeBean()} is called | |||
* <li> | |||
* {@link BindingBuilder#bind(SerializableFunction, SerializableBiConsumer)} | |||
* {@link BindingBuilder#bind(ValueProvider, SerializableBiConsumer)} | |||
* is called | |||
* <li>{@link Binder#validate()} or {@link Binding#validate()} is called | |||
* </ul> |
@@ -200,7 +200,7 @@ public interface HasValue<V> extends Serializable { | |||
* values. Specific implementations might not support this. | |||
* | |||
* @return empty value | |||
* @see Binder#bind(HasValue, java.util.function.Function, BiConsumer) | |||
* @see Binder#bind(HasValue, ValueProvider, BiConsumer) | |||
*/ | |||
public default V getEmptyValue() { | |||
return null; |
@@ -20,7 +20,6 @@ import java.util.EventObject; | |||
import com.vaadin.data.Binder.Binding; | |||
import com.vaadin.data.Binder.BindingBuilder; | |||
import com.vaadin.server.SerializableBiConsumer; | |||
import com.vaadin.server.SerializableFunction; | |||
/** | |||
* Binder status change event. | |||
@@ -33,7 +32,7 @@ import com.vaadin.server.SerializableFunction; | |||
* <li>{@link Binder#readBean(Object)} is called | |||
* <li>{@link Binder#setBean(Object)} is called | |||
* <li>{@link Binder#removeBean()} is called | |||
* <li>{@link BindingBuilder#bind(SerializableFunction, SerializableBiConsumer)} | |||
* <li>{@link BindingBuilder#bind(ValueProvider, SerializableBiConsumer)} | |||
* is called | |||
* <li>{@link Binder#validate()} or {@link Binding#validate()} is called | |||
* </ul> |
@@ -0,0 +1,59 @@ | |||
/* | |||
* 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.data; | |||
import com.vaadin.server.SerializableFunction; | |||
/** | |||
* A callback interface for providing values from a given source. | |||
* <p> | |||
* For example this interface can be implemented to simply extract a value with | |||
* a getter, or to create a composite value based on the fields of the source | |||
* object. | |||
* | |||
* @author Vaadin Ltd. | |||
* @since 8.0 | |||
* | |||
* @param <SOURCE> | |||
* the type of the object used to provide the value | |||
* @param <TARGET> | |||
* the type of the provided value | |||
*/ | |||
@FunctionalInterface | |||
public interface ValueProvider<SOURCE, TARGET> | |||
extends SerializableFunction<SOURCE, TARGET> { | |||
/** | |||
* Returns a value provider that always returns its input argument. | |||
* | |||
* @param <T> | |||
* the type of the input and output objects to the function | |||
* @return a function that always returns its input argument | |||
*/ | |||
public static <T> ValueProvider<T, T> identity() { | |||
return t -> t; | |||
} | |||
/** | |||
* Provides a value from the given source object. | |||
* | |||
* @param source | |||
* the source to retrieve the value from | |||
* @return the value provided by the source | |||
*/ | |||
@Override | |||
public TARGET apply(SOURCE source); | |||
} |
@@ -18,7 +18,7 @@ package com.vaadin.ui; | |||
import java.util.IdentityHashMap; | |||
import java.util.Map; | |||
import com.vaadin.server.SerializableFunction; | |||
import com.vaadin.data.ValueProvider; | |||
/** | |||
* Value provider class for declarative support. | |||
@@ -28,7 +28,7 @@ import com.vaadin.server.SerializableFunction; | |||
* @param <T> | |||
* item type | |||
*/ | |||
class DeclarativeValueProvider<T> implements SerializableFunction<T, String> { | |||
class DeclarativeValueProvider<T> implements ValueProvider<T, String> { | |||
private final Map<T, String> values = new IdentityHashMap<>(); | |||
@@ -47,6 +47,7 @@ import com.vaadin.data.Binder; | |||
import com.vaadin.data.BinderValidationStatus; | |||
import com.vaadin.data.Listing; | |||
import com.vaadin.data.SelectionModel; | |||
import com.vaadin.data.ValueProvider; | |||
import com.vaadin.event.ConnectorEvent; | |||
import com.vaadin.event.ContextClickEvent; | |||
import com.vaadin.event.SerializableEventListener; | |||
@@ -1005,7 +1006,7 @@ public class Grid<T> extends AbstractListing<T> | |||
* the type of value | |||
*/ | |||
protected Column(String caption, | |||
SerializableFunction<T, ? extends V> valueProvider, | |||
ValueProvider<T, ? extends V> valueProvider, | |||
Renderer<V> renderer) { | |||
Objects.requireNonNull(caption, "Header caption can't be null"); | |||
Objects.requireNonNull(valueProvider, | |||
@@ -2448,7 +2449,7 @@ public class Grid<T> extends AbstractListing<T> | |||
* @see AbstractRenderer | |||
*/ | |||
public <V> Column<T, V> addColumn(String identifier, | |||
SerializableFunction<T, ? extends V> valueProvider, | |||
ValueProvider<T, ? extends V> valueProvider, | |||
AbstractRenderer<? super T, V> renderer) | |||
throws IllegalArgumentException { | |||
if (columnKeys.containsKey(identifier)) { | |||
@@ -2477,7 +2478,7 @@ public class Grid<T> extends AbstractListing<T> | |||
* if the same identifier is used for multiple columns | |||
*/ | |||
public Column<T, String> addColumn(String identifier, | |||
SerializableFunction<T, String> valueProvider) { | |||
ValueProvider<T, String> valueProvider) { | |||
return addColumn(identifier, valueProvider, new TextRenderer()); | |||
} | |||
@@ -2494,7 +2495,7 @@ public class Grid<T> extends AbstractListing<T> | |||
* @return the new column | |||
*/ | |||
public Column<T, String> addColumn( | |||
SerializableFunction<T, ?> valueProvider) { | |||
ValueProvider<T, String> valueProvider) { | |||
return addColumn(getGeneratedIdentifier(), | |||
t -> String.valueOf(valueProvider.apply(t)), | |||
new TextRenderer()); | |||
@@ -2516,7 +2517,7 @@ public class Grid<T> extends AbstractListing<T> | |||
* @see AbstractRenderer | |||
*/ | |||
public <V> Column<T, V> addColumn( | |||
SerializableFunction<T, ? extends V> valueProvider, | |||
ValueProvider<T, ? extends V> valueProvider, | |||
AbstractRenderer<? super T, V> renderer) { | |||
return addColumn(getGeneratedIdentifier(), valueProvider, renderer); | |||
} |
@@ -22,7 +22,7 @@ import static org.junit.Assert.assertSame; | |||
import org.junit.Before; | |||
import org.junit.Test; | |||
import com.vaadin.server.SerializableFunction; | |||
import com.vaadin.data.ValueProvider; | |||
import com.vaadin.ui.Grid; | |||
import com.vaadin.ui.Grid.Column; | |||
import com.vaadin.ui.Grid.HeaderRow; | |||
@@ -35,8 +35,8 @@ public class GridDefaultHeaderTest { | |||
public void setUp() { | |||
grid = new Grid<>(); | |||
column1 = grid.addColumn("First", SerializableFunction.identity()); | |||
column2 = grid.addColumn("Second", SerializableFunction.identity()); | |||
column1 = grid.addColumn("First", ValueProvider.identity()); | |||
column2 = grid.addColumn("Second", ValueProvider.identity()); | |||
} | |||
@Test |
@@ -23,7 +23,7 @@ import static org.junit.Assert.fail; | |||
import org.junit.Before; | |||
import org.junit.Test; | |||
import com.vaadin.server.SerializableFunction; | |||
import com.vaadin.data.ValueProvider; | |||
import com.vaadin.ui.Grid; | |||
import com.vaadin.ui.Grid.Column; | |||
import com.vaadin.ui.Grid.HeaderRow; | |||
@@ -140,7 +140,7 @@ public class GridHeaderFooterTest { | |||
@Test | |||
public void addColumn_headerCellAdded() { | |||
Column<?, ?> column = grid.addColumn("Col", | |||
SerializableFunction.identity()); | |||
ValueProvider.identity()); | |||
assertNotNull(grid.getHeaderRow(0).getCell(column)); | |||
} | |||
@@ -148,7 +148,7 @@ public class GridHeaderFooterTest { | |||
@Test(expected = IllegalArgumentException.class) | |||
public void removeColumn_headerCellRemoved() { | |||
Column<String, ?> column = grid.addColumn("Col", | |||
SerializableFunction.identity()); | |||
ValueProvider.identity()); | |||
grid.removeColumn(column); | |||
grid.getHeaderRow(0).getCell(column); |
@@ -11,8 +11,8 @@ import org.junit.Assert; | |||
import org.junit.Before; | |||
import org.junit.Test; | |||
import com.vaadin.data.ValueProvider; | |||
import com.vaadin.event.selection.SelectionEvent; | |||
import com.vaadin.server.SerializableFunction; | |||
import com.vaadin.shared.ui.grid.HeightMode; | |||
import com.vaadin.ui.Grid; | |||
import com.vaadin.ui.Grid.SelectionMode; | |||
@@ -25,9 +25,9 @@ public class GridTest { | |||
@Before | |||
public void setUp() { | |||
grid = new Grid<>(); | |||
grid.addColumn("foo", SerializableFunction.identity()); | |||
grid.addColumn("foo", ValueProvider.identity()); | |||
grid.addColumn(String::length, new NumberRenderer()); | |||
grid.addColumn("randomColumnId", SerializableFunction.identity()); | |||
grid.addColumn("randomColumnId", ValueProvider.identity()); | |||
} | |||
@Test |
@@ -3,7 +3,7 @@ package com.vaadin.tests.components.grid; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import com.vaadin.server.SerializableFunction; | |||
import com.vaadin.data.ValueProvider; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.server.data.DataProvider; | |||
import com.vaadin.tests.components.AbstractTestUI; | |||
@@ -16,7 +16,7 @@ public class GridApplyFilterWhenScrolledDown extends AbstractTestUI { | |||
protected void setup(VaadinRequest request) { | |||
Grid<String> grid = new Grid<>(); | |||
grid.addColumn("Name", SerializableFunction.identity()); | |||
grid.addColumn("Name", ValueProvider.identity()); | |||
List<String> data = new ArrayList<>(); | |||
for (int i = 0; i < 1000; i++) { |