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));
63 text_minVal
= formFactory
.createNumberTextWithLabelElement(this,
64 "Min : ", getMinimum(), style
);
66 text_maxVal
= formFactory
.createNumberTextWithLabelElement(this,
67 "Max : ", getMaximum(), style
);
69 text_freeText
= formFactory
.createTextWithLabelElement(this,
70 "Freetext : ", getFreetext(), style
);
72 formFactory
.addPropertyChangeListener(this);
77 * Setter for the field <code>timePeriod</code>.
81 * a {@link eu.etaxonomy.cdm.model.common.TimePeriod} object.
84 public void setEntity(DerivedUnitFacade gatheringEvent
) {
85 super.setEntity(gatheringEvent
);
89 private void updateValues() {
90 if(getEntity() != null) {
93 if(getEntity().getAbsoluteElevation() != null) {
94 text_minVal
.setNumber(getEntity().getAbsoluteElevation());
96 if(getEntity().getAbsoluteElevationMaximum() != null) {
97 text_maxVal
.setNumber(getEntity().getAbsoluteElevation());
99 if(getEntity().getAbsoluteElevationText() != null) {
100 text_freeText
.setText(getEntity().getAbsoluteElevationText());
104 if(getEntity().getDistanceToGround() != null) {
105 text_minVal
.setNumber(getEntity().getDistanceToGround());
107 if(getEntity().getDistanceToGroundMax() != null) {
108 text_maxVal
.setNumber(getEntity().getDistanceToGroundMax());
110 if(getEntity().getDistanceToGroundText() != null) {
111 text_freeText
.setText(getEntity().getDistanceToGroundText());
115 if(getEntity().getDistanceToWaterSurface() != null) {
116 text_minVal
.setNumber(getEntity().getDistanceToWaterSurface());
118 if(getEntity().getDistanceToWaterSurfaceMax() != null) {
119 text_maxVal
.setNumber(getEntity().getDistanceToWaterSurfaceMax());
121 if(getEntity().getDistanceToWaterSurfaceText() != null) {
122 text_freeText
.setText(getEntity().getDistanceToWaterSurfaceText());
133 public void propertyChange(PropertyChangeEvent event
) {
137 Object eventSource
= event
.getSource();
139 if (getElements().contains(eventSource
)) {
140 if (event
instanceof CdmPropertyChangeEvent
) {
141 if (((CdmPropertyChangeEvent
) event
).hasException()) {
142 handleException((CdmPropertyChangeEvent
) event
);
146 handleEvent(eventSource
);
153 private void handleException(CdmPropertyChangeEvent event
) {
154 firePropertyChangeEvent(new CdmPropertyChangeEvent(this,
155 event
.getException()));
158 private void handleEvent(Object eventSource
) {
159 if (eventSource
== text_minVal
) {
161 } else if (eventSource
== text_maxVal
) {
163 } else if (eventSource
== text_freeText
) {
166 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
174 * @see eu.etaxonomy.taxeditor.forms.AbstractFormSection#dispose()
178 public void dispose() {
179 formFactory
.removePropertyChangeListener(this);
183 private void updateMinimum() {
186 getEntity().setAbsoluteElevation(text_minVal
.getInteger());
189 getEntity().setDistanceToGround(text_minVal
.getDouble());
192 getEntity().setDistanceToWaterSurface(text_minVal
.getDouble());
197 private Number
getMinimum() {
198 if(getEntity() == null) {
203 return getEntity().getAbsoluteElevation();
205 return getEntity().getDistanceToGround();
207 return getEntity().getDistanceToWaterSurface();
212 private void updateMaximum() {
215 getEntity().setAbsoluteElevationMax(text_maxVal
.getInteger());
218 getEntity().setDistanceToGroundMax(text_maxVal
.getDouble());
221 getEntity().setDistanceToWaterSurfaceMax(text_maxVal
.getDouble());
226 private Number
getMaximum() {
227 if(getEntity() == null) {
232 return getEntity().getAbsoluteElevationMaximum();
234 return getEntity().getDistanceToGroundMax();
236 return getEntity().getDistanceToWaterSurfaceMax();
241 private void updateFreetext() {
244 getEntity().setAbsoluteElevationText(text_freeText
.getText());
247 getEntity().setDistanceToGroundText(text_freeText
.getText());
250 getEntity().setDistanceToWaterSurfaceText(text_freeText
.getText());
255 private String
getFreetext() {
256 if(getEntity() == null) {
261 return getEntity().getAbsoluteElevationText();
263 return getEntity().getDistanceToGroundText();
265 return getEntity().getDistanceToWaterSurfaceText();