1
|
/**
|
2
|
* Copyright (C) 2013 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
|
|
10
|
package eu.etaxonomy.taxeditor.ui.section.occurrence.dna;
|
11
|
|
12
|
import eu.etaxonomy.cdm.model.agent.AgentBase;
|
13
|
import eu.etaxonomy.cdm.model.agent.Institution;
|
14
|
import eu.etaxonomy.cdm.model.common.TimePeriod;
|
15
|
import eu.etaxonomy.cdm.model.molecular.DnaSample;
|
16
|
import eu.etaxonomy.cdm.model.occurrence.PreservationMethod;
|
17
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
18
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
19
|
import eu.etaxonomy.taxeditor.ui.element.NumberWithLabelElement;
|
20
|
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
|
21
|
import eu.etaxonomy.taxeditor.ui.element.TimePeriodElement;
|
22
|
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
|
23
|
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
|
24
|
|
25
|
/**
|
26
|
* @author pplitzner
|
27
|
* @date 16.12.2013
|
28
|
*
|
29
|
*/
|
30
|
public class DnaSamplePreparationPreservationDetailElement extends AbstractCdmDetailElement<DnaSample> {
|
31
|
|
32
|
private EntitySelectionElement<Institution> selectionInstitution;
|
33
|
private EntitySelectionElement<AgentBase> selectionStaff;
|
34
|
private TimePeriodElement datePreparationDate;
|
35
|
private NumberWithLabelElement numberPreservationTemperature;
|
36
|
private TextWithLabelElement txtMaterialOrMethods;
|
37
|
|
38
|
/**
|
39
|
* @param formFactory
|
40
|
* @param formElement
|
41
|
*/
|
42
|
public DnaSamplePreparationPreservationDetailElement(CdmFormFactory formFactory, ICdmFormElement formElement) {
|
43
|
super(formFactory, formElement);
|
44
|
}
|
45
|
|
46
|
/*
|
47
|
* (non-Javadoc)
|
48
|
*
|
49
|
* @see
|
50
|
* eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#createControls
|
51
|
* (eu.etaxonomy.taxeditor.forms.ICdmFormElement, java.lang.Object, int)
|
52
|
*/
|
53
|
@Override
|
54
|
protected void createControls(ICdmFormElement formElement, DnaSample entity, int style) {
|
55
|
Institution institution = null;
|
56
|
AgentBase<?> staff = null;
|
57
|
TimePeriod preparationDate = null;
|
58
|
if(entity.getDerivedFrom()!=null){
|
59
|
institution = entity.getDerivedFrom().getInstitution();
|
60
|
staff = entity.getDerivedFrom().getActor();
|
61
|
preparationDate = entity.getDerivedFrom().getTimeperiod();
|
62
|
}
|
63
|
|
64
|
Double temperature = null;
|
65
|
String materialOrMethodText = null;
|
66
|
if(entity.getPreservation()!=null){
|
67
|
temperature = entity.getPreservation().getTemperature();
|
68
|
}
|
69
|
if(entity.getDerivedFrom()!=null){
|
70
|
materialOrMethodText = entity.getDerivedFrom().getDescription();
|
71
|
}
|
72
|
selectionInstitution = formFactory.createSelectionElement(Institution.class, //getConversationHolder(),
|
73
|
formElement, "Institution", institution, EntitySelectionElement.ALL, style);
|
74
|
selectionStaff = formFactory.createSelectionElement(AgentBase.class, //getConversationHolder(),
|
75
|
formElement, "Staff", staff, EntitySelectionElement.ALL, style);
|
76
|
datePreparationDate = formFactory.createTimePeriodElement(formElement, "Preparation date", preparationDate, style);
|
77
|
numberPreservationTemperature = formFactory.createNumberTextWithLabelElement(formElement, "Preservation Temp. [C°]", temperature, style);
|
78
|
txtMaterialOrMethods = formFactory.createTextWithLabelElement(formElement, "Materials && Methods", materialOrMethodText, style);
|
79
|
|
80
|
}
|
81
|
|
82
|
/*
|
83
|
* (non-Javadoc)
|
84
|
*
|
85
|
* @see
|
86
|
* eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleEvent(java
|
87
|
* .lang.Object)
|
88
|
*/
|
89
|
@Override
|
90
|
public void handleEvent(Object eventSource) {
|
91
|
if(eventSource==datePreparationDate){
|
92
|
if(getEntity().getDerivedFrom()!=null){
|
93
|
getEntity().getDerivedFrom().setTimeperiod(datePreparationDate.getTimePeriod());
|
94
|
}
|
95
|
}
|
96
|
else if(eventSource==selectionInstitution){
|
97
|
if(getEntity().getDerivedFrom()!=null){
|
98
|
getEntity().getDerivedFrom().setInstitution(selectionInstitution.getSelection());
|
99
|
}
|
100
|
}
|
101
|
else if(eventSource==selectionStaff){
|
102
|
if(getEntity().getDerivedFrom()!=null){
|
103
|
getEntity().getDerivedFrom().setActor(selectionStaff.getSelection());
|
104
|
}
|
105
|
}
|
106
|
else if(eventSource==numberPreservationTemperature && numberPreservationTemperature.getText()!=null){
|
107
|
addPreservationMethod().setTemperature(numberPreservationTemperature.getDouble());
|
108
|
}
|
109
|
else if(eventSource==txtMaterialOrMethods && getEntity().getDerivedFrom()!=null){
|
110
|
getEntity().getDerivedFrom().setDescription(txtMaterialOrMethods.getText());
|
111
|
}
|
112
|
}
|
113
|
|
114
|
private PreservationMethod addPreservationMethod(){
|
115
|
PreservationMethod preservationMethod = getEntity().getPreservation();
|
116
|
if(preservationMethod==null){
|
117
|
preservationMethod = PreservationMethod.NewInstance();
|
118
|
getEntity().setPreservation(preservationMethod);
|
119
|
}
|
120
|
return preservationMethod;
|
121
|
}
|
122
|
}
|