ref #7575 Merge aggregated and exact value cell editor
authorPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 23 Jul 2018 16:06:44 +0000 (18:06 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 23 Jul 2018 16:07:32 +0000 (18:07 +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/CharacterMatrixConfigLabelAccumulator.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/quantitative/QuantitativeDataCellEditor.java [deleted file]
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/quantitative/QuantitativeDataDialog.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/quantitative/QuantitativeDataDialogComposite.java

index 76e9bfe030ed70259796491e2a0b442cfa72430d..500f5768d3c0ce8e8af7523e36b3d1ebcb927228 100644 (file)
@@ -24,7 +24,6 @@ import org.eclipse.swt.graphics.Point;
 import eu.etaxonomy.cdm.model.description.Feature;
 import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.categorical.CategoricalDataCellEditor;
 import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.categorical.CategoricalDataDisplayConverter;
-import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.quantitative.QuantitativeDataCellEditor;
 import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.quantitative.QuantitativeDataDialogEditor;
 import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.quantitative.QuantitativeDataEditModeDisplayConverter;
 import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.quantitative.QuantitativeDataNormalModeDisplayConverter;
@@ -112,21 +111,18 @@ final class CellEditorDataConversionConfiguration extends AbstractRegistryConfig
                 DisplayMode.NORMAL,
                 CharacterMatrixConfigLabelAccumulator.QUANTITATIVE);
 
-        /**
-         * exact value editor
-         */
         //Open cell editor in dialog
         configRegistry.registerConfigAttribute(
                 EditConfigAttributes.OPEN_IN_DIALOG,
                 Boolean.TRUE,
                 DisplayMode.EDIT,
-                CharacterMatrixConfigLabelAccumulator.QUANT_EXACT);
+                CharacterMatrixConfigLabelAccumulator.QUANTITATIVE);
         //register quantitative editor
         configRegistry.registerConfigAttribute(
                 EditConfigAttributes.CELL_EDITOR,
                 new QuantitativeDataDialogEditor(matrix),
                 DisplayMode.EDIT,
-                CharacterMatrixConfigLabelAccumulator.QUANT_EXACT);
+                CharacterMatrixConfigLabelAccumulator.QUANTITATIVE);
         // configure custom dialog settings
         Map<String, Object> editDialogSettings = new HashMap<>();
         editDialogSettings.put(ICellEditDialog.DIALOG_SHELL_TITLE, "Quantitative Data");
@@ -135,7 +131,6 @@ final class CellEditorDataConversionConfiguration extends AbstractRegistryConfig
         Point size = new Point(250, 300);
         editDialogSettings.put(ICellEditDialog.DIALOG_SHELL_SIZE, size);
 
-        // add custum message
         //FIXME: this is not displayed because the cell editor
         //is already a dialog. Maybe the cell editor and the
         //dialog can be merged
@@ -145,7 +140,7 @@ final class CellEditorDataConversionConfiguration extends AbstractRegistryConfig
                 EditConfigAttributes.EDIT_DIALOG_SETTINGS,
                 editDialogSettings,
                 DisplayMode.EDIT,
-                CharacterMatrixConfigLabelAccumulator.QUANT_EXACT);
+                CharacterMatrixConfigLabelAccumulator.QUANTITATIVE);
 
 
         //TODO: this for loop can maybe be avoided
@@ -153,17 +148,7 @@ final class CellEditorDataConversionConfiguration extends AbstractRegistryConfig
     }
 
     private void registerColumnConfiguration(Feature feature, IConfigRegistry configRegistry) {
-        if(feature.isSupportsQuantitativeData()){
-        /**
-         * aggregated value editor
-         */
-        configRegistry.registerConfigAttribute(
-                EditConfigAttributes.CELL_EDITOR,
-                new QuantitativeDataCellEditor(feature, matrix),
-                DisplayMode.EDIT,
-                CharacterMatrixConfigLabelAccumulator.QUANT_AGGREGATED);
-        }
-        else if(feature.isSupportsCategoricalData()){
+        if(feature.isSupportsCategoricalData()){
             //add combo box cell editor
             //register editor
             configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR,
@@ -172,6 +157,5 @@ final class CellEditorDataConversionConfiguration extends AbstractRegistryConfig
                     MatrixUtility.getProperty(feature));
 
         }
-
     }
 }
index 1468d9ebebbf70b2ed1af06e35c935df4d4445ca..964c70ce8a349a644661e806b497a37e7848243d 100644 (file)
@@ -22,8 +22,6 @@ import eu.etaxonomy.cdm.model.taxon.TaxonNode;
 public class CharacterMatrixConfigLabelAccumulator implements IConfigLabelAccumulator {
 
     public static final String QUANTITATIVE = "QUANTITATIVE";
-    public static final String QUANT_AGGREGATED = QUANTITATIVE+"_AGGREGATED";
-    public static final String QUANT_EXACT = QUANTITATIVE+"_EXACT";
     public static final String CATEGORICAL = "CATEGORICAL";
 
     private CharacterMatrix matrix;
@@ -33,7 +31,6 @@ public class CharacterMatrixConfigLabelAccumulator implements IConfigLabelAccumu
         this.matrix = matrix;
     }
 
-
     @Override
     public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
         Object rowObject = matrix.getBodyDataProvider().getRowObject(rowPosition);
@@ -60,7 +57,6 @@ public class CharacterMatrixConfigLabelAccumulator implements IConfigLabelAccumu
             }
             else if(feature.isSupportsQuantitativeData()){
                 configLabels.addLabel(QUANTITATIVE);
-                configLabels.addLabel(matrix.isExactQuantitativeValue()?QUANT_EXACT:QUANT_AGGREGATED);
             }
         }
     }
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/quantitative/QuantitativeDataCellEditor.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/quantitative/QuantitativeDataCellEditor.java
deleted file mode 100644 (file)
index 3bfd2c2..0000000
+++ /dev/null
@@ -1,175 +0,0 @@
-/**
-* Copyright (C) 2017 EDIT
-* European Distributed Institute of Taxonomy
-* http://www.e-taxonomy.eu
-*
-* The contents of this file are subject to the Mozilla Public License Version 1.1
-* See LICENSE.TXT at the top of this package for the full license terms.
-*/
-package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.quantitative;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-import org.eclipse.nebula.widgets.nattable.edit.editor.AbstractCellEditor;
-import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer.MoveDirectionEnum;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Text;
-
-import eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO;
-import eu.etaxonomy.cdm.model.description.Feature;
-import eu.etaxonomy.cdm.model.description.QuantitativeData;
-import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
-import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.CharacterMatrix;
-
-/**
- * Cell editor for QuantitativeData
- * @author pplitzner
- * @since Dec 7, 2017
- *
- */
-public class QuantitativeDataCellEditor extends AbstractCellEditor{
-
-    private Control editorControl;
-
-    private Feature feature;
-
-    private Map<StatisticalMeasure, Text> measureToTextMap = new HashMap<>();
-
-    private Object editorValue;
-
-    private CharacterMatrix matrix;
-
-    private boolean dirty = false;
-
-    public QuantitativeDataCellEditor(Feature feature, CharacterMatrix matrix) {
-        super();
-        this.matrix = matrix;
-        this.feature = feature;
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public Object getEditorValue() {
-        return this.editorValue;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void setEditorValue(Object value) {
-        this.editorValue = value;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public Control getEditorControl() {
-        return editorControl;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public Control createEditorControl(Composite parent) {
-        Composite composite = new Composite(parent, SWT.NONE);
-        composite.setLayout(new FillLayout(SWT.HORIZONTAL));
-
-        for (StatisticalMeasure measure: feature.getRecommendedStatisticalMeasures()) {
-            Composite measureComposite = new Composite(composite, SWT.NONE);
-            GridLayout layout = new GridLayout(2, false);
-            layout.horizontalSpacing = 0;
-            layout.marginBottom = 0;
-            layout.marginHeight = 0;
-            layout.marginLeft = 0;
-            layout.marginRight = 0;
-            layout.marginTop = 0;
-            layout.marginWidth = 0;
-            layout.verticalSpacing = 0;
-            measureComposite.setLayout(layout);
-            Label label = new Label(measureComposite, SWT.NONE);
-            GridData layoutData = new GridData(SWT.CENTER, SWT.TOP, false, false);
-            label.setLayoutData(layoutData);
-            label.setText(measure.getLabel().substring(0, 3));
-
-            Text text = new Text(measureComposite, SWT.NONE);
-            label.setLayoutData(new GridData(SWT.CENTER, SWT.TOP, false, false));
-
-            measureToTextMap.put(measure, text);
-        }
-        return composite;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public boolean commit(MoveDirectionEnum direction, boolean closeAfterCommit, boolean skipValidation) {
-        if(dirty){
-            matrix.setDirty();
-            dirty = false;
-        }
-        return super.commit(direction, closeAfterCommit, skipValidation);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    protected Control activateCell(Composite parent, Object originalCanonicalValue) {
-        Object rowObject = matrix.getBodyDataProvider().getRowObject(this.getRowIndex());
-        if(rowObject instanceof RowWrapperDTO){
-            this.editorControl = createEditorControl(parent);
-            if(originalCanonicalValue==null){
-                originalCanonicalValue = ((RowWrapperDTO) rowObject).addQuantitativeData(feature);
-            }
-            this.setEditorValue(originalCanonicalValue);
-
-            if(originalCanonicalValue instanceof QuantitativeData){
-                QuantitativeData quantitativeData = (QuantitativeData)originalCanonicalValue;
-                Set<StatisticalMeasure> statisticalValues = quantitativeData.getFeature().getRecommendedStatisticalMeasures();
-                //Fill text controls with actual values and add modify listeners for editing
-                for (StatisticalMeasure value : statisticalValues) {
-                    Text text = measureToTextMap.get(value);
-                    text.addModifyListener(e->{
-                        try {
-                            float parseFloat = Float.parseFloat(text.getText());
-                            quantitativeData.setSpecificStatisticalValue(parseFloat, null, value);
-                            dirty = true;
-                        } catch (NumberFormatException|NullPointerException ex) {
-                            // ignore exception for wrong number format
-                        }
-                    });
-
-                    Float specificStatisticalValue = quantitativeData.getSpecificStatisticalValue(value);
-                    if(specificStatisticalValue!=null){
-                        Listener[] listeners = text.getListeners(SWT.Modify);
-                        for (Listener listener : listeners) {
-                            text.removeListener(SWT.Modify, listener);
-                        }
-                        text.setText(Float.toString(specificStatisticalValue));
-                        for (Listener listener : listeners) {
-                            text.addListener(SWT.Modify, listener);
-                        }
-                    }
-                }
-            }
-        }
-        return this.editorControl;
-    }
-
-}
index 3866169b5db8260de2d6b32003ef369bc2609aa5..7a2ad250aa7f865f9eb4b285ce360a61eedf7772 100644 (file)
@@ -9,7 +9,7 @@
 package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.quantitative;
 
 import java.util.List;
-import java.util.stream.Collectors;
+import java.util.Map;
 
 import org.eclipse.jface.window.Window;
 import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
@@ -68,26 +68,21 @@ public class QuantitativeDataDialog extends CellEditDialog {
         return super.close();
     }
 
-    void updateQuantitativeData(QuantitativeData object){
-        QuantitativeData quantitativeData = object;
-        //get all non-exact values
-        List<StatisticalMeasurementValue> values = quantitativeData.getStatisticalValues().stream()
-                .filter(value->!value.getType().equals(StatisticalMeasure.EXACT_VALUE()))
-                .collect(Collectors.toList());
+    void updateQuantitativeData(QuantitativeData quantitativeData){
         //clear values
         quantitativeData.getStatisticalValues().clear();
-        //add back all non-exact values
-        values.forEach(value->quantitativeData.addStatisticalValue(value));
-        //get exact values from text fields
-        List<Text> textFields = composite.getTextFields();
-        for (Text text : textFields) {
+        //add back all values from text fields
+        Map<StatisticalMeasure, List<Text>> textFields = composite.getTextFields();
+        textFields.forEach((measure, texts)->{
+            texts.forEach(text->{
             String string = text.getText();
             try {
                 float exactValue = Float.parseFloat(string);
-                quantitativeData.addStatisticalValue(StatisticalMeasurementValue.NewInstance(StatisticalMeasure.EXACT_VALUE(), exactValue));
+                quantitativeData.addStatisticalValue(StatisticalMeasurementValue.NewInstance(measure, exactValue));
             } catch (NumberFormatException e) {
             }
-        }
+            });
+        });
     }
 
 }
index f478a742f188a5cc2004091dfd7f43a5688a4cb3..c4ea27629bda0f5c202539afeb330c35e01cb4d8 100644 (file)
@@ -10,7 +10,9 @@
 package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.quantitative;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.custom.ScrolledComposite;
@@ -20,6 +22,7 @@ import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Text;
 
 import eu.etaxonomy.cdm.model.description.QuantitativeData;
@@ -33,7 +36,7 @@ import eu.etaxonomy.taxeditor.model.ImageResources;
  */
 public class QuantitativeDataDialogComposite extends Composite {
 
-    private List<Text> textFields = new ArrayList<>();
+    private Map<StatisticalMeasure, List<Text>> textFieldMap = new HashMap<>();
 
     public QuantitativeDataDialogComposite(Character initialInput, QuantitativeData editorValue, Composite parent, int style) {
         super(parent, style);
@@ -41,7 +44,6 @@ public class QuantitativeDataDialogComposite extends Composite {
 
         setLayout(new GridLayout(1, false));
 
-
         ScrolledComposite scrolledComposite_1 = new ScrolledComposite(this, SWT.BORDER | SWT.V_SCROLL);
         scrolledComposite_1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
         scrolledComposite_1.setExpandHorizontal(true);
@@ -53,40 +55,58 @@ public class QuantitativeDataDialogComposite extends Composite {
         gl_valuesComposite.marginHeight = 0;
         valuesComposite.setLayout(gl_valuesComposite);
 
-        //add empty text field
-        Text emptyTextField = addValue(initialInput==null?null:initialInput.toString(), valuesComposite);
+        //add empty text field for exact value
+        Text emptyTextField = addText(valuesComposite, StatisticalMeasure.EXACT_VALUE(), initialInput==null?null:initialInput.toString());
         emptyTextField.setFocus();
         emptyTextField.setSelection(emptyTextField.getText().length());
 
-        //add exisiting values
+        //add existing exact values
         editorValue.getStatisticalValues().stream()
-        .filter(value->value.getType().equals(StatisticalMeasure.EXACT_VALUE()))
-        .forEach(exact->addValue(Float.toString(exact.getValue()), valuesComposite));
-
+        .filter(measure->measure.getType().equals(StatisticalMeasure.EXACT_VALUE()))
+        .forEach(exact->addText(valuesComposite, exact.getType(), Float.toString(exact.getValue())));
+
+        //add aggregation values
+        editorValue.getFeature().getRecommendedStatisticalMeasures()
+        .stream()
+        .filter(sm->!sm.equals(StatisticalMeasure.EXACT_VALUE()))
+        .forEach(measure->{
+            Float specificStatisticalValue = editorValue.getSpecificStatisticalValue(measure);
+            addText(valuesComposite, measure, specificStatisticalValue!=null?Float.toString(specificStatisticalValue):null);
+        });
 
         scrolledComposite_1.setContent(valuesComposite);
         scrolledComposite_1.setMinSize(valuesComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
     }
 
-    private Text addValue(String value, Composite valuesComposite) {
+    private Text addText(Composite valuesComposite, StatisticalMeasure type, String value){
         Composite composite_2 = new Composite(valuesComposite, SWT.NONE);
         composite_2.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
-        GridLayout gl_composite_2 = new GridLayout(2, false);
+        GridLayout gl_composite_2 = new GridLayout(4, false);
         gl_composite_2.marginHeight = 0;
         gl_composite_2.marginWidth = 0;
         gl_composite_2.verticalSpacing = 0;
         gl_composite_2.horizontalSpacing = 2;
         composite_2.setLayout(gl_composite_2);
 
+        Label lblNewLabel = new Label(composite_2, SWT.NONE);
+        lblNewLabel.setText(type.getLabel().substring(0, 3));
+
         Text text = new Text(composite_2, SWT.BORDER);
         text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
         if(value!=null){
             text.setText(value);
         }
-        textFields.add(text);
+
+        List<Text> list = textFieldMap.get(type);
+        if(list==null){
+            list = new ArrayList<>();
+        }
+        textFieldMap.put(type, list);
+        list.add(text);
 
         Button btnNewButton_2 = new Button(composite_2, SWT.NONE);
         btnNewButton_2.setImage(ImageResources.getImage(ImageResources.TRASH_ICON));
+        new Label(composite_2, SWT.NONE);
         btnNewButton_2.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
@@ -96,8 +116,8 @@ public class QuantitativeDataDialogComposite extends Composite {
         return text;
     }
 
-    public List<Text> getTextFields() {
-        return textFields;
+    public Map<StatisticalMeasure, List<Text>> getTextFields() {
+        return textFieldMap;
     }
 
 }