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.term.Representation;
|
15
|
import eu.etaxonomy.cdm.model.description.Distribution;
|
16
|
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
|
17
|
import eu.etaxonomy.cdm.model.metadata.TermDisplayEnum;
|
18
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
19
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
20
|
|
21
|
/**
|
22
|
* @author k.luther
|
23
|
* @since 05.12.2018
|
24
|
*
|
25
|
*/
|
26
|
public class StatusDisplayConverter extends DisplayConverter{
|
27
|
public static final String DEFAULT_ENTRY = " ";
|
28
|
/**
|
29
|
* {@inheritDoc}
|
30
|
*/
|
31
|
@Override
|
32
|
public Object canonicalToDisplayValue(Object canonicalValue) {
|
33
|
if(canonicalValue instanceof Distribution){
|
34
|
Distribution distribution = (Distribution)canonicalValue;
|
35
|
if (distribution.getStatus() != null){
|
36
|
|
37
|
Representation rep = distribution.getStatus().getPreferredRepresentation(CdmStore.getDefaultLanguage());
|
38
|
String label = rep.getLabel();
|
39
|
|
40
|
if (label == null){
|
41
|
label = distribution.getStatus().getTitleCache();
|
42
|
}
|
43
|
if (PreferencesUtil.displayStatusInChecklistEditor() != null){
|
44
|
if(PreferencesUtil.displayStatusInChecklistEditor().equals(TermDisplayEnum.IdInVocabulary.getKey())){
|
45
|
return (StringUtils.isNotBlank(distribution.getStatus().getIdInVocabulary()))?distribution.getStatus().getIdInVocabulary():label;
|
46
|
}else if(PreferencesUtil.displayStatusInChecklistEditor().equals(TermDisplayEnum.Symbol1.getKey())){
|
47
|
|
48
|
return (StringUtils.isNotBlank(distribution.getStatus().getSymbol() ))?distribution.getStatus().getSymbol():label;
|
49
|
}else if(PreferencesUtil.displayStatusInChecklistEditor().equals(TermDisplayEnum.Symbol2.getKey())){
|
50
|
return (StringUtils.isNotBlank(distribution.getStatus().getSymbol2() ))?distribution.getStatus().getSymbol2():label;
|
51
|
}else{
|
52
|
return (label != null)?label:DEFAULT_ENTRY;
|
53
|
}
|
54
|
|
55
|
}else{
|
56
|
return (label != null)?label:DEFAULT_ENTRY;
|
57
|
}
|
58
|
}
|
59
|
|
60
|
return DEFAULT_ENTRY;
|
61
|
}else if(canonicalValue instanceof PresenceAbsenceTerm){
|
62
|
return ((PresenceAbsenceTerm)canonicalValue).getLabel();
|
63
|
} else if(canonicalValue!=null){
|
64
|
return canonicalValue.toString();
|
65
|
}
|
66
|
return null;
|
67
|
}
|
68
|
|
69
|
/**
|
70
|
* {@inheritDoc}
|
71
|
*/
|
72
|
@Override
|
73
|
public Object displayToCanonicalValue(Object displayValue) {
|
74
|
return null;
|
75
|
}
|
76
|
|
77
|
}
|