diff options
author | Teemu Suo-Anttila <teemusa@vaadin.com> | 2016-11-28 16:03:22 +0200 |
---|---|---|
committer | Teemu Suo-Anttila <teemusa@vaadin.com> | 2016-11-28 16:03:22 +0200 |
commit | 302f870e302e9d8324e7cc6e8a5b6db41038db0a (patch) | |
tree | 4132ade892eda7e450455a66e9c45cb28385ec0a /server | |
parent | b89b7f2d05dd66ce588311720a9ec6121a39d83c (diff) | |
download | vaadin-framework-302f870e302e9d8324e7cc6e8a5b6db41038db0a.tar.gz vaadin-framework-302f870e302e9d8324e7cc6e8a5b6db41038db0a.zip |
Add a fallback to Declarative*Generator
Change-Id: I7eca92ca6e2eb234000cb9c9533974fcd357d33f
Diffstat (limited to 'server')
5 files changed, 30 insertions, 9 deletions
diff --git a/server/src/main/java/com/vaadin/ui/AbstractListing.java b/server/src/main/java/com/vaadin/ui/AbstractListing.java index 2f455fa27b..6f0463b822 100644 --- a/server/src/main/java/com/vaadin/ui/AbstractListing.java +++ b/server/src/main/java/com/vaadin/ui/AbstractListing.java @@ -324,8 +324,10 @@ public abstract class AbstractListing<T> extends AbstractComponent { Boolean.class)); } - setItemCaptionGenerator(new DeclarativeCaptionGenerator<>()); - setItemIconGenerator(new DeclarativeIconGenerator<>()); + setItemCaptionGenerator( + new DeclarativeCaptionGenerator<>(getItemCaptionGenerator())); + setItemIconGenerator( + new DeclarativeIconGenerator<>(getItemIconGenerator())); List<T> readItems = readItems(design, context); if (!readItems.isEmpty() && this instanceof Listing) { diff --git a/server/src/main/java/com/vaadin/ui/ComboBox.java b/server/src/main/java/com/vaadin/ui/ComboBox.java index f0f90eab22..2b91236843 100644 --- a/server/src/main/java/com/vaadin/ui/ComboBox.java +++ b/server/src/main/java/com/vaadin/ui/ComboBox.java @@ -84,11 +84,18 @@ public class ComboBox<T> extends AbstractSingleSelect<T> */ protected static class DeclarativeStyleGenerator<T> implements StyleGenerator<T> { + + private StyleGenerator<T> fallback; private Map<T, String> styles = new HashMap<>(); + public DeclarativeStyleGenerator(StyleGenerator<T> fallback) { + this.fallback = fallback; + } + @Override public String apply(T item) { - return styles.get(item); + return styles.containsKey(item) ? styles.get(item) + : fallback.apply(item); } /** @@ -581,7 +588,7 @@ public class ComboBox<T> extends AbstractSingleSelect<T> @Override protected List<T> readItems(Element design, DesignContext context) { - setStyleGenerator(new DeclarativeStyleGenerator<>()); + setStyleGenerator(new DeclarativeStyleGenerator<>(getStyleGenerator())); return super.readItems(design, context); } diff --git a/server/src/main/java/com/vaadin/ui/DeclarativeCaptionGenerator.java b/server/src/main/java/com/vaadin/ui/DeclarativeCaptionGenerator.java index 9aa6035d9d..617315459d 100644 --- a/server/src/main/java/com/vaadin/ui/DeclarativeCaptionGenerator.java +++ b/server/src/main/java/com/vaadin/ui/DeclarativeCaptionGenerator.java @@ -28,16 +28,22 @@ import java.util.Map; */ class DeclarativeCaptionGenerator<T> implements ItemCaptionGenerator<T> { + private ItemCaptionGenerator<T> fallback; private Map<T, String> captions = new HashMap<>(); + public DeclarativeCaptionGenerator(ItemCaptionGenerator<T> fallback) { + this.fallback = fallback; + } + @Override public String apply(T item) { - return captions.get(item); + return captions.containsKey(item) ? captions.get(item) + : fallback.apply(item); } /** * Sets a {@code caption} for the {@code item}. - * + * * @param item * a data item * @param caption diff --git a/server/src/main/java/com/vaadin/ui/DeclarativeIconGenerator.java b/server/src/main/java/com/vaadin/ui/DeclarativeIconGenerator.java index 984ac4cf47..926de395b3 100644 --- a/server/src/main/java/com/vaadin/ui/DeclarativeIconGenerator.java +++ b/server/src/main/java/com/vaadin/ui/DeclarativeIconGenerator.java @@ -30,16 +30,22 @@ import com.vaadin.server.Resource; */ class DeclarativeIconGenerator<T> implements IconGenerator<T> { + private IconGenerator<T> fallback; private Map<T, Resource> captions = new HashMap<>(); + public DeclarativeIconGenerator(IconGenerator<T> fallback) { + this.fallback = fallback; + } + @Override public Resource apply(T item) { - return captions.get(item); + return captions.containsKey(item) ? captions.get(item) + : fallback.apply(item); } /** * Sets an {@code icon} for the {@code item}. - * + * * @param item * a data item * @param icon diff --git a/server/src/main/java/com/vaadin/ui/DeclarativeItemEnabledProvider.java b/server/src/main/java/com/vaadin/ui/DeclarativeItemEnabledProvider.java index f16e54f1b2..adb2ade00f 100644 --- a/server/src/main/java/com/vaadin/ui/DeclarativeItemEnabledProvider.java +++ b/server/src/main/java/com/vaadin/ui/DeclarativeItemEnabledProvider.java @@ -39,7 +39,7 @@ class DeclarativeItemEnabledProvider<T> implements SerializablePredicate<T> { /** * Adds the {@code item} to disabled items list. - * + * * @param item * a data item * @param caption |