Project

General

Profile

Download (2.06 KB) Statistics
| Branch: | Tag: | Revision:
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.Locale;
12
import java.util.UUID;
13

    
14
import com.vaadin.data.util.converter.Converter;
15

    
16
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
17
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
18

    
19
/**
20
 * @author freimeier
21
 * @since 22.11.2017
22
 *
23
 */
24
public class PresenceAbsenceTermUuidObjectConverter implements Converter<Object, UUID> {
25

    
26
    private static final long serialVersionUID = 4373972113891990480L;
27

    
28
    /* (non-Javadoc)
29
     * @see com.vaadin.data.util.converter.Converter#convertToModel(java.lang.Object, java.lang.Class, java.util.Locale)
30
     */
31
    @Override
32
    public UUID convertToModel(Object value, Class<? extends UUID> targetType, Locale locale) throws ConversionException {
33
        if(value != null) {
34
            return ((PresenceAbsenceTerm) value).getUuid();
35
        }
36
        return null;
37
    }
38

    
39
    /* (non-Javadoc)
40
     * @see com.vaadin.data.util.converter.Converter#convertToPresentation(java.lang.Object, java.lang.Class, java.util.Locale)
41
     */
42
    @Override
43
    public Object convertToPresentation(UUID value, Class<? extends Object> targetType, Locale locale) throws ConversionException {
44
        if(value != null) {
45
            try {
46
               return CdmSpringContextHelper.getTermService().load(value);
47
            }catch(IllegalArgumentException iae) {
48
               return null;
49
            }
50
        }
51
        return null;
52
    }
53

    
54
    /* (non-Javadoc)
55
     * @see com.vaadin.data.util.converter.Converter#getModelType()
56
     */
57
    @Override
58
    public Class<UUID> getModelType() {
59
        return UUID.class;
60
    }
61

    
62
    /* (non-Javadoc)
63
     * @see com.vaadin.data.util.converter.Converter#getPresentationType()
64
     */
65
    @Override
66
    public Class<Object> getPresentationType() {
67
        return Object.class;
68
    }
69
}
(8-8/14)