1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.taxeditor.ui.forms;
|
12
|
|
13
|
import org.eclipse.jface.util.PropertyChangeEvent;
|
14
|
import org.eclipse.swt.graphics.Color;
|
15
|
import org.eclipse.swt.widgets.Label;
|
16
|
import org.eclipse.ui.forms.widgets.Section;
|
17
|
|
18
|
import eu.etaxonomy.cdm.model.common.TimePeriod;
|
19
|
import eu.etaxonomy.taxeditor.singlesource.ui.forms.CdmFormFactoryFacade;
|
20
|
|
21
|
/**
|
22
|
* <p>
|
23
|
* TimePeriodElement class.
|
24
|
* </p>
|
25
|
*
|
26
|
* @author n.hoffmann
|
27
|
* @created Nov 17, 2009
|
28
|
* @version 1.0
|
29
|
*/
|
30
|
public class TimePeriodElement extends AbstractCdmFormElement {
|
31
|
|
32
|
private TimePeriod timePeriod;
|
33
|
private final Label label;
|
34
|
private final DateDetailSection section_dateDetails;
|
35
|
|
36
|
/**
|
37
|
* <p>
|
38
|
* Constructor for TimePeriodElement.
|
39
|
* </p>
|
40
|
*
|
41
|
* @param style
|
42
|
* a int.
|
43
|
* @param formFactory
|
44
|
* a {@link eu.etaxonomy.taxeditor.singlesource.ui.forms.CdmFormFactoryFacade}
|
45
|
* object.
|
46
|
* @param parentElement
|
47
|
* a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
|
48
|
* object.
|
49
|
* @param labelString
|
50
|
* a {@link java.lang.String} object.
|
51
|
* @param timePeriod
|
52
|
* a {@link eu.etaxonomy.cdm.model.common.TimePeriod} object.
|
53
|
*/
|
54
|
public TimePeriodElement(CdmFormFactoryFacade formFactory,
|
55
|
ICdmFormElement parentElement, String labelString,
|
56
|
TimePeriod timePeriod, final int style) {
|
57
|
super(formFactory, parentElement);
|
58
|
|
59
|
label = formFactory.createLabel(getLayoutComposite(), labelString);
|
60
|
addControl(label);
|
61
|
|
62
|
section_dateDetails = formFactory.createDateDetailSection(this,
|
63
|
Section.TWISTIE);
|
64
|
addControl(section_dateDetails);
|
65
|
|
66
|
setTimePeriod(timePeriod);
|
67
|
|
68
|
formFactory.addPropertyChangeListener(this);
|
69
|
}
|
70
|
|
71
|
/** {@inheritDoc} */
|
72
|
@Override
|
73
|
public void setSelected(boolean selected) {
|
74
|
setBackground(getColor(selected));
|
75
|
}
|
76
|
|
77
|
/**
|
78
|
* <p>
|
79
|
* setEntity
|
80
|
* </p>
|
81
|
*
|
82
|
* @param timePeriod
|
83
|
* a {@link eu.etaxonomy.cdm.model.common.TimePeriod} object.
|
84
|
*/
|
85
|
public void setEntity(TimePeriod timePeriod) {
|
86
|
setTimePeriod(timePeriod);
|
87
|
}
|
88
|
|
89
|
/** {@inheritDoc} */
|
90
|
@Override
|
91
|
public void propertyChange(PropertyChangeEvent event) {
|
92
|
if (event == null) {
|
93
|
return;
|
94
|
}
|
95
|
Object eventSource = event.getSource();
|
96
|
|
97
|
if (getElements().contains(eventSource)) {
|
98
|
handleEvent(eventSource);
|
99
|
}
|
100
|
}
|
101
|
|
102
|
private void handleEvent(Object eventSource) {
|
103
|
|
104
|
// if(eventSource == text_freeText){
|
105
|
// String freeText = text_freeText.getText();
|
106
|
// timePeriod = TimePeriod.parseString(freeText);
|
107
|
// section_dateDetails.setEntity(timePeriod);
|
108
|
//
|
109
|
if (eventSource == section_dateDetails) {
|
110
|
timePeriod = section_dateDetails.getEntity();
|
111
|
firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
|
112
|
}
|
113
|
|
114
|
}
|
115
|
|
116
|
/**
|
117
|
* <p>
|
118
|
* Setter for the field <code>timePeriod</code>.
|
119
|
* </p>
|
120
|
*
|
121
|
* @param timePeriod
|
122
|
* the timePeriod to set
|
123
|
*/
|
124
|
public void setTimePeriod(TimePeriod timePeriod) {
|
125
|
this.timePeriod = timePeriod;
|
126
|
if (timePeriod != null) {
|
127
|
section_dateDetails.setEntity(timePeriod);
|
128
|
}
|
129
|
}
|
130
|
|
131
|
/**
|
132
|
* <p>
|
133
|
* Getter for the field <code>timePeriod</code>.
|
134
|
* </p>
|
135
|
*
|
136
|
* @return the timePeriod
|
137
|
*/
|
138
|
public TimePeriod getTimePeriod() {
|
139
|
return timePeriod;
|
140
|
}
|
141
|
|
142
|
/** {@inheritDoc} */
|
143
|
@Override
|
144
|
public void setBackground(Color color) {
|
145
|
label.setBackground(color);
|
146
|
section_dateDetails.setBackground(color);
|
147
|
}
|
148
|
|
149
|
public void setLabel(String string) {
|
150
|
label.setText(string);
|
151
|
}
|
152
|
}
|