Project

General

Profile

Download (3.19 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.ui.combo;
10

    
11
import eu.etaxonomy.cdm.model.name.NameRelationshipType;
12
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
13
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
14
import eu.etaxonomy.taxeditor.store.CdmStore;
15

    
16
/**
17
 * @author k.luther
18
 * @since 15.10.2018
19
 *
20
 */
21
public class InverseTermWrapper {
22
    String label;
23
    NameRelationshipType term;
24
    boolean isInverse;
25

    
26

    
27
    boolean useAbbrevLabel;
28

    
29
    InverseTermWrapper(NameRelationshipType term, boolean isInverse, boolean useAbbrevLabel){
30
        this.term = term;
31
        this.isInverse = isInverse;
32
        this.useAbbrevLabel = useAbbrevLabel;
33
        if (isInverse){
34
            this.label = getInverseLabel(term);
35
        }else{
36
            this.label = getLabel( term);
37
        }
38
    }
39

    
40

    
41
    public NameRelationshipType getTerm() {
42
        return term;
43
    }
44

    
45

    
46
    public void setTerm(NameRelationshipType term) {
47
        this.term = term;
48
    }
49

    
50

    
51
    public String getLabel() {
52
        return label;
53
    }
54

    
55

    
56
    public void setLabel(String label) {
57
        this.label = label;
58
    }
59

    
60
    public boolean isInverse() {
61
        return isInverse;
62
    }
63

    
64

    
65
    public void setInverse(boolean isInverse) {
66
        this.isInverse = isInverse;
67
    }
68

    
69
    /**
70
     * @param term
71
     * @return
72
     */
73
    private String getInverseLabel(NameRelationshipType term) {
74
        if (term == null){
75
            return "";
76
        }else{
77
            String termLabel = null;
78
            if (useAbbrevLabel){
79
                termLabel = term.getInverseSymbol();
80
            }else{
81
                termLabel = term.getInverseLabel(CdmStore.getDefaultLanguage());
82
            }
83
            if (termLabel == null){
84
                termLabel = term.getInverseLabel();
85
            }
86

    
87
            return termLabel;
88
        }
89

    
90
    }
91

    
92
    /**
93
     * May be overridden by derived classes if the desired label string does not
94
     * reside in term.getLabel();
95
     *
96
     * @param term
97
     *            a T object.
98
     * @return a {@link java.lang.String} object.
99
     */
100
    protected String getLabel(NameRelationshipType term) {
101
        if (term == null){
102
            return "";
103
        }else{
104
            String termLabel = null;
105
            if (useAbbrevLabel){
106
                termLabel = term.getIdInVocabulary();
107
            }else{
108
                termLabel = term.getLabel(CdmStore.getDefaultLanguage());
109
            }
110
            if (termLabel == null){
111
                termLabel = term.getLabel();
112
            }
113
            if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_VOCABULARY_ID_FOR_TERM_LABELS)
114
                && term.getVocabulary()!=null){
115
                String vocLabel = term.getVocabulary().getLabel(CdmStore.getDefaultLanguage());
116
                if (vocLabel == null){
117
                    vocLabel = term.getVocabulary().getLabel();
118
                }
119
                termLabel += " ["+vocLabel+"]";
120
            }
121
            return termLabel;
122
        }
123
    }
124

    
125
}
(4-4/11)