Project

General

Profile

Download (3.4 KB) Statistics
| Branch: | Tag: | Revision:
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
import eu.etaxonomy.taxeditor.ui.section.campanula.compatibility.ICdmFormElement;
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 implements ISelectable {
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.ui.element.CdmFormFactory}
45
	 *            object.
46
	 * @param parentElement
47
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.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(CdmFormFactory 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
	/**
72
	 * <p>
73
	 * setEntity
74
	 * </p>
75
	 * 
76
	 * @param timePeriod
77
	 *            a {@link eu.etaxonomy.cdm.model.common.TimePeriod} object.
78
	 */
79
	public void setEntity(TimePeriod timePeriod) {
80
		setTimePeriod(timePeriod);
81
	}
82

    
83
	/** {@inheritDoc} */
84
	@Override
85
	public void propertyChange(PropertyChangeEvent event) {
86
		if (event == null) {
87
			return;
88
		}
89
		Object eventSource = event.getSource();
90

    
91
		if (getElements().contains(eventSource)) {
92
			handleEvent(eventSource);
93
		}
94
	}
95

    
96
	private void handleEvent(Object eventSource) {
97
		if (eventSource == section_dateDetails) {
98
			timePeriod = section_dateDetails.getEntity();
99
			firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
100
		}
101
	}
102

    
103
	/**
104
	 * <p>
105
	 * Setter for the field <code>timePeriod</code>.
106
	 * </p>
107
	 * 
108
	 * @param timePeriod
109
	 *            the timePeriod to set
110
	 */
111
	public void setTimePeriod(TimePeriod timePeriod) {
112
		this.timePeriod = timePeriod;
113
		if (timePeriod != null) {
114
			section_dateDetails.setEntity(timePeriod);
115
		}
116
	}
117

    
118
	/**
119
	 * <p>
120
	 * Getter for the field <code>timePeriod</code>.
121
	 * </p>
122
	 * 
123
	 * @return the timePeriod
124
	 */
125
	public TimePeriod getTimePeriod() {
126
		return timePeriod;
127
	}
128

    
129
	/** {@inheritDoc} */
130
	@Override
131
	public void setBackground(Color color) {
132
		label.setBackground(color);
133
		section_dateDetails.setBackground(color);
134
	}
135
	
136
	@Override
137
	public void setSelected(boolean selected) {
138
		setBackground(selected ? SELECTED : getPersistentBackground());
139
	}
140

    
141
	public void setLabel(String string) {
142
		label.setText(string);
143
	}
144
}
(33-33/35)