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.
10 package eu
.etaxonomy
.taxeditor
.ui
.element
;
12 import org
.eclipse
.jface
.util
.PropertyChangeEvent
;
14 import eu
.etaxonomy
.cdm
.api
.facade
.DerivedUnitFacade
;
18 * MinMaxTextSection class.
22 * @created 23 Jul 2013
25 public class MinMaxTextSection
extends AbstractFormSection
<DerivedUnitFacade
> {
27 private final TextWithLabelElement text_freeText
;
28 private final NumberWithLabelElement text_minVal
;
29 private final NumberWithLabelElement text_maxVal
;
30 private int cursorPosition
;
32 // unit types handled by this section
33 public enum UnitType
{
39 private UnitType unitType
= UnitType
.ELEVATION
;
43 * Constructor for DateDetailSection.
47 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
49 * @param parentElement
50 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
55 protected MinMaxTextSection(CdmFormFactory formFactory
,
56 ICdmFormElement parentElement
, UnitType unitType
, int style
) {
57 super(formFactory
, parentElement
, style
);
58 this.unitType
= unitType
;
59 getLayoutComposite().setLayout(LayoutConstants
.LAYOUT(2, false));
63 text_minVal
= formFactory
.createFloatTextWithLabelElement(this, "Min [m] : ", getMinimum(), style
);
64 text_maxVal
= formFactory
.createFloatTextWithLabelElement(this, "Max [m] : ", getMaximum(), style
);
67 text_minVal
= formFactory
.createFloatTextWithLabelElement(this, "Min [m] : ", getMinimum(), style
);
68 text_maxVal
= formFactory
.createFloatTextWithLabelElement(this, "Max [m] : ", getMaximum(), style
);
71 text_freeText
= formFactory
.createTextWithLabelElement(this,
72 "Freetext : ", getFreetext(), style
);
74 formFactory
.addPropertyChangeListener(this);
79 * Setter for the field <code>timePeriod</code>.
83 * a {@link eu.etaxonomy.cdm.model.common.TimePeriod} object.
86 public void setEntity(DerivedUnitFacade gatheringEvent
) {
87 super.setEntity(gatheringEvent
);
92 private void updateValues() {
93 if(getEntity() != null) {
96 if(getEntity().getAbsoluteElevation() != null) {
97 text_minVal
.setNumber(getEntity().getAbsoluteElevation());
99 if(getEntity().getAbsoluteElevationMaximum() != null) {
100 text_maxVal
.setNumber(getEntity().getAbsoluteElevationMaximum());
102 if(getEntity().getAbsoluteElevationText() != null) {
103 text_freeText
.setText(getEntity().getAbsoluteElevationText());
107 if(getEntity().getDistanceToGround() != null) {
108 text_minVal
.setNumber(getEntity().getDistanceToGround());
110 if(getEntity().getDistanceToGroundMax() != null) {
111 text_maxVal
.setNumber(getEntity().getDistanceToGroundMax());
113 if(getEntity().getDistanceToGroundText() != null) {
114 text_freeText
.setText(getEntity().getDistanceToGroundText());
118 if(getEntity().getDistanceToWaterSurface() != null) {
119 text_minVal
.setNumber(getEntity().getDistanceToWaterSurface());
121 if(getEntity().getDistanceToWaterSurfaceMax() != null) {
122 text_maxVal
.setNumber(getEntity().getDistanceToWaterSurfaceMax());
124 if(getEntity().getDistanceToWaterSurfaceText() != null) {
125 text_freeText
.setText(getEntity().getDistanceToWaterSurfaceText());
136 public void propertyChange(PropertyChangeEvent event
) {
140 Object eventSource
= event
.getSource();
142 if (getElements().contains(eventSource
)) {
143 if (event
instanceof CdmPropertyChangeEvent
) {
144 if (((CdmPropertyChangeEvent
) event
).hasException()) {
145 handleException((CdmPropertyChangeEvent
) event
);
149 handleEvent(eventSource
);
156 private void handleException(CdmPropertyChangeEvent event
) {
157 firePropertyChangeEvent(new CdmPropertyChangeEvent(this,
158 event
.getException()));
161 private void handleEvent(Object eventSource
) {
162 if (eventSource
== text_minVal
) {
164 } else if (eventSource
== text_maxVal
) {
166 } else if (eventSource
== text_freeText
) {
170 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
173 private void updateTitle(){
175 if(text_minVal
.getText()!=null){
176 title
+= text_minVal
.getText();
178 if(text_maxVal
.getText()!=null && !text_maxVal
.getText().equals("")){
179 if(!title
.equals("")){
180 title
+= " - "+text_maxVal
.getText();
183 if(title
.equals("") && text_freeText
.getText()!=null){
184 title
= text_freeText
.getText();
193 * @see eu.etaxonomy.taxeditor.forms.AbstractFormSection#dispose()
197 public void dispose() {
198 formFactory
.removePropertyChangeListener(this);
202 private void updateMinimum() {
205 getEntity().setAbsoluteElevation(text_minVal
.getDouble()!=null ? text_minVal
.getDouble().intValue(): null);
208 getEntity().setDistanceToGround(text_minVal
.getDouble());
211 getEntity().setDistanceToWaterSurface(text_minVal
.getDouble());
216 private Number
getMinimum() {
217 if(getEntity() == null) {
222 return getEntity().getAbsoluteElevation();
224 return getEntity().getDistanceToGround();
226 return getEntity().getDistanceToWaterSurface();
231 private void updateMaximum() {
234 getEntity().setAbsoluteElevationMax(text_maxVal
.getDouble() != null ? text_maxVal
.getDouble().intValue() : null);
237 getEntity().setDistanceToGroundMax(text_maxVal
.getDouble());
240 getEntity().setDistanceToWaterSurfaceMax(text_maxVal
.getDouble());
245 private Number
getMaximum() {
246 if(getEntity() == null) {
251 return getEntity().getAbsoluteElevationMaximum();
253 return getEntity().getDistanceToGroundMax();
255 return getEntity().getDistanceToWaterSurfaceMax();
260 private void updateFreetext() {
263 getEntity().setAbsoluteElevationText(text_freeText
.getText());
266 getEntity().setDistanceToGroundText(text_freeText
.getText());
269 getEntity().setDistanceToWaterSurfaceText(text_freeText
.getText());
274 private String
getFreetext() {
275 if(getEntity() == null) {
280 return getEntity().getAbsoluteElevationText();
282 return getEntity().getDistanceToGroundText();
284 return getEntity().getDistanceToWaterSurfaceText();