summaryrefslogtreecommitdiffstats
path: root/server/src/com/vaadin/ui/declarative
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2015-02-05 01:35:09 +0200
committerVaadin Code Review <review@vaadin.com>2015-02-05 13:28:06 +0000
commit620658687ec206bd3a631132e512b3e307890374 (patch)
tree393795d1be016129efcc223c6d1a79f218b7e8b8 /server/src/com/vaadin/ui/declarative
parent3c0a9961b0965b8cd0d88af8f3f4971c09ab271a (diff)
downloadvaadin-framework-620658687ec206bd3a631132e512b3e307890374.tar.gz
vaadin-framework-620658687ec206bd3a631132e512b3e307890374.zip
Declarative support for AbstractSelect (#15545)
Change-Id: Ie66ee3f2b02ce7b6aa2edb66176bfbf5bdcd6c33
Diffstat (limited to 'server/src/com/vaadin/ui/declarative')
-rw-r--r--server/src/com/vaadin/ui/declarative/DesignFormatter.java8
-rw-r--r--server/src/com/vaadin/ui/declarative/converters/DesignObjectConverter.java60
2 files changed, 68 insertions, 0 deletions
diff --git a/server/src/com/vaadin/ui/declarative/DesignFormatter.java b/server/src/com/vaadin/ui/declarative/DesignFormatter.java
index 25cf05cc9b..985b9235f3 100644
--- a/server/src/com/vaadin/ui/declarative/DesignFormatter.java
+++ b/server/src/com/vaadin/ui/declarative/DesignFormatter.java
@@ -33,6 +33,7 @@ import com.vaadin.server.Resource;
import com.vaadin.ui.declarative.converters.DesignDateConverter;
import com.vaadin.ui.declarative.converters.DesignEnumConverter;
import com.vaadin.ui.declarative.converters.DesignFormatConverter;
+import com.vaadin.ui.declarative.converters.DesignObjectConverter;
import com.vaadin.ui.declarative.converters.DesignResourceConverter;
import com.vaadin.ui.declarative.converters.DesignShortcutActionConverter;
import com.vaadin.ui.declarative.converters.DesignTimeZoneConverter;
@@ -50,6 +51,7 @@ public class DesignFormatter implements Serializable {
private final Map<Class<?>, Converter<String, ?>> converterMap = new ConcurrentHashMap<Class<?>, Converter<String, ?>>();
private final Converter<String, Enum> stringEnumConverter = new DesignEnumConverter();
+ private final Converter<String, Object> stringObjectConverter = new DesignObjectConverter();
/**
* Creates the formatter with default types already mapped.
@@ -294,6 +296,12 @@ public class DesignFormatter implements Serializable {
@SuppressWarnings("unchecked")
protected <T> Converter<String, T> findConverterFor(
Class<? extends T> sourceType, boolean strict) {
+ if (sourceType == Object.class) {
+ // Use for propertyIds, itemIds and such. Only string type objects
+ // are really supported if no special logic is implemented in the
+ // component.
+ return (Converter<String, T>) stringObjectConverter;
+ }
if (sourceType.isEnum()) {
return (Converter<String, T>) stringEnumConverter;
} else if (converterMap.containsKey(sourceType)) {
diff --git a/server/src/com/vaadin/ui/declarative/converters/DesignObjectConverter.java b/server/src/com/vaadin/ui/declarative/converters/DesignObjectConverter.java
new file mode 100644
index 0000000000..f11585d6b8
--- /dev/null
+++ b/server/src/com/vaadin/ui/declarative/converters/DesignObjectConverter.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2000-2014 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.ui.declarative.converters;
+
+import java.util.Locale;
+
+import com.vaadin.data.util.converter.Converter;
+import com.vaadin.ui.declarative.DesignAttributeHandler;
+
+/**
+ * An converter for Object to/from String for {@link DesignAttributeHandler} to
+ * use internally.
+ *
+ * @since 7.4
+ * @author Vaadin Ltd
+ */
+public class DesignObjectConverter implements Converter<String, Object> {
+
+ @Override
+ public Object convertToModel(String value,
+ Class<? extends Object> targetType, Locale locale)
+ throws com.vaadin.data.util.converter.Converter.ConversionException {
+ return value;
+ }
+
+ @Override
+ public String convertToPresentation(Object value,
+ Class<? extends String> targetType, Locale locale)
+ throws com.vaadin.data.util.converter.Converter.ConversionException {
+ if (value == null) {
+ return null;
+ }
+
+ return value.toString();
+ }
+
+ @Override
+ public Class<Object> getModelType() {
+ return Object.class;
+ }
+
+ @Override
+ public Class<String> getPresentationType() {
+ return String.class;
+ }
+
+}