*/
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;
/**
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);
}
}
}
}
+ 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;
}
}