Unify product files
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / element / VerbatimDateDetailSection.java
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 import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
16
17 /**
18 * @author k.luther
19 * @since 15.05.2018
20 *
21 */
22 public class VerbatimDateDetailSection extends DateDetailSectionBase<VerbatimTimePeriod> {
23
24
25 private final TextWithLabelElement text_VerbatimDate;
26
27 /**
28 * <p>
29 * Constructor for DateDetailSection.
30 * </p>
31 *
32 * @param formFactory
33 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
34 * object.
35 * @param parentElement
36 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
37 * object.
38 * @param style
39 * a int.
40 */
41 protected VerbatimDateDetailSection(CdmFormFactory formFactory,
42 ICdmFormElement parentElement, int style) {
43 super(formFactory, parentElement, style);
44
45 text_VerbatimDate = formFactory.createTextWithLabelElement(this,
46 "Verbatim Date", null, style);
47
48 text_VerbatimDate.getMainControl().setLayoutData(
49 LayoutConstants.FILL_HORIZONTALLY(6, 1));
50
51
52 formFactory.addPropertyChangeListener(this);
53 }
54
55 @Override
56 protected VerbatimTimePeriod newInstance(){
57 return VerbatimTimePeriod.NewVerbatimInstance();
58 }
59
60 protected VerbatimTimePeriod parseNewInstance() {
61 VerbatimTimePeriod result = TimePeriodParser.parseStringVerbatim(getText_parseText().getText());
62 return result;
63 }
64
65 //
66 // /**
67 // * <p>
68 // * Setter for the field <code>timePeriod</code>.
69 // * </p>
70 // *
71 // * @param timePeriod
72 // * a {@link eu.etaxonomy.cdm.model.common.TimePeriod} object.
73 // */
74 //
75 // public void setEntity(VerbatimTimePeriod timePeriod) {
76 // setEntityInternally(timePeriod);
77 // updateTitle();
78 // getText_parseText().setText(timePeriod.toString());
79 //
80 // }
81
82 @Override
83 protected void handleEvent(Object eventSource) {
84
85 if (eventSource == text_VerbatimDate) {
86 TimePeriod entity = getEntity();
87 if(entity instanceof VerbatimTimePeriod){
88 ((VerbatimTimePeriod)entity).setVerbatimDate(text_VerbatimDate.getText());
89 }else{
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());
95 setEntity(newEntity);
96 }
97 }
98 super.handleEvent(eventSource);
99
100 }
101
102 /**
103 * When setting the entity through parsing we do not want to alter the parse field
104 * @param timePeriod
105 */
106 @Override
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);
112 }
113
114 }