Project

General

Profile

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