merge-update from trunk
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / element / GatheringEventUnitElement.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.api.facade.DerivedUnitFacade;
19 import eu.etaxonomy.taxeditor.ui.campanula.compatibility.ICdmFormElement;
20
21 /**
22 * <p>
23 * GatheringEventUnitElement class.
24 * </p>
25 *
26 * @author c.mathew
27 * @created 23 Jul. 2013
28 * @version 1.0
29 */
30 public class GatheringEventUnitElement extends AbstractCdmFormElement implements ISelectable {
31
32 private final Label label;
33 private final MinMaxTextSection section_minMaxText;
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 GatheringEventUnitElement(CdmFormFactory formFactory,
54 ICdmFormElement parentElement,
55 String labelString,
56 DerivedUnitFacade gatheringEvent,
57 MinMaxTextSection.UnitType unitType,
58 final int style) {
59 super(formFactory, parentElement);
60
61 label = formFactory.createLabel(getLayoutComposite(), labelString);
62 addControl(label);
63
64 section_minMaxText = formFactory.createMinMaxTextSection(this,
65 unitType,
66 Section.TWISTIE);
67
68 addControl(section_minMaxText);
69
70 section_minMaxText.setEntity(gatheringEvent);
71
72 formFactory.addPropertyChangeListener(this);
73 }
74
75
76 /** {@inheritDoc} */
77 @Override
78 public void propertyChange(PropertyChangeEvent event) {
79 if (event == null) {
80 return;
81 }
82 Object eventSource = event.getSource();
83
84 if (getElements().contains(eventSource)) {
85 handleEvent(eventSource);
86 }
87 }
88
89 private void handleEvent(Object eventSource) {
90 if (eventSource == section_minMaxText) {
91 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
92 }
93 }
94
95 /** {@inheritDoc} */
96 @Override
97 public void setBackground(Color color) {
98 label.setBackground(color);
99 section_minMaxText.setBackground(color);
100 }
101
102 @Override
103 public void setSelected(boolean selected) {
104 setBackground(selected ? SELECTED : getPersistentBackground());
105 }
106
107 public void setLabel(String string) {
108 label.setText(string);
109 }
110 }
111