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
;
16 import eu
.etaxonomy
.taxeditor
.ui
.campanula
.compatibility
.ICdmFormElement
;
20 * MinMaxTextSection class.
24 * @created 23 Jul 2013
27 public class MinMaxTextSection
extends AbstractFormSection
<DerivedUnitFacade
> {
29 private final TextWithLabelElement text_freeText
;
30 private final NumberWithLabelElement text_minVal
;
31 private final NumberWithLabelElement text_maxVal
;
32 private int cursorPosition
;
34 // unit types handled by this section
35 public enum UnitType
{
41 private UnitType unitType
= UnitType
.ELEVATION
;
45 * Constructor for DateDetailSection.
49 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
51 * @param parentElement
52 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
57 protected MinMaxTextSection(CdmFormFactory formFactory
,
58 ICdmFormElement parentElement
, UnitType unitType
, int style
) {
59 super(formFactory
, parentElement
, style
);
60 this.unitType
= unitType
;
61 getLayoutComposite().setLayout(LayoutConstants
.LAYOUT(2, false));
65 text_minVal
= formFactory
.createNumberTextWithLabelElement(this, "Min [m] : ", getMinimum(), style
);
66 text_maxVal
= formFactory
.createNumberTextWithLabelElement(this, "Max [m] : ", getMaximum(), style
);
69 text_minVal
= formFactory
.createNumberTextWithLabelElement(this, "Min [m] : ", getMinimum(), style
);
70 text_maxVal
= formFactory
.createNumberTextWithLabelElement(this, "Max [m] : ", getMaximum(), style
);
73 text_freeText
= formFactory
.createTextWithLabelElement(this,
74 "Freetext : ", getFreetext(), style
);
76 formFactory
.addPropertyChangeListener(this);
81 * Setter for the field <code>timePeriod</code>.
85 * a {@link eu.etaxonomy.cdm.model.common.TimePeriod} object.
88 public void setEntity(DerivedUnitFacade gatheringEvent
) {
89 super.setEntity(gatheringEvent
);
93 private void updateValues() {
94 if(getEntity() != null) {
97 if(getEntity().getAbsoluteElevation() != null) {
98 text_minVal
.setNumber(getEntity().getAbsoluteElevation());
100 if(getEntity().getAbsoluteElevationMaximum() != null) {
101 text_maxVal
.setNumber(getEntity().getAbsoluteElevation());
103 if(getEntity().getAbsoluteElevationText() != null) {
104 text_freeText
.setText(getEntity().getAbsoluteElevationText());
108 if(getEntity().getDistanceToGround() != null) {
109 text_minVal
.setNumber(getEntity().getDistanceToGround());
111 if(getEntity().getDistanceToGroundMax() != null) {
112 text_maxVal
.setNumber(getEntity().getDistanceToGroundMax());
114 if(getEntity().getDistanceToGroundText() != null) {
115 text_freeText
.setText(getEntity().getDistanceToGroundText());
119 if(getEntity().getDistanceToWaterSurface() != null) {
120 text_minVal
.setNumber(getEntity().getDistanceToWaterSurface());
122 if(getEntity().getDistanceToWaterSurfaceMax() != null) {
123 text_maxVal
.setNumber(getEntity().getDistanceToWaterSurfaceMax());
125 if(getEntity().getDistanceToWaterSurfaceText() != null) {
126 text_freeText
.setText(getEntity().getDistanceToWaterSurfaceText());
137 public void propertyChange(PropertyChangeEvent event
) {
141 Object eventSource
= event
.getSource();
143 if (getElements().contains(eventSource
)) {
144 if (event
instanceof CdmPropertyChangeEvent
) {
145 if (((CdmPropertyChangeEvent
) event
).hasException()) {
146 handleException((CdmPropertyChangeEvent
) event
);
150 handleEvent(eventSource
);
157 private void handleException(CdmPropertyChangeEvent event
) {
158 firePropertyChangeEvent(new CdmPropertyChangeEvent(this,
159 event
.getException()));
162 private void handleEvent(Object eventSource
) {
163 if (eventSource
== text_minVal
) {
165 } else if (eventSource
== text_maxVal
) {
167 } else if (eventSource
== text_freeText
) {
170 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
178 * @see eu.etaxonomy.taxeditor.forms.AbstractFormSection#dispose()
182 public void dispose() {
183 formFactory
.removePropertyChangeListener(this);
187 private void updateMinimum() {
190 getEntity().setAbsoluteElevation(text_minVal
.getDouble().intValue());
193 getEntity().setDistanceToGround(text_minVal
.getDouble());
196 getEntity().setDistanceToWaterSurface(text_minVal
.getDouble());
201 private Number
getMinimum() {
202 if(getEntity() == null) {
207 return getEntity().getAbsoluteElevation();
209 return getEntity().getDistanceToGround();
211 return getEntity().getDistanceToWaterSurface();
216 private void updateMaximum() {
219 getEntity().setAbsoluteElevationMax(text_maxVal
.getDouble().intValue());
222 getEntity().setDistanceToGroundMax(text_maxVal
.getDouble());
225 getEntity().setDistanceToWaterSurfaceMax(text_maxVal
.getDouble());
230 private Number
getMaximum() {
231 if(getEntity() == null) {
236 return getEntity().getAbsoluteElevationMaximum();
238 return getEntity().getDistanceToGroundMax();
240 return getEntity().getDistanceToWaterSurfaceMax();
245 private void updateFreetext() {
248 getEntity().setAbsoluteElevationText(text_freeText
.getText());
251 getEntity().setDistanceToGroundText(text_freeText
.getText());
254 getEntity().setDistanceToWaterSurfaceText(text_freeText
.getText());
259 private String
getFreetext() {
260 if(getEntity() == null) {
265 return getEntity().getAbsoluteElevationText();
267 return getEntity().getDistanceToGroundText();
269 return getEntity().getDistanceToWaterSurfaceText();