3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.taxeditor
.ui
.forms
;
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
;
18 import eu
.etaxonomy
.cdm
.model
.common
.TimePeriod
;
22 * TimePeriodElement class.
26 * @created Nov 17, 2009
29 public class TimePeriodElement
extends AbstractCdmFormElement
{
31 private TimePeriod timePeriod
;
32 private final Label label
;
33 private final DateDetailSection section_dateDetails
;
37 * Constructor for TimePeriodElement.
43 * a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory}
45 * @param parentElement
46 * a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
49 * a {@link java.lang.String} object.
51 * a {@link eu.etaxonomy.cdm.model.common.TimePeriod} object.
53 public TimePeriodElement(CdmFormFactory formFactory
,
54 ICdmFormElement parentElement
, String labelString
,
55 TimePeriod timePeriod
, final int style
) {
56 super(formFactory
, parentElement
);
58 label
= formFactory
.createLabel(getLayoutComposite(), labelString
);
61 section_dateDetails
= formFactory
.createDateDetailSection(this,
63 addControl(section_dateDetails
);
65 setTimePeriod(timePeriod
);
67 formFactory
.addPropertyChangeListener(this);
72 public void setSelected(boolean selected
) {
73 setBackground(getColor(selected
));
82 * a {@link eu.etaxonomy.cdm.model.common.TimePeriod} object.
84 public void setEntity(TimePeriod timePeriod
) {
85 setTimePeriod(timePeriod
);
90 public void propertyChange(PropertyChangeEvent event
) {
94 Object eventSource
= event
.getSource();
96 if (getElements().contains(eventSource
)) {
97 handleEvent(eventSource
);
101 private void handleEvent(Object eventSource
) {
103 // if(eventSource == text_freeText){
104 // String freeText = text_freeText.getText();
105 // timePeriod = TimePeriod.parseString(freeText);
106 // section_dateDetails.setEntity(timePeriod);
108 if (eventSource
== section_dateDetails
) {
109 timePeriod
= section_dateDetails
.getEntity();
110 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
117 * Setter for the field <code>timePeriod</code>.
121 * the timePeriod to set
123 public void setTimePeriod(TimePeriod timePeriod
) {
124 this.timePeriod
= timePeriod
;
125 if (timePeriod
!= null) {
126 section_dateDetails
.setEntity(timePeriod
);
132 * Getter for the field <code>timePeriod</code>.
135 * @return the timePeriod
137 public TimePeriod
getTimePeriod() {
143 public void setBackground(Color color
) {
144 label
.setBackground(color
);
145 section_dateDetails
.setBackground(color
);