2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.taxeditor
.ui
.element
;
11 import org
.eclipse
.jface
.util
.PropertyChangeEvent
;
13 import eu
.etaxonomy
.cdm
.facade
.DerivedUnitFacade
;
18 * @created 23 Jul 2013
20 public class MinMaxTextSection
extends AbstractFormSection
<DerivedUnitFacade
> {
22 private final TextWithLabelElement text_freeText
;
23 private final NumberWithLabelElement text_minVal
;
24 private final NumberWithLabelElement text_maxVal
;
25 private int cursorPosition
;
27 // unit types handled by this section
28 public enum UnitType
{
34 private UnitType unitType
= UnitType
.ELEVATION
;
38 * Constructor for DateDetailSection.
42 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
44 * @param parentElement
45 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
50 protected MinMaxTextSection(CdmFormFactory formFactory
,
51 ICdmFormElement parentElement
, UnitType unitType
, int style
) {
52 super(formFactory
, parentElement
, style
);
53 this.unitType
= unitType
;
54 getLayoutComposite().setLayout(LayoutConstants
.LAYOUT(2, false));
58 text_minVal
= formFactory
.createFloatTextWithLabelElement(this, "Min [m] : ", getMinimum(), style
);
59 text_maxVal
= formFactory
.createFloatTextWithLabelElement(this, "Max [m] : ", getMaximum(), style
);
62 text_minVal
= formFactory
.createFloatTextWithLabelElement(this, "Min [m] : ", getMinimum(), style
);
63 text_maxVal
= formFactory
.createFloatTextWithLabelElement(this, "Max [m] : ", getMaximum(), style
);
66 text_freeText
= formFactory
.createTextWithLabelElement(this,
67 "Freetext : ", getFreetext(), style
);
69 formFactory
.addPropertyChangeListener(this);
73 public void setEntity(DerivedUnitFacade gatheringEvent
) {
74 super.setEntity(gatheringEvent
);
79 private void updateValues() {
80 if(getEntity() != null) {
83 if(getEntity().getAbsoluteElevation() != null) {
84 text_minVal
.setNumber(getEntity().getAbsoluteElevation());
86 if(getEntity().getAbsoluteElevationMaximum() != null) {
87 text_maxVal
.setNumber(getEntity().getAbsoluteElevationMaximum());
89 if(getEntity().getAbsoluteElevationText() != null) {
90 text_freeText
.setText(getEntity().getAbsoluteElevationText());
94 if(getEntity().getDistanceToGround() != null) {
95 text_minVal
.setNumber(getEntity().getDistanceToGround());
97 if(getEntity().getDistanceToGroundMax() != null) {
98 text_maxVal
.setNumber(getEntity().getDistanceToGroundMax());
100 if(getEntity().getDistanceToGroundText() != null) {
101 text_freeText
.setText(getEntity().getDistanceToGroundText());
105 if(getEntity().getDistanceToWaterSurface() != null) {
106 text_minVal
.setNumber(getEntity().getDistanceToWaterSurface());
108 if(getEntity().getDistanceToWaterSurfaceMax() != null) {
109 text_maxVal
.setNumber(getEntity().getDistanceToWaterSurfaceMax());
111 if(getEntity().getDistanceToWaterSurfaceText() != null) {
112 text_freeText
.setText(getEntity().getDistanceToWaterSurfaceText());
123 public void propertyChange(PropertyChangeEvent event
) {
127 Object eventSource
= event
.getSource();
129 if (getElements().contains(eventSource
)) {
130 if (event
instanceof CdmPropertyChangeEvent
) {
131 if (((CdmPropertyChangeEvent
) event
).hasException()) {
132 handleException((CdmPropertyChangeEvent
) event
);
136 handleEvent(eventSource
);
143 private void handleException(CdmPropertyChangeEvent event
) {
144 firePropertyChangeEvent(new CdmPropertyChangeEvent(this,
145 event
.getException()));
148 private void handleEvent(Object eventSource
) {
149 if (eventSource
== text_minVal
) {
151 } else if (eventSource
== text_maxVal
) {
153 } else if (eventSource
== text_freeText
) {
157 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
160 private void updateTitle(){
162 if(text_minVal
.getText()!=null){
163 title
+= text_minVal
.getText();
165 if(text_maxVal
.getText()!=null && !text_maxVal
.getText().equals("")){
166 if(!title
.equals("")){
167 title
+= " - "+text_maxVal
.getText();
170 if(title
.equals("") && text_freeText
.getText()!=null){
171 title
= text_freeText
.getText();
180 * @see eu.etaxonomy.taxeditor.forms.AbstractFormSection#dispose()
184 public void dispose() {
185 formFactory
.removePropertyChangeListener(this);
189 private void updateMinimum() {
192 getEntity().setAbsoluteElevation(text_minVal
.getDouble()!=null ? text_minVal
.getDouble().intValue(): null);
195 getEntity().setDistanceToGround(text_minVal
.getDouble());
198 getEntity().setDistanceToWaterSurface(text_minVal
.getDouble());
203 private Number
getMinimum() {
204 if(getEntity() == null) {
209 return getEntity().getAbsoluteElevation();
211 return getEntity().getDistanceToGround();
213 return getEntity().getDistanceToWaterSurface();
218 private void updateMaximum() {
221 getEntity().setAbsoluteElevationMax(text_maxVal
.getDouble() != null ? text_maxVal
.getDouble().intValue() : null);
224 getEntity().setDistanceToGroundMax(text_maxVal
.getDouble());
227 getEntity().setDistanceToWaterSurfaceMax(text_maxVal
.getDouble());
232 private Number
getMaximum() {
233 if(getEntity() == null) {
238 return getEntity().getAbsoluteElevationMaximum();
240 return getEntity().getDistanceToGroundMax();
242 return getEntity().getDistanceToWaterSurfaceMax();
247 private void updateFreetext() {
250 getEntity().setAbsoluteElevationText(text_freeText
.getText());
253 getEntity().setDistanceToGroundText(text_freeText
.getText());
256 getEntity().setDistanceToWaterSurfaceText(text_freeText
.getText());
261 private String
getFreetext() {
262 if(getEntity() == null) {
267 return getEntity().getAbsoluteElevationText();
269 return getEntity().getDistanceToGroundText();
271 return getEntity().getDistanceToWaterSurfaceText();