Project

General

Profile

Download (2.13 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 eu.etaxonomy.cdm.model.common.Language;
15
import eu.etaxonomy.cdm.model.common.Representation;
16
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
17
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
18
import eu.etaxonomy.cdm.vaadin.util.DistributionEditorUtil;
19

    
20
/**
21
 * @author freimeier
22
 * @since 22.11.2017
23
 *
24
 */
25
public class PresenceAbsenceTermUuidTitleStringConverter extends UuidTitleStringConverter {
26

    
27
    private static final long serialVersionUID = 6205306206377080294L;
28

    
29
    /* (non-Javadoc)
30
     * @see com.vaadin.data.util.converter.Converter#convertToPresentation(java.lang.Object, java.lang.Class, java.util.Locale)
31
     */
32
    @Override
33
    public String convertToPresentation(UUID value, Class<? extends String> targetType, Locale locale) throws ConversionException {
34
        PresenceAbsenceTerm presenceAbsenceTerm = null;
35
        String formattedValue = null;
36
        if (value == null) {
37
            return formattedValue;
38
        }
39
        try{
40
            presenceAbsenceTerm = (PresenceAbsenceTerm) CdmSpringContextHelper.getTermService().load(value);
41
        }catch(IllegalArgumentException iae) {
42
            presenceAbsenceTerm = null;
43
        }
44

    
45
        if(presenceAbsenceTerm != null){
46
            Representation representation = presenceAbsenceTerm.getRepresentation(Language.DEFAULT());
47
            if(representation!=null){
48
                if(DistributionEditorUtil.isAbbreviatedLabels()){
49
                    formattedValue = representation.getAbbreviatedLabel();
50
                }
51
                else{
52
                    formattedValue = representation.getLabel();
53
                }
54
            }
55
            if(formattedValue==null){
56
                formattedValue = presenceAbsenceTerm.getTitleCache();
57
            }
58
        }
59
        return formattedValue;
60
    }
61
}
(8-8/13)