3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.taxeditor
.ui
.element
;
13 import org
.eclipse
.jface
.util
.PropertyChangeEvent
;
15 import eu
.etaxonomy
.cdm
.api
.facade
.DerivedUnitFacade
;
19 * MinMaxTextSection class.
23 * @created 23 Jul 2013
26 public class MinMaxTextSection
extends AbstractFormSection
<DerivedUnitFacade
> {
28 private final TextWithLabelElement text_freeText
;
29 private final NumberWithLabelElement text_minVal
;
30 private final NumberWithLabelElement text_maxVal
;
31 private int cursorPosition
;
33 // unit types handled by this section
34 public enum UnitType
{
40 private UnitType unitType
= UnitType
.ELEVATION
;
44 * Constructor for DateDetailSection.
48 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
50 * @param parentElement
51 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
56 protected MinMaxTextSection(CdmFormFactory formFactory
,
57 ICdmFormElement parentElement
, UnitType unitType
, int style
) {
58 super(formFactory
, parentElement
, style
);
59 this.unitType
= unitType
;
60 getLayoutComposite().setLayout(LayoutConstants
.LAYOUT(2, false));
62 text_minVal
= formFactory
.createNumberTextWithLabelElement(this,
63 "Min : ", getMinimum(), style
);
65 text_maxVal
= formFactory
.createNumberTextWithLabelElement(this,
66 "Max : ", getMaximum(), style
);
68 text_freeText
= formFactory
.createTextWithLabelElement(this,
69 "Freetext : ", getFreetext(), style
);
71 formFactory
.addPropertyChangeListener(this);
76 * Setter for the field <code>timePeriod</code>.
80 * a {@link eu.etaxonomy.cdm.model.common.TimePeriod} object.
83 public void setEntity(DerivedUnitFacade gatheringEvent
) {
84 super.setEntity(gatheringEvent
);
88 private void updateValues() {
89 if(getEntity() != null) {
92 if(getEntity().getAbsoluteElevation() != null) {
93 text_minVal
.setNumber(getEntity().getAbsoluteElevation());
95 if(getEntity().getAbsoluteElevationMaximum() != null) {
96 text_maxVal
.setNumber(getEntity().getAbsoluteElevation());
98 if(getEntity().getAbsoluteElevationText() != null) {
99 text_freeText
.setText(getEntity().getAbsoluteElevationText());
103 if(getEntity().getDistanceToGround() != null) {
104 text_minVal
.setNumber(getEntity().getDistanceToGround());
106 if(getEntity().getDistanceToGroundMax() != null) {
107 text_maxVal
.setNumber(getEntity().getDistanceToGroundMax());
109 if(getEntity().getDistanceToGroundText() != null) {
110 text_freeText
.setText(getEntity().getDistanceToGroundText());
114 if(getEntity().getDistanceToWaterSurface() != null) {
115 text_minVal
.setNumber(getEntity().getDistanceToWaterSurface());
117 if(getEntity().getDistanceToWaterSurfaceMax() != null) {
118 text_maxVal
.setNumber(getEntity().getDistanceToWaterSurfaceMax());
120 if(getEntity().getDistanceToWaterSurfaceText() != null) {
121 text_freeText
.setText(getEntity().getDistanceToWaterSurfaceText());
132 public void propertyChange(PropertyChangeEvent event
) {
136 Object eventSource
= event
.getSource();
138 if (getElements().contains(eventSource
)) {
139 if (event
instanceof CdmPropertyChangeEvent
) {
140 if (((CdmPropertyChangeEvent
) event
).hasException()) {
141 handleException((CdmPropertyChangeEvent
) event
);
145 handleEvent(eventSource
);
152 private void handleException(CdmPropertyChangeEvent event
) {
153 firePropertyChangeEvent(new CdmPropertyChangeEvent(this,
154 event
.getException()));
157 private void handleEvent(Object eventSource
) {
158 if (eventSource
== text_minVal
) {
160 } else if (eventSource
== text_maxVal
) {
162 } else if (eventSource
== text_freeText
) {
165 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
173 * @see eu.etaxonomy.taxeditor.forms.AbstractFormSection#dispose()
177 public void dispose() {
178 formFactory
.removePropertyChangeListener(this);
182 private void updateMinimum() {
185 getEntity().setAbsoluteElevation(text_minVal
.getInteger());
188 getEntity().setDistanceToGround(text_minVal
.getDouble());
191 getEntity().setDistanceToWaterSurface(text_minVal
.getDouble());
196 private Number
getMinimum() {
197 if(getEntity() == null) {
202 return getEntity().getAbsoluteElevation();
204 return getEntity().getDistanceToGround();
206 return getEntity().getDistanceToWaterSurface();
211 private void updateMaximum() {
214 getEntity().setAbsoluteElevationMax(text_maxVal
.getInteger());
217 getEntity().setDistanceToGroundMax(text_maxVal
.getDouble());
220 getEntity().setDistanceToWaterSurfaceMax(text_maxVal
.getDouble());
225 private Number
getMaximum() {
226 if(getEntity() == null) {
231 return getEntity().getAbsoluteElevationMaximum();
233 return getEntity().getDistanceToGroundMax();
235 return getEntity().getDistanceToWaterSurfaceMax();
240 private void updateFreetext() {
243 getEntity().setAbsoluteElevationText(text_freeText
.getText());
246 getEntity().setDistanceToGroundText(text_freeText
.getText());
249 getEntity().setDistanceToWaterSurfaceText(text_freeText
.getText());
254 private String
getFreetext() {
255 if(getEntity() == null) {
260 return getEntity().getAbsoluteElevationText();
262 return getEntity().getDistanceToGroundText();
264 return getEntity().getDistanceToWaterSurfaceText();