1
|
/**
|
2
|
* Copyright (C) 2017 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.workingSet.matrix.supplementalInfo;
|
10
|
|
11
|
import org.eclipse.nebula.widgets.nattable.data.convert.DisplayConverter;
|
12
|
|
13
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
14
|
import eu.etaxonomy.cdm.model.agent.AgentBase;
|
15
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
16
|
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
|
17
|
import eu.etaxonomy.cdm.model.occurrence.GatheringEvent;
|
18
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
19
|
|
20
|
/**
|
21
|
* Converts the supplemental information (taxon and specimen data)
|
22
|
* belonging to a specimen description to a String.
|
23
|
*
|
24
|
* @author pplitzner
|
25
|
* @since Dec 14, 2017
|
26
|
*
|
27
|
*/
|
28
|
public class SupplementalInfoDisplayConverter extends DisplayConverter{
|
29
|
|
30
|
public SupplementalInfoDisplayConverter() {
|
31
|
}
|
32
|
|
33
|
/**
|
34
|
* {@inheritDoc}
|
35
|
*/
|
36
|
@Override
|
37
|
public Object canonicalToDisplayValue(Object canonicalValue) {
|
38
|
String displayValue = "";
|
39
|
if(HibernateProxyHelper.isInstanceOf(canonicalValue, TaxonNode.class)){
|
40
|
TaxonNode node = (TaxonNode)canonicalValue;
|
41
|
displayValue = node.getTaxon().getName().getTitleCache();
|
42
|
}
|
43
|
else if(HibernateProxyHelper.isInstanceOf(canonicalValue, FieldUnit.class)){
|
44
|
FieldUnit fieldUnit = HibernateProxyHelper.deproxy(canonicalValue, FieldUnit.class);
|
45
|
GatheringEvent gatheringEvent = fieldUnit.getGatheringEvent();
|
46
|
if(gatheringEvent!=null){
|
47
|
AgentBase collector = gatheringEvent.getCollector();
|
48
|
if(collector!=null && collector.getTitleCache()!=null){
|
49
|
displayValue += collector.getTitleCache()+" ";
|
50
|
}
|
51
|
String fieldNumber = fieldUnit.getFieldNumber();
|
52
|
if(fieldNumber!=null){
|
53
|
displayValue += fieldNumber;
|
54
|
}
|
55
|
}
|
56
|
}
|
57
|
else if(HibernateProxyHelper.isInstanceOf(canonicalValue, NamedArea.class)){
|
58
|
displayValue = HibernateProxyHelper.deproxy(canonicalValue, NamedArea.class).getLabel();
|
59
|
}
|
60
|
|
61
|
if(displayValue.isEmpty() && canonicalValue!=null){
|
62
|
return canonicalValue.toString();
|
63
|
}
|
64
|
return displayValue;
|
65
|
}
|
66
|
|
67
|
/**
|
68
|
* {@inheritDoc}
|
69
|
*/
|
70
|
@Override
|
71
|
public Object displayToCanonicalValue(Object displayValue) {
|
72
|
return null;
|
73
|
}
|
74
|
|
75
|
}
|