package com.vaadin.data;
+import com.vaadin.server.SerializableConsumer;
+import com.vaadin.server.SerializableFunction;
+import com.vaadin.server.SerializableSupplier;
+
import java.io.Serializable;
import java.util.Objects;
import java.util.Optional;
-import java.util.function.Consumer;
-import java.util.function.Function;
-import java.util.function.Supplier;
/**
* Represents the result of an operation that might fail, such as type
* the function to provide the error message
* @return the result of invoking the supplier
*/
- public static <R> Result<R> of(Supplier<R> supplier,
- Function<Exception, String> onError) {
+ public static <R> Result<R> of(SerializableSupplier<R> supplier,
+ SerializableFunction<Exception, String> onError) {
Objects.requireNonNull(supplier, "supplier cannot be null");
Objects.requireNonNull(onError, "onError cannot be null");
* the mapping function
* @return the mapped result
*/
- default <S> Result<S> map(Function<R, S> mapper) {
+ public default <S> Result<S> map(SerializableFunction<R, S> mapper) {
return flatMap(value -> ok(mapper.apply(value)));
}
* the mapping function
* @return the mapped result
*/
- <S> Result<S> flatMap(Function<R, Result<S>> mapper);
+ public <S> Result<S> flatMap(SerializableFunction<R, Result<S>> mapper);
/**
* Invokes either the first callback or the second one, depending on whether
* @param ifError
* the function to call if failure
*/
- void handle(Consumer<R> ifOk, Consumer<String> ifError);
+ public void handle(SerializableConsumer<R> ifOk, SerializableConsumer<String> ifError);
/**
* Applies the {@code consumer} if result is not an error.
* @param consumer
* consumer to apply in case it's not an error
*/
- default void ifOk(Consumer<R> consumer) {
+ public default void ifOk(SerializableConsumer<R> consumer) {
handle(consumer, error -> {
});
}
* @param consumer
* consumer to apply in case it's an error
*/
- default void ifError(Consumer<String> consumer) {
+ public default void ifError(SerializableConsumer<String> consumer) {
handle(value -> {
}, consumer);
}
* @return <code>true</code> if the result denotes an error,
* <code>false</code> otherwise
*/
- boolean isError();
+ public boolean isError();
/**
* Returns an Optional of the result message, or an empty Optional if none.
*
* @return the optional message
*/
- Optional<String> getMessage();
+ public Optional<String> getMessage();
/**
* Return the value, if the result denotes success, otherwise throw an
* @throws X
* if this result denotes an error
*/
- <X extends Throwable> R getOrThrow(
- Function<String, ? extends X> exceptionProvider) throws X;
+ public <X extends Throwable> R getOrThrow(
+ SerializableFunction<String, ? extends X> exceptionProvider) throws X;
}
*/
package com.vaadin.data;
+import com.vaadin.server.SerializableConsumer;
+import com.vaadin.server.SerializableFunction;
+
import java.util.Objects;
import java.util.Optional;
-import java.util.function.Consumer;
-import java.util.function.Function;
/**
* An internal implementation of {@code Result}.
@Override
@SuppressWarnings("unchecked")
- public <S> Result<S> flatMap(Function<R, Result<S>> mapper) {
+ public <S> Result<S> flatMap(SerializableFunction<R, Result<S>> mapper) {
Objects.requireNonNull(mapper, "mapper cannot be null");
if (isError()) {
}
@Override
- public void handle(Consumer<R> ifOk, Consumer<String> ifError) {
+ public void handle(SerializableConsumer<R> ifOk, SerializableConsumer<String> ifError) {
Objects.requireNonNull(ifOk, "ifOk cannot be null");
Objects.requireNonNull(ifError, "ifError cannot be null");
if (isError()) {
@Override
public <X extends Throwable> R getOrThrow(
- Function<String, ? extends X> exceptionSupplier) throws X {
+ SerializableFunction<String, ? extends X> exceptionSupplier) throws X {
Objects.requireNonNull(exceptionSupplier,
"Exception supplier cannot be null");
if (isError()) {
* type <code>eventType</code> with one or more methods.
*
* @since 6.2
+ * @deprecated use a {@link Registration} from
+ * {@link #addListener(Class, Object, Method)} to remove a
+ * listener
*/
+ @Deprecated
protected void removeListener(String eventIdentifier, Class<?> eventType,
Object target) {
if (eventRouter != null) {
* <p>
* Note: Using this method is discouraged because it cannot be checked
* during compilation. Use {@link #addListener(Class, Object, Method)} or
- * {@link #addListener(com.vaadin.ui.Component.Listener)} instead.
+ * {@link #addListener(String, Class, Object, Method) instead.
* </p>
*
* @param eventType
* @param target
* the target object that has registered to listen to events of
* type <code>eventType</code> with one or more methods.
+ * @deprecated use a {@link Registration} from
+ * {@link #addListener} to remove a
+ * listener
*/
+ @Deprecated
@Override
public void removeListener(Class<?> eventType, Object target) {
if (eventRouter != null) {
--- /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.server;
+
+import java.io.Serializable;
+import java.util.function.Function;
+import java.util.function.Supplier;
+
+/**
+ * A {@link Supplier} that is also {@link Serializable}.
+ *
+ * @see Supplier
+ * @author Vaadin Ltd
+ * @since 8.0
+ * @param <T>
+ * the type of the input to the function
+ */
+@FunctionalInterface
+public interface SerializableSupplier<T>
+ extends Supplier<T>, Serializable {
+ // Only method inherited from Supplier
+}
package com.vaadin.ui;
-import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
-import java.util.function.Consumer;
+import com.vaadin.server.KeyMapper;
+import com.vaadin.server.Resource;
+import com.vaadin.server.ResourceReference;
+import com.vaadin.server.SerializableBiPredicate;
+import com.vaadin.server.SerializableConsumer;
import org.jsoup.nodes.Element;
import com.vaadin.data.HasValue;
import com.vaadin.event.FieldEvents.FocusAndBlurServerRpcDecorator;
import com.vaadin.event.FieldEvents.FocusEvent;
import com.vaadin.event.FieldEvents.FocusListener;
-import com.vaadin.server.KeyMapper;
-import com.vaadin.server.Resource;
-import com.vaadin.server.ResourceReference;
-import com.vaadin.server.SerializableBiPredicate;
import com.vaadin.server.data.DataCommunicator;
import com.vaadin.server.data.DataKeyMapper;
import com.vaadin.server.data.DataProvider;
* allowed mode is active.
*/
@FunctionalInterface
- public interface NewItemHandler extends Consumer<String>, Serializable {
+ public interface NewItemHandler extends SerializableConsumer<String> {
}
/**
* Note that unlike {@link #setItems(Collection)}, no automatic case
* conversion is performed before the comparison.
*
- * @param filterPredicate
- * predicate for comparing the item string (first parameter) and
- * the filter string (second parameter)
+ * @param captionFilter
+ * filter to check if an item is shown when user typed some text into the ComboBox
* @param items
* the data items to display
*/
public void setItems(
- SerializableBiPredicate<String, String> filterPredicate,
+ CaptionFilter captionFilter,
Collection<T> items) {
DataProvider<T, String> provider = DataProvider.create(items)
- .convertFilter(filterText -> item -> filterPredicate.test(
+ .convertFilter(filterText -> item -> captionFilter.test(
getItemCaptionGenerator().apply(item), filterText));
setDataProvider(provider);
}
* Note that unlike {@link #setItems(Collection)}, no automatic case
* conversion is performed before the comparison.
*
- * @param filterPredicate
- * predicate for comparing the item string (first parameter) and
- * the filter string (second parameter)
+ * @param captionFilter
+ * filter to check if an item is shown when user typed some text into the ComboBox
* @param items
* the data items to display
*/
public void setItems(
- SerializableBiPredicate<String, String> filterPredicate,
+ CaptionFilter captionFilter,
@SuppressWarnings("unchecked") T... items) {
DataProvider<T, String> provider = DataProvider.create(items)
- .convertFilter(filterText -> item -> filterPredicate.test(
+ .convertFilter(filterText -> item -> captionFilter.test(
getItemCaptionGenerator().apply(item), filterText));
setDataProvider(provider);
}
* @see #isEmptySelectionAllowed()
* @see #setEmptySelectionCaption(String)
* @see #isSelected(Object)
- * @see #select(Object)
*
* @return the empty selection caption, not {@code null}
*/
*/
updateDiffstate("selectedItemKey", Json.create(0));
}
+
+ /**
+ * Predicate to check {@link ComboBox} item captions against user typed strings.
+ *
+ * @see #setItems(CaptionFilter, Collection)
+ * @see #setItems(CaptionFilter, Object[])
+ */
+ @FunctionalInterface
+ public interface CaptionFilter extends SerializableBiPredicate<String, String> {
+
+ /**
+ * Check item caption against entered text
+ *
+ * @param itemCaption
+ * @param filterText
+ * @return {@code true} if item passes the filter and should be listed, {@code false} otherwise
+ */
+ @Override
+ public boolean test(String itemCaption, String filterText);
+ }
}
import com.vaadin.shared.ui.grid.HeightMode;
import com.vaadin.shared.ui.grid.SectionState;
import com.vaadin.shared.util.SharedUtil;
-import com.vaadin.ui.Grid.FooterRow;
import com.vaadin.ui.components.grid.AbstractSelectionModel;
import com.vaadin.ui.components.grid.EditorImpl;
import com.vaadin.ui.components.grid.Footer;
*/
@FunctionalInterface
public interface DetailsGenerator<T>
- extends Function<T, Component>, Serializable {
+ extends SerializableFunction<T, Component> {
}
/**
private final SerializableFunction<T, ? extends V> valueProvider;
- private SerializableFunction<SortDirection, Stream<SortOrder<String>>> sortOrderProvider;
+ private SortOrderProvider sortOrderProvider;
private SerializableComparator<T> comparator;
private StyleGenerator<T> styleGenerator = item -> null;
private DescriptionGenerator<T> descriptionGenerator;
* given direction
* @return this column
*/
- public Column<T, V> setSortOrderProvider(
- SerializableFunction<SortDirection, Stream<SortOrder<String>>> provider) {
+ public Column<T, V> setSortOrderProvider(SortOrderProvider provider) {
Objects.requireNonNull(provider,
"Sort order provider can't be null");
sortOrderProvider = provider;
* @param <T>
* the bean type
*/
+ @FunctionalInterface
public interface EditorErrorGenerator<T> extends Serializable,
BiFunction<Map<Component, Column<T, ?>>, BinderValidationStatus<T>, String> {
return result;
}
+ /**
+ * Generates the sort orders when rows are sorted by a column.
+ * @see Column#setSortOrderProvider
+ *
+ * @since 8.0
+ * @author Vaadin Ltd
+ */
+ @FunctionalInterface
+ public interface SortOrderProvider extends SerializableFunction<SortDirection, Stream<SortOrder<String>>> {
+
+ /**
+ * Generates the sort orders when rows are sorted by a column.
+ *
+ * @param sortDirection desired sort direction
+ *
+ * @return sort information
+ */
+ @Override
+ public Stream<SortOrder<String>> apply(SortDirection sortDirection);
+
+ }
}
*/
package com.vaadin.data;
-import java.util.function.Function;
-
+import com.vaadin.server.SerializableFunction;
import org.junit.Assert;
import org.junit.Test;
Result<String> result = new SimpleResult<String>("foo", null) {
@Override
- public <S> Result<S> flatMap(Function<String, Result<S>> mapper) {
+ public <S> Result<S> flatMap(SerializableFunction<String, Result<S>> mapper) {
return mapper.apply("foo");
}
};
Result<String> result = new SimpleResult<String>("foo", null) {
@Override
- public <S> Result<S> flatMap(Function<String, Result<S>> mapper) {
+ public <S> Result<S> flatMap(SerializableFunction<String, Result<S>> mapper) {
return new SimpleResult<>(null, "bar");
}
};