ref #8450 Fix config labels for default matrix values
authorPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 14 Oct 2019 13:30:10 +0000 (15:30 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 14 Oct 2019 13:30:10 +0000 (15:30 +0200)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrixConfigLabelAccumulator.java

index 4b803ac21dc56f75962643205175c05594e4e38b..a2401c6ced398f6215e8ea400248061e069530dd 100644 (file)
@@ -8,12 +8,17 @@
 */
 package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix;
 
+import java.util.Optional;
+
 import org.eclipse.nebula.widgets.nattable.layer.LabelStack;
 import org.eclipse.nebula.widgets.nattable.layer.cell.IConfigLabelAccumulator;
 
 import eu.etaxonomy.cdm.api.service.dto.SpecimenRowWrapperDTO;
 import eu.etaxonomy.cdm.api.service.dto.TaxonRowWrapperDTO;
+import eu.etaxonomy.cdm.model.description.CategoricalData;
+import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
 import eu.etaxonomy.cdm.model.description.Feature;
+import eu.etaxonomy.cdm.model.description.QuantitativeData;
 import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
 
 /**
@@ -94,7 +99,8 @@ public class CharacterMatrixConfigLabelAccumulator implements IConfigLabelAccumu
                 if(hasDefaultValue(feature, specimenRowWrapper)){
                     configLabels.addLabel(HAS_DEFAULT);
                 }
-                if(specimenRowWrapper.getDataValueForFeature(feature)!=null){
+                if(hasDefaultOverriddenValue(feature, specimenRowWrapper)){
+                    configLabels.removeLabel(HAS_DEFAULT);
                     configLabels.addLabel(DEFAULT_OVERRIDDEN);
                 }
             }
@@ -114,8 +120,33 @@ public class CharacterMatrixConfigLabelAccumulator implements IConfigLabelAccumu
         }
     }
 
+    private boolean hasDefaultOverriddenValue(Feature feature, SpecimenRowWrapperDTO specimenRowWrapper) {
+        DescriptionElementBase dataValueForFeature = specimenRowWrapper.getDataValueForFeature(feature);
+        if(dataValueForFeature!=null){
+            if(dataValueForFeature instanceof CategoricalData){
+                return !((CategoricalData) dataValueForFeature).getStatesOnly().isEmpty();
+            }
+            else if(dataValueForFeature instanceof QuantitativeData){
+                return !((QuantitativeData) dataValueForFeature).getStatisticalValues().isEmpty();
+            }
+        }
+        return false;
+    }
+
     private boolean hasDefaultValue(Feature feature, SpecimenRowWrapperDTO specimenRowWrapper) {
         TaxonRowWrapperDTO defaultDescription = specimenRowWrapper.getDefaultDescription();
-        return defaultDescription.getDescription().getElements().stream().anyMatch(element->element.getFeature().equals(feature));
+        if(defaultDescription!=null){
+            Optional<DescriptionElementBase> descriptionElement = defaultDescription.getDescription().getElements().stream()
+                    .filter(element->element.getFeature().equals(feature))
+                    .findAny();
+            if(descriptionElement.isPresent() && descriptionElement.get() instanceof CategoricalData){
+                return !((CategoricalData) descriptionElement.get()).getStatesOnly().isEmpty();
+            }
+            else if(descriptionElement.isPresent() && descriptionElement.get() instanceof QuantitativeData){
+                return !((QuantitativeData) descriptionElement.get()).getStatisticalValues().isEmpty();
+            }
+
+        }
+        return false;
     }
 }