1
|
/**
|
2
|
* Copyright (C) 2018 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.ui.element;
|
10
|
|
11
|
import org.eclipse.swt.widgets.Text;
|
12
|
|
13
|
import eu.etaxonomy.cdm.model.common.TimePeriod;
|
14
|
import eu.etaxonomy.cdm.model.common.VerbatimTimePeriod;
|
15
|
|
16
|
/**
|
17
|
* @author k.luther
|
18
|
* @since 15.05.2018
|
19
|
*
|
20
|
*/
|
21
|
public class VerbatimDateDetailSection extends DateDetailSection {
|
22
|
|
23
|
|
24
|
private final TextWithLabelElement text_VerbatimDate;
|
25
|
|
26
|
/**
|
27
|
* <p>
|
28
|
* Constructor for DateDetailSection.
|
29
|
* </p>
|
30
|
*
|
31
|
* @param formFactory
|
32
|
* a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
|
33
|
* object.
|
34
|
* @param parentElement
|
35
|
* a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
|
36
|
* object.
|
37
|
* @param style
|
38
|
* a int.
|
39
|
*/
|
40
|
protected VerbatimDateDetailSection(CdmFormFactory formFactory,
|
41
|
ICdmFormElement parentElement, int style) {
|
42
|
super(formFactory, parentElement, style);
|
43
|
|
44
|
text_VerbatimDate = formFactory.createTextWithLabelElement(this,
|
45
|
"Verbatim Date", null, style);
|
46
|
|
47
|
text_VerbatimDate.getMainControl().setLayoutData(
|
48
|
LayoutConstants.FILL_HORIZONTALLY(6, 1));
|
49
|
|
50
|
|
51
|
formFactory.addPropertyChangeListener(this);
|
52
|
}
|
53
|
|
54
|
|
55
|
/**
|
56
|
* <p>
|
57
|
* Setter for the field <code>timePeriod</code>.
|
58
|
* </p>
|
59
|
*
|
60
|
* @param timePeriod
|
61
|
* a {@link eu.etaxonomy.cdm.model.common.TimePeriod} object.
|
62
|
*/
|
63
|
@Override
|
64
|
public void setEntity(TimePeriod timePeriod) {
|
65
|
setEntityInternally(timePeriod);
|
66
|
updateTitle();
|
67
|
getText_parseText().setText(timePeriod.toString());
|
68
|
if (timePeriod instanceof VerbatimTimePeriod){
|
69
|
text_VerbatimDate.setText(((VerbatimTimePeriod)timePeriod).getVerbatimDate());
|
70
|
}
|
71
|
}
|
72
|
@Override
|
73
|
protected void handleEvent(Object eventSource) {
|
74
|
|
75
|
if (eventSource == text_VerbatimDate) {
|
76
|
TimePeriod entity = getEntity();
|
77
|
if(entity instanceof VerbatimTimePeriod){
|
78
|
((VerbatimTimePeriod)entity).setVerbatimDate(text_VerbatimDate.getText());
|
79
|
}else{
|
80
|
VerbatimTimePeriod newEntity = VerbatimTimePeriod.NewVerbatimInstance();
|
81
|
newEntity.setEnd(entity.getEnd());
|
82
|
newEntity.setStart(entity.getStart());
|
83
|
newEntity.setFreeText(entity.getFreeText());
|
84
|
setEntity(newEntity);
|
85
|
((VerbatimTimePeriod)getEntity()).setVerbatimDate(text_VerbatimDate.getText());
|
86
|
}
|
87
|
}
|
88
|
super.handleEvent(eventSource);
|
89
|
|
90
|
}
|
91
|
|
92
|
@Override
|
93
|
public TimePeriod getEntity() {
|
94
|
if(super.getEntity() == null){
|
95
|
setEntity(VerbatimTimePeriod.NewVerbatimInstance());
|
96
|
}
|
97
|
return super.getEntity();
|
98
|
}
|
99
|
|
100
|
/**
|
101
|
* When setting the entity through parsing we do not want to alter the parse field
|
102
|
* @param timePeriod
|
103
|
*/
|
104
|
|
105
|
private void setEntityInternally(VerbatimTimePeriod timePeriod){
|
106
|
super.setEntityInternally(timePeriod);
|
107
|
((Text) text_VerbatimDate.getMainControl()).setSelection(super.getCursorPosition());
|
108
|
text_VerbatimDate.setText(timePeriod.getVerbatimDate());
|
109
|
super.setEntity(timePeriod);
|
110
|
}
|
111
|
|
112
|
}
|