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));
64 text_minVal
= formFactory
.createNumberTextWithLabelElement(this, "Min [m] : ", getMinimum(), style
);
65 text_maxVal
= formFactory
.createNumberTextWithLabelElement(this, "Max [m] : ", getMaximum(), style
);
68 text_minVal
= formFactory
.createNumberTextWithLabelElement(this, "Min [m] : ", getMinimum(), style
);
69 text_maxVal
= formFactory
.createNumberTextWithLabelElement(this, "Max [m] : ", getMaximum(), style
);
72 text_freeText
= formFactory
.createTextWithLabelElement(this,
73 "Freetext : ", getFreetext(), style
);
75 formFactory
.addPropertyChangeListener(this);
80 * Setter for the field <code>timePeriod</code>.
84 * a {@link eu.etaxonomy.cdm.model.common.TimePeriod} object.
87 public void setEntity(DerivedUnitFacade gatheringEvent
) {
88 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().getAbsoluteElevationMaximum());
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
) {
171 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
174 private void updateTitle(){
176 if(text_minVal
.getText()!=null){
177 title
+= text_minVal
.getText();
179 if(text_maxVal
.getText()!=null && !text_maxVal
.getText().equals("")){
180 if(!title
.equals("")){
181 title
+= " - "+text_maxVal
.getText();
184 if(title
.equals("") && text_freeText
.getText()!=null){
185 title
= text_freeText
.getText();
194 * @see eu.etaxonomy.taxeditor.forms.AbstractFormSection#dispose()
198 public void dispose() {
199 formFactory
.removePropertyChangeListener(this);
203 private void updateMinimum() {
206 getEntity().setAbsoluteElevation(text_minVal
.getDouble()!=null?text_minVal
.getDouble().intValue():null);
209 getEntity().setDistanceToGround(text_minVal
.getDouble());
212 getEntity().setDistanceToWaterSurface(text_minVal
.getDouble());
217 private Number
getMinimum() {
218 if(getEntity() == null) {
223 return getEntity().getAbsoluteElevation();
225 return getEntity().getDistanceToGround();
227 return getEntity().getDistanceToWaterSurface();
232 private void updateMaximum() {
235 getEntity().setAbsoluteElevationMax(text_maxVal
.getDouble()!=null?text_maxVal
.getDouble().intValue():null);
238 getEntity().setDistanceToGroundMax(text_maxVal
.getDouble());
241 getEntity().setDistanceToWaterSurfaceMax(text_maxVal
.getDouble());
246 private Number
getMaximum() {
247 if(getEntity() == null) {
252 return getEntity().getAbsoluteElevationMaximum();
254 return getEntity().getDistanceToGroundMax();
256 return getEntity().getDistanceToWaterSurfaceMax();
261 private void updateFreetext() {
264 getEntity().setAbsoluteElevationText(text_freeText
.getText());
267 getEntity().setDistanceToGroundText(text_freeText
.getText());
270 getEntity().setDistanceToWaterSurfaceText(text_freeText
.getText());
275 private String
getFreetext() {
276 if(getEntity() == null) {
281 return getEntity().getAbsoluteElevationText();
283 return getEntity().getDistanceToGroundText();
285 return getEntity().getDistanceToWaterSurfaceText();