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 java.util.HashSet;
|
12
|
import java.util.Iterator;
|
13
|
|
14
|
import org.apache.commons.lang3.StringUtils;
|
15
|
import org.eclipse.nebula.widgets.nattable.data.convert.DisplayConverter;
|
16
|
|
17
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
18
|
import eu.etaxonomy.cdm.model.description.Distribution;
|
19
|
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
|
20
|
import eu.etaxonomy.cdm.model.metadata.TermDisplayEnum;
|
21
|
import eu.etaxonomy.cdm.model.term.Representation;
|
22
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
23
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
24
|
|
25
|
/**
|
26
|
* @author k.luther
|
27
|
* @since 05.12.2018
|
28
|
*
|
29
|
*/
|
30
|
public class StatusDisplayConverter extends DisplayConverter{
|
31
|
public static final String DEFAULT_ENTRY = " ";
|
32
|
/**
|
33
|
* {@inheritDoc}
|
34
|
*/
|
35
|
@Override
|
36
|
public Object canonicalToDisplayValue(Object canonicalValue) {
|
37
|
if(canonicalValue instanceof Distribution){
|
38
|
Distribution distribution = HibernateProxyHelper.deproxy(canonicalValue, Distribution.class);
|
39
|
return extractStatusString(distribution);
|
40
|
|
41
|
}else if(canonicalValue instanceof PresenceAbsenceTerm){
|
42
|
return ((PresenceAbsenceTerm)canonicalValue).getLabel();
|
43
|
} else if(canonicalValue instanceof HashSet<?>){
|
44
|
HashSet<Distribution> statusSet = (HashSet<Distribution>) canonicalValue;
|
45
|
Iterator<Distribution> status = statusSet.iterator();
|
46
|
String result = "";
|
47
|
while(status.hasNext()){
|
48
|
result= extractStatusString(status.next()) + ", " +result ;
|
49
|
}
|
50
|
result = result.substring(0, result.length() - 2);
|
51
|
return result;
|
52
|
}else if (canonicalValue != null){
|
53
|
return canonicalValue.toString();
|
54
|
}
|
55
|
return null;
|
56
|
}
|
57
|
|
58
|
/**
|
59
|
* {@inheritDoc}
|
60
|
*/
|
61
|
@Override
|
62
|
public Object displayToCanonicalValue(Object displayValue) {
|
63
|
return null;
|
64
|
}
|
65
|
|
66
|
public Object extractStatusString(Object distribution) {
|
67
|
PresenceAbsenceTerm status = null;
|
68
|
if (distribution instanceof Distribution){
|
69
|
status = HibernateProxyHelper.deproxy(((Distribution)distribution).getStatus(), PresenceAbsenceTerm.class);
|
70
|
}
|
71
|
// if (distribution instanceof String){
|
72
|
// status = (PresenceAbsenceTerm)distribution;
|
73
|
// }
|
74
|
if (status == null){
|
75
|
return DEFAULT_ENTRY;
|
76
|
}
|
77
|
|
78
|
Representation rep = status.getPreferredRepresentation(CdmStore.getDefaultLanguage());
|
79
|
String label = rep.getLabel();
|
80
|
|
81
|
if (label == null){
|
82
|
label = status.getTitleCache();
|
83
|
}
|
84
|
if (PreferencesUtil.displayStatusInChecklistEditor() != null){
|
85
|
if(PreferencesUtil.displayStatusInChecklistEditor().equals(TermDisplayEnum.IdInVocabulary)){
|
86
|
|
87
|
return (StringUtils.isNotBlank(status.getIdInVocabulary()))?status.getIdInVocabulary():label;
|
88
|
}else if(PreferencesUtil.displayStatusInChecklistEditor().equals(TermDisplayEnum.Symbol1)){
|
89
|
|
90
|
return (StringUtils.isNotBlank(status.getSymbol() ))?status.getSymbol():label;
|
91
|
}else if(PreferencesUtil.displayStatusInChecklistEditor().equals(TermDisplayEnum.Symbol2)){
|
92
|
return (StringUtils.isNotBlank(status.getSymbol2() ))?status.getSymbol2():label;
|
93
|
}else{
|
94
|
return (label != null)?label:DEFAULT_ENTRY;
|
95
|
}
|
96
|
|
97
|
}else{
|
98
|
return (label != null)?label:DEFAULT_ENTRY;
|
99
|
}
|
100
|
}
|
101
|
|
102
|
}
|