aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/com/vaadin/ui/declarative/converters/DesignEnumConverter.java
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2015-02-04 15:52:42 +0200
committerVaadin Code Review <review@vaadin.com>2015-02-05 12:34:29 +0000
commitedabf251a53762d5bf45a70be757e5b0bd48d25a (patch)
treed6e175da06e6ab040565b4fc5315445ac44d558d /server/src/com/vaadin/ui/declarative/converters/DesignEnumConverter.java
parentb5b98e47441aa4ac587de097b22b25cc4852a4ec (diff)
downloadvaadin-framework-edabf251a53762d5bf45a70be757e5b0bd48d25a.tar.gz
vaadin-framework-edabf251a53762d5bf45a70be757e5b0bd48d25a.zip
Simplified declarative converters
* Removed shortcut interface * Moved TimeZone converter to a separate class * Moved Enum converter to a separate class Change-Id: I2b959e3a002e6319912212df4a62a3bd05677f80
Diffstat (limited to 'server/src/com/vaadin/ui/declarative/converters/DesignEnumConverter.java')
-rw-r--r--server/src/com/vaadin/ui/declarative/converters/DesignEnumConverter.java63
1 files changed, 63 insertions, 0 deletions
diff --git a/server/src/com/vaadin/ui/declarative/converters/DesignEnumConverter.java b/server/src/com/vaadin/ui/declarative/converters/DesignEnumConverter.java
new file mode 100644
index 0000000000..9f07ff9560
--- /dev/null
+++ b/server/src/com/vaadin/ui/declarative/converters/DesignEnumConverter.java
@@ -0,0 +1,63 @@
+/*
+ * 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 Enum to/from String for {@link DesignAttributeHandler} to
+ * use internally.
+ *
+ * @since 7.4
+ * @author Vaadin Ltd
+ */
+public class DesignEnumConverter implements Converter<String, Enum> {
+
+ @Override
+ public Enum convertToModel(String value, Class<? extends Enum> targetType,
+ Locale locale)
+ throws com.vaadin.data.util.converter.Converter.ConversionException {
+ if (value == null || value.trim().equals("")) {
+ return null;
+ }
+ return Enum.valueOf(targetType, value.toUpperCase(Locale.ENGLISH));
+ }
+
+ @Override
+ public String convertToPresentation(Enum value,
+ Class<? extends String> targetType, Locale locale)
+ throws com.vaadin.data.util.converter.Converter.ConversionException {
+ if (value == null) {
+ return null;
+ }
+
+ return value.name().toLowerCase(Locale.ENGLISH);
+ }
+
+ @Override
+ public Class<Enum> getModelType() {
+ return Enum.class;
+ }
+
+ @Override
+ public Class<String> getPresentationType() {
+ return String.class;
+ }
+
+}