2 * Copyright (C) 2018 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.ui
.element
;
11 import org
.eclipse
.swt
.widgets
.Text
;
13 import eu
.etaxonomy
.cdm
.model
.common
.TimePeriod
;
14 import eu
.etaxonomy
.cdm
.model
.common
.VerbatimTimePeriod
;
15 import eu
.etaxonomy
.cdm
.strategy
.parser
.TimePeriodParser
;
22 public class VerbatimDateDetailSection
extends DateDetailSectionBase
<VerbatimTimePeriod
> {
25 private final TextWithLabelElement text_VerbatimDate
;
29 * Constructor for DateDetailSection.
33 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
35 * @param parentElement
36 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
41 protected VerbatimDateDetailSection(CdmFormFactory formFactory
,
42 ICdmFormElement parentElement
, int style
) {
43 super(formFactory
, parentElement
, style
);
45 text_VerbatimDate
= formFactory
.createTextWithLabelElement(this,
46 "Verbatim Date", null, style
);
48 text_VerbatimDate
.getMainControl().setLayoutData(
49 LayoutConstants
.FILL_HORIZONTALLY(6, 1));
52 formFactory
.addPropertyChangeListener(this);
56 protected VerbatimTimePeriod
newInstance(){
57 return VerbatimTimePeriod
.NewVerbatimInstance();
60 protected VerbatimTimePeriod
parseNewInstance() {
61 VerbatimTimePeriod result
= TimePeriodParser
.parseStringVerbatim(getText_parseText().getText());
68 // * Setter for the field <code>timePeriod</code>.
71 // * @param timePeriod
72 // * a {@link eu.etaxonomy.cdm.model.common.TimePeriod} object.
75 // public void setEntity(VerbatimTimePeriod timePeriod) {
76 // setEntityInternally(timePeriod);
78 // getText_parseText().setText(timePeriod.toString());
83 protected void handleEvent(Object eventSource
) {
85 if (eventSource
== text_VerbatimDate
) {
86 TimePeriod entity
= getEntity();
87 if(entity
instanceof VerbatimTimePeriod
){
88 ((VerbatimTimePeriod
)entity
).setVerbatimDate(text_VerbatimDate
.getText());
90 VerbatimTimePeriod newEntity
= newInstance();
91 newEntity
.setEnd(entity
.getEnd());
92 newEntity
.setStart(entity
.getStart());
93 newEntity
.setFreeText(entity
.getFreeText());
94 newEntity
.setVerbatimDate(text_VerbatimDate
.getText());
98 super.handleEvent(eventSource
);
103 * When setting the entity through parsing we do not want to alter the parse field
107 protected void setEntityInternally(VerbatimTimePeriod timePeriod
){
108 super.setEntityInternally(timePeriod
);
109 ((Text
) text_VerbatimDate
.getMainControl()).setSelection(super.getCursorPosition());
110 text_VerbatimDate
.setText(timePeriod
.getVerbatimDate());
111 // super.setEntity(timePeriod);