ref #9816: adapt matrix to possibility of more than one descr element
authorKatja Luther <k.luther@bgbm.org>
Tue, 26 Oct 2021 07:46:45 +0000 (09:46 +0200)
committerKatja Luther <k.luther@bgbm.org>
Tue, 26 Oct 2021 07:46:45 +0000 (09:46 +0200)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CellEditorDataConversionConfiguration.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/categorical/CategoricalDataCellEditor.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/quantitative/QuantitativeDataDialogEditor.java

index 286fbddfcf5100abdf5e19bd29ecc7aae8ce9921..ac15efbd6897b5ad842621a9752b9940b07dfde0 100644 (file)
@@ -79,8 +79,8 @@ final class CellEditorDataConversionConfiguration extends AbstractRegistryConfig
         //make cell editable
         configRegistry.registerConfigAttribute(
                 EditConfigAttributes.CELL_EDITABLE_RULE,
-                getEditRule(matrix.getBodyDataProvider()),
-//                IEditableRule.ALWAYS_EDITABLE,
+//                getEditRule(matrix.getBodyDataProvider()),
+                IEditableRule.ALWAYS_EDITABLE,
                 DisplayMode.EDIT,
                 CharacterMatrixConfigLabelAccumulator.CATEGORICAL_EDITABLE
                 );
@@ -105,8 +105,8 @@ final class CellEditorDataConversionConfiguration extends AbstractRegistryConfig
         //make cell editable
         configRegistry.registerConfigAttribute(
                 EditConfigAttributes.CELL_EDITABLE_RULE,
-                getEditRule(matrix.getBodyDataProvider()),
-//                IEditableRule.ALWAYS_EDITABLE,
+//                getEditRule(matrix.getBodyDataProvider()),
+                IEditableRule.ALWAYS_EDITABLE,
                 DisplayMode.EDIT,
                 CharacterMatrixConfigLabelAccumulator.QUANTITATIVE_EDITABLE
                 );
@@ -157,15 +157,15 @@ final class CellEditorDataConversionConfiguration extends AbstractRegistryConfig
     }
    
     
-    private static IEditableRule getEditRule(final IDataProvider dataProvider) {
-                       return new EditableRule(){
-                       public boolean isEditable(int columnIndex, int rowIndex) {
-                               Object dataValue = dataProvider.getDataValue(columnIndex, rowIndex);
-                               if (dataValue instanceof Set && ((Set)dataValue).size()>1){
-                                       return false;
-                               }else return true;
-                               }
-                       };
-               }
+//    private static IEditableRule getEditRule(final IDataProvider dataProvider) {
+//                     return new EditableRule(){
+//                     public boolean isEditable(int columnIndex, int rowIndex) {
+//                             Object dataValue = dataProvider.getDataValue(columnIndex, rowIndex);
+//                             if (dataValue instanceof Set && ((Set)dataValue).size()>1){
+//                                     return false;
+//                             }else return true;
+//                             }
+//                     };
+//             }
 
 }
index 1890198cd1711b26e7d574cafdc0145e686334c2..4347fd04ef25a79c6350d50b87e5fafb93f64e7a 100644 (file)
@@ -8,6 +8,10 @@
 */
 package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.categorical;
 
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 
 import org.eclipse.nebula.widgets.nattable.edit.editor.ComboBoxCellEditor;
@@ -38,14 +42,6 @@ public class CategoricalDataCellEditor extends ComboBoxCellEditor{
         setUseCheckbox(true);
         setMultiselect(true);
         setShowDropdownFilter(true);
-//        Object rowWrapper = matrix.getBodyDataProvider().getRowObject(this.getRowIndex());
-//        if(rowWrapper instanceof RowWrapperDTO){
-//             FeatureDto feature = matrix.getIndexToFeatureMap().get(getColumnIndex());
-//             Set<DescriptionElementDto> elements = ((RowWrapperDTO)rowWrapper).getDataValueForFeature(feature.getUuid());
-//             if (elements != null && elements.size() >1){
-//                     this.getEditorControl().setEnabled(false);
-//             }
-//        }
     }
 
     @Override
@@ -56,12 +52,24 @@ public class CategoricalDataCellEditor extends ComboBoxCellEditor{
                 FeatureDto feature = matrix.getIndexToFeatureMap().get(getColumnIndex());
                 // FIXME avoid creating empty CategoricalData
 //                ((RowWrapperDTO) rowWrapper).addCategoricalData(feature);
-                
             }
             
         }
+        List canonicalValueList = new ArrayList<>();
         
-        super.setCanonicalValue(canonicalValue);
+        if (canonicalValue instanceof String[]){
+               String[] stringArray = (String[])canonicalValue;
+               for (int i = 0; i<stringArray.length; i++){
+                       canonicalValueList.add(stringArray[i]);
+               }
+        }else if (canonicalValue instanceof List){
+               canonicalValueList = (List<String>)canonicalValue;
+        }else if (canonicalValue instanceof String){
+               canonicalValueList.add((String)canonicalValue);
+        }else if (canonicalValue instanceof HashSet){
+               canonicalValueList = new ArrayList(((HashSet)canonicalValue));
+        }
+        super.setCanonicalValue(canonicalValueList);
     }
 
     @Override
index d024999d8ea8027b818039a181ac31ff88520014..fade75999b3a3e45b201eb530fb24e6776bb0673 100644 (file)
@@ -8,6 +8,7 @@
 */
 package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.quantitative;
 
+import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
 
@@ -98,11 +99,15 @@ public class QuantitativeDataDialogEditor extends AbstractDialogCellEditor {
         if(rowObject instanceof RowWrapperDTO){
             rowWrapperDTO = (RowWrapperDTO<?>) rowObject;
             Set<DescriptionElementDto> dataValueForFeature = rowWrapperDTO.getDataValueForFeature(feature.getUuid());
-            if (dataValueForFeature.size() > 1){
+            if (dataValueForFeature != null && dataValueForFeature.size() > 1){
                return null;
             }
-            if(dataValueForFeature instanceof QuantitativeDataDto){
-                quantitativeData = (QuantitativeDataDto) dataValueForFeature;
+            Iterator<DescriptionElementDto> it = dataValueForFeature.iterator();
+            if(it.hasNext() ){
+               DescriptionElementDto dto = it.next();
+               if(dto instanceof QuantitativeDataDto){
+                       quantitativeData = (QuantitativeDataDto) dto;
+               }
             }
             //create new Quantitative Data
             if (quantitativeData == null) {