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
.element
;
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
;
19 import eu
.etaxonomy
.taxeditor
.ui
.campanula
.compatibility
.ICdmFormElement
;
23 * TimePeriodElement class.
27 * @created Nov 17, 2009
30 public class TimePeriodElement
extends AbstractCdmFormElement
implements ISelectable
{
32 private TimePeriod timePeriod
;
33 private final Label label
;
34 private final DateDetailSection section_dateDetails
;
38 * Constructor for TimePeriodElement.
44 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
46 * @param parentElement
47 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
50 * a {@link java.lang.String} object.
52 * a {@link eu.etaxonomy.cdm.model.common.TimePeriod} object.
54 public TimePeriodElement(CdmFormFactory formFactory
,
55 ICdmFormElement parentElement
, String labelString
,
56 TimePeriod timePeriod
, final int style
) {
57 super(formFactory
, parentElement
);
59 label
= formFactory
.createLabel(getLayoutComposite(), labelString
);
62 section_dateDetails
= formFactory
.createDateDetailSection(this,
64 addControl(section_dateDetails
);
66 setTimePeriod(timePeriod
);
68 formFactory
.addPropertyChangeListener(this);
77 * a {@link eu.etaxonomy.cdm.model.common.TimePeriod} object.
79 public void setEntity(TimePeriod timePeriod
) {
80 setTimePeriod(timePeriod
);
85 public void propertyChange(PropertyChangeEvent event
) {
89 Object eventSource
= event
.getSource();
91 if (getElements().contains(eventSource
)) {
92 handleEvent(eventSource
);
96 private void handleEvent(Object eventSource
) {
97 if (eventSource
== section_dateDetails
) {
98 timePeriod
= section_dateDetails
.getEntity();
99 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
105 * Setter for the field <code>timePeriod</code>.
109 * the timePeriod to set
111 public void setTimePeriod(TimePeriod timePeriod
) {
112 this.timePeriod
= timePeriod
;
113 if (timePeriod
!= null) {
114 section_dateDetails
.setEntity(timePeriod
);
120 * Getter for the field <code>timePeriod</code>.
123 * @return the timePeriod
125 public TimePeriod
getTimePeriod() {
131 public void setBackground(Color color
) {
132 label
.setBackground(color
);
133 section_dateDetails
.setBackground(color
);
137 public void setSelected(boolean selected
) {
138 setBackground(selected ? SELECTED
: getPersistentBackground());
141 public void setLabel(String string
) {
142 label
.setText(string
);