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