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 java.util.ArrayList;
|
12
|
import java.util.List;
|
13
|
|
14
|
import eu.etaxonomy.cdm.model.common.Language;
|
15
|
import eu.etaxonomy.cdm.model.common.Representation;
|
16
|
import eu.etaxonomy.cdm.model.name.NameRelationshipType;
|
17
|
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
|
18
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
19
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
20
|
|
21
|
/**
|
22
|
* @author k.luther
|
23
|
* @since 15.10.2018
|
24
|
*
|
25
|
*/
|
26
|
public class InverseTermWrapper {
|
27
|
String label;
|
28
|
NameRelationshipType term;
|
29
|
boolean isInverse;
|
30
|
|
31
|
|
32
|
boolean useAbbrevLabel;
|
33
|
|
34
|
InverseTermWrapper(NameRelationshipType term, boolean isInverse, boolean useAbbrevLabel){
|
35
|
this.term = term;
|
36
|
this.isInverse = isInverse;
|
37
|
this.useAbbrevLabel = useAbbrevLabel;
|
38
|
if (isInverse){
|
39
|
this.label = getInverseLabel(term);
|
40
|
}else{
|
41
|
this.label = getLabel( term);
|
42
|
}
|
43
|
}
|
44
|
|
45
|
|
46
|
public NameRelationshipType getTerm() {
|
47
|
return term;
|
48
|
}
|
49
|
|
50
|
|
51
|
public void setTerm(NameRelationshipType term) {
|
52
|
this.term = term;
|
53
|
}
|
54
|
|
55
|
|
56
|
public String getLabel() {
|
57
|
return label;
|
58
|
}
|
59
|
|
60
|
|
61
|
public void setLabel(String label) {
|
62
|
this.label = label;
|
63
|
}
|
64
|
|
65
|
public boolean isInverse() {
|
66
|
return isInverse;
|
67
|
}
|
68
|
|
69
|
|
70
|
public void setInverse(boolean isInverse) {
|
71
|
this.isInverse = isInverse;
|
72
|
}
|
73
|
|
74
|
/**
|
75
|
* @param term
|
76
|
* @return
|
77
|
*/
|
78
|
private String getInverseLabel(NameRelationshipType term) {
|
79
|
if (term == null){
|
80
|
return "";
|
81
|
}else{
|
82
|
String termLabel = null;
|
83
|
List<Language> languages = new ArrayList();
|
84
|
|
85
|
languages.add(CdmStore.getDefaultLanguage());
|
86
|
Representation rep = term.getPreferredInverseRepresentation(languages);
|
87
|
if (useAbbrevLabel){
|
88
|
termLabel = rep.getAbbreviatedLabel();
|
89
|
if (termLabel == null){
|
90
|
termLabel = rep.getLabel();
|
91
|
}
|
92
|
|
93
|
}else{
|
94
|
termLabel = rep.getLabel();
|
95
|
}
|
96
|
if (termLabel == null){
|
97
|
termLabel = term.getInverseLabel();
|
98
|
}
|
99
|
|
100
|
return termLabel;
|
101
|
}
|
102
|
|
103
|
}
|
104
|
|
105
|
/**
|
106
|
* May be overridden by derived classes if the desired label string does not
|
107
|
* reside in term.getLabel();
|
108
|
*
|
109
|
* @param term
|
110
|
* a T object.
|
111
|
* @return a {@link java.lang.String} object.
|
112
|
*/
|
113
|
protected String getLabel(NameRelationshipType term) {
|
114
|
if (term == null){
|
115
|
return "";
|
116
|
}else{
|
117
|
String termLabel = null;
|
118
|
Representation rep = term.getPreferredRepresentation(CdmStore.getDefaultLanguage());
|
119
|
if (useAbbrevLabel){
|
120
|
termLabel = rep.getAbbreviatedLabel();
|
121
|
if (termLabel == null){
|
122
|
termLabel = rep.getLabel();
|
123
|
}
|
124
|
}else{
|
125
|
termLabel = rep.getLabel();
|
126
|
}
|
127
|
if (termLabel == null){
|
128
|
termLabel = term.getLabel();
|
129
|
}
|
130
|
if(PreferencesUtil.getBooleanValue(IPreferenceKeys.SHOW_VOCABULARY_ID_FOR_TERM_LABELS)
|
131
|
&& term.getVocabulary()!=null){
|
132
|
String vocLabel = term.getVocabulary().getLabel(CdmStore.getDefaultLanguage());
|
133
|
if (vocLabel == null){
|
134
|
vocLabel = term.getVocabulary().getLabel();
|
135
|
}
|
136
|
termLabel += " ["+vocLabel+"]";
|
137
|
}
|
138
|
return termLabel;
|
139
|
}
|
140
|
}
|
141
|
|
142
|
}
|