Project

General

Profile

Download (3.23 KB) Statistics
| Branch: | Tag: | Revision:
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

    
64
    public void setEntity(VerbatimTimePeriod timePeriod) {
65
        setEntityInternally(timePeriod);
66
        updateTitle();
67
        getText_parseText().setText(timePeriod.toString());
68

    
69
    }
70
    @Override
71
    protected void handleEvent(Object eventSource) {
72

    
73
        if (eventSource == text_VerbatimDate) {
74
            TimePeriod entity = getEntity();
75
            if(entity instanceof VerbatimTimePeriod){
76
                ((VerbatimTimePeriod)entity).setVerbatimDate(text_VerbatimDate.getText());
77
            }else{
78
                VerbatimTimePeriod newEntity = VerbatimTimePeriod.NewVerbatimInstance();
79
                newEntity.setEnd(entity.getEnd());
80
                newEntity.setStart(entity.getStart());
81
                newEntity.setFreeText(entity.getFreeText());
82
                newEntity.setVerbatimDate(text_VerbatimDate.getText());
83
                setEntity(newEntity);
84

    
85
            }
86
        }
87
        super.handleEvent(eventSource);
88

    
89
    }
90

    
91
    @Override
92
    public TimePeriod getEntity() {
93
        if(super.getEntity() == null){
94
            setEntity(VerbatimTimePeriod.NewVerbatimInstance());
95
        }
96
        return super.getEntity();
97
    }
98

    
99
    /**
100
     * When setting the entity through parsing we do not want to alter the parse field
101
     * @param timePeriod
102
     */
103

    
104
    private void setEntityInternally(VerbatimTimePeriod timePeriod){
105
        super.setEntityInternally(timePeriod);
106
        ((Text) text_VerbatimDate.getMainControl()).setSelection(super.getCursorPosition());
107
        text_VerbatimDate.setText(timePeriod.getVerbatimDate());
108
        super.setEntity(timePeriod);
109
    }
110

    
111
}
(46-46/47)