refactoring of package names for consistency
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / element / TimePeriodElement.java
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.element;
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
20 /**
21 * <p>
22 * TimePeriodElement class.
23 * </p>
24 *
25 * @author n.hoffmann
26 * @created Nov 17, 2009
27 * @version 1.0
28 */
29 public class TimePeriodElement extends AbstractCdmFormElement implements ISelectable {
30
31 private TimePeriod timePeriod;
32 private final Label label;
33 private final DateDetailSection section_dateDetails;
34
35 /**
36 * <p>
37 * Constructor for TimePeriodElement.
38 * </p>
39 *
40 * @param style
41 * a int.
42 * @param formFactory
43 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
44 * object.
45 * @param parentElement
46 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
47 * object.
48 * @param labelString
49 * a {@link java.lang.String} object.
50 * @param timePeriod
51 * a {@link eu.etaxonomy.cdm.model.common.TimePeriod} object.
52 */
53 public TimePeriodElement(CdmFormFactory formFactory,
54 ICdmFormElement parentElement, String labelString,
55 TimePeriod timePeriod, final int style) {
56 super(formFactory, parentElement);
57
58 label = formFactory.createLabel(getLayoutComposite(), labelString);
59 addControl(label);
60
61 section_dateDetails = formFactory.createDateDetailSection(this,
62 Section.TWISTIE);
63 addControl(section_dateDetails);
64
65 setTimePeriod(timePeriod);
66
67 formFactory.addPropertyChangeListener(this);
68 }
69
70 /**
71 * <p>
72 * setEntity
73 * </p>
74 *
75 * @param timePeriod
76 * a {@link eu.etaxonomy.cdm.model.common.TimePeriod} object.
77 */
78 public void setEntity(TimePeriod timePeriod) {
79 setTimePeriod(timePeriod);
80 }
81
82 /** {@inheritDoc} */
83 @Override
84 public void propertyChange(PropertyChangeEvent event) {
85 if (event == null) {
86 return;
87 }
88 Object eventSource = event.getSource();
89
90 if (getElements().contains(eventSource)) {
91 handleEvent(eventSource);
92 }
93 }
94
95 private void handleEvent(Object eventSource) {
96 if (eventSource == section_dateDetails) {
97 timePeriod = section_dateDetails.getEntity();
98 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
99 }
100 }
101
102 /**
103 * <p>
104 * Setter for the field <code>timePeriod</code>.
105 * </p>
106 *
107 * @param timePeriod
108 * the timePeriod to set
109 */
110 public void setTimePeriod(TimePeriod timePeriod) {
111 this.timePeriod = timePeriod;
112 if (timePeriod != null) {
113 section_dateDetails.setEntity(timePeriod);
114 }
115 }
116
117 /**
118 * <p>
119 * Getter for the field <code>timePeriod</code>.
120 * </p>
121 *
122 * @return the timePeriod
123 */
124 public TimePeriod getTimePeriod() {
125 return timePeriod;
126 }
127
128 /** {@inheritDoc} */
129 @Override
130 public void setBackground(Color color) {
131 label.setBackground(color);
132 section_dateDetails.setBackground(color);
133 }
134
135 @Override
136 public void setSelected(boolean selected) {
137 setBackground(selected ? SELECTED : getPersistentBackground());
138 }
139
140 public void setLabel(String string) {
141 label.setText(string);
142 }
143 }