ref #7023 switched to vaadin-grid
[cdm-vaadin.git] / src / main / java / eu / etaxonomy / cdm / vaadin / util / converter / JodaDateTimeConverter.java
1 /**
2 * Copyright (C) 2017 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9 package eu.etaxonomy.cdm.vaadin.util.converter;
10
11 import java.util.Date;
12 import java.util.Locale;
13
14 import org.joda.time.DateTime;
15
16 import com.vaadin.data.util.converter.Converter;
17
18 /**
19 * @author a.kohlbecker
20 * @since Mar 7, 2017
21 *
22 */
23 public final class JodaDateTimeConverter implements Converter<Date, DateTime> {
24 @Override
25 public DateTime convertToModel(Date value, Class<? extends DateTime> targetType, Locale locale)
26 throws com.vaadin.data.util.converter.Converter.ConversionException {
27 DateTime dateTime = null;
28 if(value != null) {
29 try {
30 dateTime = new DateTime(value);
31 } catch (IllegalArgumentException e) {
32 throw new ConversionException(e);
33 }
34 }
35 return dateTime;
36 }
37
38 @Override
39 public Date convertToPresentation(DateTime value, Class<? extends Date> targetType, Locale locale)
40 throws com.vaadin.data.util.converter.Converter.ConversionException {
41 Date date = null;
42 if(value != null){
43 date = value.toDate();
44 }
45 return date;
46 }
47
48 @Override
49 public Class<DateTime> getModelType() {
50 return DateTime.class;
51 }
52
53 @Override
54 public Class<Date> getPresentationType() {
55 return Date.class;
56 }
57 }