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.Taxon;
|
19
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
20
|
import eu.etaxonomy.taxeditor.editor.workingSet.matrix.CharacterMatrix;
|
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
|
*/
|
30
|
public class SupplementalInfoDisplayConverter extends DisplayConverter{
|
31
|
|
32
|
private CharacterMatrix matrix;
|
33
|
|
34
|
public SupplementalInfoDisplayConverter(CharacterMatrix matrix) {
|
35
|
this.matrix= matrix;
|
36
|
}
|
37
|
|
38
|
/**
|
39
|
* {@inheritDoc}
|
40
|
*/
|
41
|
@Override
|
42
|
public Object canonicalToDisplayValue(Object canonicalValue) {
|
43
|
String displayValue = "";
|
44
|
if(canonicalValue instanceof TaxonNode){
|
45
|
TaxonNode node = (TaxonNode)canonicalValue;
|
46
|
displayValue = node.getTaxon().getName().getTitleCache();
|
47
|
}
|
48
|
else if(canonicalValue instanceof Taxon){
|
49
|
if(matrix.isTreeView()){
|
50
|
return "---";
|
51
|
}
|
52
|
else {
|
53
|
Taxon taxon = (Taxon)canonicalValue;
|
54
|
displayValue = taxon.getName().getTitleCache();
|
55
|
}
|
56
|
}
|
57
|
else if(HibernateProxyHelper.isInstanceOf(canonicalValue, FieldUnit.class)){
|
58
|
FieldUnit fieldUnit = HibernateProxyHelper.deproxy(canonicalValue, FieldUnit.class);
|
59
|
GatheringEvent gatheringEvent = fieldUnit.getGatheringEvent();
|
60
|
if(gatheringEvent!=null){
|
61
|
AgentBase collector = gatheringEvent.getCollector();
|
62
|
if(collector!=null && collector.getTitleCache()!=null){
|
63
|
displayValue += collector.getTitleCache()+" ";
|
64
|
}
|
65
|
String fieldNumber = fieldUnit.getFieldNumber();
|
66
|
if(fieldNumber!=null){
|
67
|
displayValue += fieldNumber;
|
68
|
}
|
69
|
}
|
70
|
}
|
71
|
else if(HibernateProxyHelper.isInstanceOf(canonicalValue, NamedArea.class)){
|
72
|
displayValue = HibernateProxyHelper.deproxy(canonicalValue, NamedArea.class).getLabel();
|
73
|
}
|
74
|
|
75
|
if(displayValue.isEmpty() && canonicalValue!=null){
|
76
|
return canonicalValue.toString();
|
77
|
}
|
78
|
return displayValue;
|
79
|
}
|
80
|
|
81
|
/**
|
82
|
* {@inheritDoc}
|
83
|
*/
|
84
|
@Override
|
85
|
public Object displayToCanonicalValue(Object displayValue) {
|
86
|
return null;
|
87
|
}
|
88
|
|
89
|
}
|