Project

General

Profile

Download (3.91 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2018 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.taxeditor.editor.view.checklist.e4;
10

    
11
import org.apache.commons.lang.StringUtils;
12
import org.eclipse.nebula.widgets.nattable.data.convert.DisplayConverter;
13

    
14
import eu.etaxonomy.cdm.model.common.Representation;
15
import eu.etaxonomy.cdm.model.description.Distribution;
16
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
17
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
18
import eu.etaxonomy.cdm.model.metadata.TermDisplayEnum;
19
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
20
import eu.etaxonomy.taxeditor.store.CdmStore;
21

    
22
/**
23
 * @author k.luther
24
 * @since 05.12.2018
25
 *
26
 */
27
public class FilterStatusDisplayConverter extends DisplayConverter{
28
    public static final String DEFAULT_ENTRY = " ";
29
    /**
30
     * {@inheritDoc}
31
     */
32
    @Override
33
    public Object canonicalToDisplayValue(Object canonicalValue) {
34
        if(canonicalValue instanceof Distribution){
35
            Distribution distribution = (Distribution)canonicalValue;
36
            if (distribution.getStatus() != null){
37

    
38
                Representation rep = distribution.getStatus().getPreferredRepresentation(CdmStore.getDefaultLanguage());
39
                String displayStatus = PreferencesUtil.getStringValue(PreferencePredicate.DisplayOfStatus.getKey());
40
                String label = rep.getLabel();
41
                if(PreferencesUtil.displayStatusInChecklistEditor().equals(TermDisplayEnum.IdInVocabulary.getKey())){
42
                    return (StringUtils.isNotBlank(distribution.getStatus().getIdInVocabulary()))?distribution.getStatus().getIdInVocabulary():label;
43
                }else if(PreferencesUtil.displayStatusInChecklistEditor().equals(TermDisplayEnum.Symbol1.getKey())){
44

    
45
                    return (StringUtils.isNotBlank(distribution.getStatus().getSymbol() ))?distribution.getStatus().getSymbol():label;
46
                }else if(PreferencesUtil.displayStatusInChecklistEditor().equals(TermDisplayEnum.Symbol2.getKey())){
47
                    return (StringUtils.isNotBlank(distribution.getStatus().getSymbol2() ))?distribution.getStatus().getSymbol2():label;
48
                }else{
49
                    return (label != null)?label:DEFAULT_ENTRY;
50
                }
51

    
52

    
53

    
54
            }
55

    
56
            return "";
57
        }else if(canonicalValue instanceof PresenceAbsenceTerm){
58
            PresenceAbsenceTerm status = (PresenceAbsenceTerm)canonicalValue;
59
            Representation rep = status.getPreferredRepresentation(CdmStore.getDefaultLanguage());
60
            String displayStatus = PreferencesUtil.getStringValue(PreferencePredicate.DisplayOfStatus.getKey());
61
            String label = rep.getLabel();
62
            if (status.getId() == 0){
63
                return DEFAULT_ENTRY;
64
            }
65
            if(PreferencesUtil.displayStatusInChecklistEditor().equals(TermDisplayEnum.IdInVocabulary.getKey())){
66
                return (StringUtils.isNotBlank(status.getIdInVocabulary()))?status.getIdInVocabulary():label;
67
            }else if(PreferencesUtil.displayStatusInChecklistEditor().equals(TermDisplayEnum.Symbol1.getKey())){
68

    
69
                return (StringUtils.isNotBlank(status.getSymbol() ))?status.getSymbol():label;
70
            }else if(PreferencesUtil.displayStatusInChecklistEditor().equals(TermDisplayEnum.Symbol2.getKey())){
71
                return (StringUtils.isNotBlank(status.getSymbol2() ))?status.getSymbol2():label;
72
            }else{
73
                return (label != null)?label:DEFAULT_ENTRY;
74
            }
75

    
76

    
77
        } else if(canonicalValue!=null){
78
            return canonicalValue.toString();
79
        }
80
        return DEFAULT_ENTRY;
81
    }
82

    
83
    /**
84
     * {@inheritDoc}
85
     */
86
    @Override
87
    public Object displayToCanonicalValue(Object displayValue) {
88
        return null;
89
    }
90

    
91
}
(15-15/20)