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;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.Collection;
|
13
|
import java.util.HashMap;
|
14
|
import java.util.Map;
|
15
|
import java.util.Set;
|
16
|
|
17
|
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
|
18
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
19
|
import eu.etaxonomy.cdm.model.description.CategoricalData;
|
20
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
21
|
import eu.etaxonomy.cdm.model.description.Feature;
|
22
|
import eu.etaxonomy.cdm.model.description.QuantitativeData;
|
23
|
import eu.etaxonomy.cdm.model.description.SpecimenDescription;
|
24
|
import eu.etaxonomy.cdm.model.description.State;
|
25
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
26
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
|
27
|
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
|
28
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
29
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
30
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
31
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
32
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
33
|
|
34
|
/**
|
35
|
* Wrapper object representing one row in the character matrix
|
36
|
* containing a specimen description and supplemental information
|
37
|
* about the taxon and the specimen
|
38
|
* @author pplitzner
|
39
|
* @since Dec 14, 2017
|
40
|
*
|
41
|
*/
|
42
|
public class RowWrapper {
|
43
|
|
44
|
private SpecimenDescription description;
|
45
|
|
46
|
private Taxon associatedTaxon;
|
47
|
private FieldUnit fieldUnit;
|
48
|
private String identifier;
|
49
|
private NamedArea country;
|
50
|
private Map<Feature, DescriptionElementBase> featureToElementMap = new HashMap<>();
|
51
|
|
52
|
public RowWrapper(SpecimenDescription description) {
|
53
|
this.description = description;
|
54
|
|
55
|
IOccurrenceService occurrenceService = CdmStore.getService(IOccurrenceService.class);
|
56
|
SpecimenOrObservationBase<?> specimen = HibernateProxyHelper.deproxy(description.getDescribedSpecimenOrObservation(), SpecimenOrObservationBase.class);
|
57
|
//supplemental information
|
58
|
if(specimen!=null){
|
59
|
Collection<TaxonBase<?>> associatedTaxa = occurrenceService.listAssociatedTaxa(specimen, null, null, null, null);
|
60
|
if(associatedTaxa!=null){
|
61
|
//FIXME: what about multiple associated taxa
|
62
|
associatedTaxon = (Taxon) associatedTaxa.iterator().next();
|
63
|
}
|
64
|
Collection<FieldUnit> fieldUnits = occurrenceService.getFieldUnits(specimen.getUuid());
|
65
|
if(fieldUnits.size()!=1){
|
66
|
MessagingUtils.error(RowWrapper.class, "More than one or no field unit found for specimen", null); //$NON-NLS-1$
|
67
|
}
|
68
|
else{
|
69
|
fieldUnit = fieldUnits.iterator().next();
|
70
|
}
|
71
|
if(specimen instanceof DerivedUnit){
|
72
|
identifier = occurrenceService.getMostSignificantIdentifier(HibernateProxyHelper.deproxy(specimen, DerivedUnit.class));
|
73
|
}
|
74
|
if(fieldUnit!=null && fieldUnit.getGatheringEvent()!=null){
|
75
|
country = fieldUnit.getGatheringEvent().getCountry();
|
76
|
}
|
77
|
}
|
78
|
//description elements
|
79
|
Set<DescriptionElementBase> elements = description.getElements();
|
80
|
for (DescriptionElementBase descriptionElementBase : elements) {
|
81
|
Feature feature = descriptionElementBase.getFeature();
|
82
|
featureToElementMap.put(feature, descriptionElementBase);
|
83
|
}
|
84
|
}
|
85
|
|
86
|
public QuantitativeData addQuantitativeData(Feature feature){
|
87
|
QuantitativeData data = QuantitativeData.NewInstance(feature);
|
88
|
description.addElement(data);
|
89
|
featureToElementMap.put(feature, data);
|
90
|
return data;
|
91
|
}
|
92
|
|
93
|
public CategoricalData addCategoricalData(Feature feature){
|
94
|
CategoricalData data = CategoricalData.NewInstance(feature);
|
95
|
description.addElement(data);
|
96
|
featureToElementMap.put(feature, data);
|
97
|
return data;
|
98
|
}
|
99
|
|
100
|
public SpecimenDescription getSpecimenDescription() {
|
101
|
return description;
|
102
|
}
|
103
|
|
104
|
public Taxon getAssociatedTaxon() {
|
105
|
return associatedTaxon;
|
106
|
}
|
107
|
|
108
|
public FieldUnit getFieldUnit() {
|
109
|
return fieldUnit;
|
110
|
}
|
111
|
|
112
|
public String getIdentifier() {
|
113
|
return identifier;
|
114
|
}
|
115
|
|
116
|
public NamedArea getCountry() {
|
117
|
return country;
|
118
|
}
|
119
|
|
120
|
public Object getDataValueForFeature(Feature feature){
|
121
|
DescriptionElementBase descriptionElementBase = featureToElementMap.get(feature);
|
122
|
return descriptionElementBase;
|
123
|
}
|
124
|
|
125
|
public void setDataValueForFeature(Feature feature, Object newValue){
|
126
|
/* Only CategoricalData is handled here because for QuantitativeData the value
|
127
|
* is set in the ModifyListener of the swt.Text in the CEllEditor
|
128
|
* for each StatisticalMeasure. So no need to set it again here.
|
129
|
*/
|
130
|
DescriptionElementBase descriptionElementBase = featureToElementMap.get(feature);
|
131
|
if(descriptionElementBase!=null && descriptionElementBase.isInstanceOf(CategoricalData.class) && newValue instanceof Collection){
|
132
|
CategoricalData categoricalData = HibernateProxyHelper.deproxy(descriptionElementBase, CategoricalData.class);
|
133
|
categoricalData.setStateDataOnly(new ArrayList<>((Collection<State>) newValue));
|
134
|
}
|
135
|
}
|
136
|
|
137
|
}
|