ref #7849: improve DB preference handling and use editorpreferencePredicates keys...
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / description / StatisticalMeasurementValueElement.java
index 012b6018092a2542ea7a04195b7e27c9153baec2..4afc3c99a3a64fb749d5700e78e5dd1eace28f51 100644 (file)
@@ -1,4 +1,3 @@
-// $Id$
 /**
 * Copyright (C) 2007 EDIT
 * European Distributed Institute of Taxonomy
@@ -10,9 +9,13 @@
 
 package eu.etaxonomy.taxeditor.ui.section.description;
 
+import java.util.ArrayList;
+import java.util.Set;
+
 import org.eclipse.swt.events.SelectionListener;
 import org.eclipse.ui.forms.widgets.ExpandableComposite;
 
+import eu.etaxonomy.cdm.model.common.TermType;
 import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
 import eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue;
 import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
@@ -56,8 +59,10 @@ public class StatisticalMeasurementValueElement extends
        @Override
        public void setEntity(StatisticalMeasurementValue entity) {
                this.entity = entity;
-               number_value.setNumber(entity.getValue());
+               Set<StatisticalMeasure> statisiticalMeasures = getEntity().getQuantitativeData().getFeature().getRecommendedStatisticalMeasures();
+        combo_type.setTerms(new ArrayList<StatisticalMeasure>(statisiticalMeasures));
                combo_type.setSelection(entity.getType());
+               number_value.setNumber(entity.getValue());
                section_modifiers.setEntity(entity);
        }
 
@@ -65,7 +70,7 @@ public class StatisticalMeasurementValueElement extends
        @Override
        public void createControls(ICdmFormElement element, int style) {
                number_value = formFactory.createNumberTextWithLabelElement(element, "Value", 0, style);
-               combo_type = formFactory.createTermComboElement(StatisticalMeasure.class, element, "Statistical Measure", null, style);
+               combo_type = formFactory.createDefinedTermComboElement(TermType.StatisticalMeasure, element, "Statistical Measure", null, style);
                section_modifiers = formFactory.createModifierSection(getConversationHolder(), element, ExpandableComposite.TWISTIE);
                section_modifiers.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
        }
@@ -74,10 +79,17 @@ public class StatisticalMeasurementValueElement extends
        @Override
        public void handleEvent(Object eventSource) {
                if(eventSource == number_value){
-                       getEntity().setValue(number_value.getFloat());
+                       Float floatNumber = number_value.getFloat();
+                       if(floatNumber==null){
+                           String zero = "0.0";
+                floatNumber = new Float(zero);
+                           number_value.setText(zero);
+                       }
+            getEntity().setValue(floatNumber);
                }
                else if(eventSource == combo_type){
                        getEntity().setType(combo_type.getSelection());
+                       combo_type.removeEmptyElement();
                }
        }
 }