Project

General

Profile

Download (2.78 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.api.facade.DerivedUnitFacade;
19
import eu.etaxonomy.cdm.model.common.TimePeriod;
20
import eu.etaxonomy.cdm.model.occurrence.GatheringEvent;
21

    
22
/**
23
 * <p>
24
 * GatheringEventUnitElement class.
25
 * </p>
26
 * 
27
 * @author c.mathew
28
 * @created 23 Jul. 2013
29
 * @version 1.0
30
 */
31
public class GatheringEventUnitElement extends AbstractCdmFormElement implements ISelectable {
32
	
33
	private final Label label;
34
	private final MinMaxTextSection section_minMaxText;
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 GatheringEventUnitElement(CdmFormFactory formFactory,
55
			ICdmFormElement parentElement, 
56
			String labelString,
57
			DerivedUnitFacade gatheringEvent, 
58
			MinMaxTextSection.UnitType unitType,
59
			final int style) {
60
		super(formFactory, parentElement);
61

    
62
		label = formFactory.createLabel(getLayoutComposite(), labelString);
63
		addControl(label);
64

    
65
		section_minMaxText = formFactory.createMinMaxTextSection(this,
66
				unitType,
67
				Section.TWISTIE);
68
		
69
		addControl(section_minMaxText);	
70

    
71
		section_minMaxText.setEntity(gatheringEvent);
72
		
73
		formFactory.addPropertyChangeListener(this);
74
	}
75

    
76

    
77
	/** {@inheritDoc} */
78
	@Override
79
	public void propertyChange(PropertyChangeEvent event) {
80
		if (event == null) {
81
			return;
82
		}
83
		Object eventSource = event.getSource();
84

    
85
		if (getElements().contains(eventSource)) {
86
			handleEvent(eventSource);
87
		}
88
	}
89

    
90
	private void handleEvent(Object eventSource) {
91
		if (eventSource == section_minMaxText) {			
92
			firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
93
		}
94
	}
95

    
96
	/** {@inheritDoc} */
97
	@Override
98
	public void setBackground(Color color) {
99
		label.setBackground(color);
100
		section_minMaxText.setBackground(color);
101
	}
102
	
103
	@Override
104
	public void setSelected(boolean selected) {
105
		setBackground(selected ? SELECTED : getPersistentBackground());
106
	}
107

    
108
	public void setLabel(String string) {
109
		label.setText(string);
110
	}
111
}
112

    
(10-10/38)