ref #7095 Handle dirty state of character matrix when editing
authorPatrick Plitzner <p.plitzner@bgbm.org>
Wed, 13 Dec 2017 12:28:08 +0000 (13:28 +0100)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Wed, 13 Dec 2017 12:28:08 +0000 (13:28 +0100)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/CharacterMatrix.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/categorical/CategoricalDataCellEditor.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/quantitative/QuantitativeDataCellEditor.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/quantitative/QuantitativeDataComposite.java [deleted file]
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/quantitative/QuantitativeDataDisplayConverter.java

index ed86f9c7bb0e3c770b904f9a9acf6b9b68155628..f0070f5ccafe7baacd1a87ca6ffe4941c6d7f2e9 100644 (file)
@@ -293,7 +293,7 @@ public class CharacterMatrix implements IE4SavablePart, IPartContentHasDetails,
             //register quantitative editor
             configRegistry.registerConfigAttribute(
                     EditConfigAttributes.CELL_EDITOR,
-                    new QuantitativeDataCellEditor(feature.getRecommendedStatisticalMeasures()),
+                    new QuantitativeDataCellEditor(feature.getRecommendedStatisticalMeasures(), this),
                     DisplayMode.EDIT,
                     getProperty(feature));
         }
@@ -320,7 +320,7 @@ public class CharacterMatrix implements IE4SavablePart, IPartContentHasDetails,
                     }
                     return states;
                 }
-            }, 5);
+            }, 5, this);
             //register editor
             configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR,
                     comboBoxCellEditor,
@@ -350,6 +350,10 @@ public class CharacterMatrix implements IE4SavablePart, IPartContentHasDetails,
         return feature.getLabel();
     }
 
+    public void setDirty() {
+        this.dirty.setDirty(true);
+    }
+
     @Persist
     @Override
     public void save(IProgressMonitor monitor) {
index d42521057811fb02ecff19e87ee92e5e19e9078f..c26fe0d452e090112c9e98e1956f1301fb994df3 100644 (file)
@@ -12,9 +12,15 @@ import java.util.List;
 
 import org.eclipse.nebula.widgets.nattable.edit.editor.IComboBoxDataProvider;
 import org.eclipse.nebula.widgets.nattable.filterrow.combobox.FilterRowComboBoxCellEditor;
+import org.eclipse.nebula.widgets.nattable.widget.NatCombo;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
 
 import eu.etaxonomy.cdm.model.description.CategoricalData;
 import eu.etaxonomy.cdm.model.description.State;
+import eu.etaxonomy.taxeditor.editor.workingSet.matrix.CharacterMatrix;
 
 /**
  * @author pplitzner
@@ -23,8 +29,11 @@ import eu.etaxonomy.cdm.model.description.State;
  */
 public class CategoricalDataCellEditor extends FilterRowComboBoxCellEditor{
 
-    public CategoricalDataCellEditor(IComboBoxDataProvider dataProvider, int maxVisibleItems) {
+    private CharacterMatrix matrix;
+
+    public CategoricalDataCellEditor(IComboBoxDataProvider dataProvider, int maxVisibleItems, CharacterMatrix matrix) {
         super(dataProvider, maxVisibleItems);
+        this.matrix = matrix;
     }
 
     @Override
@@ -41,4 +50,22 @@ public class CategoricalDataCellEditor extends FilterRowComboBoxCellEditor{
         }
     }
 
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected Control activateCell(Composite parent, Object originalCanonicalValue) {
+        Control editorControl = super.activateCell(parent, originalCanonicalValue);
+        ((NatCombo)editorControl).addSelectionListener(new SelectionListener() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                matrix.setDirty();
+            }
+            @Override
+            public void widgetDefaultSelected(SelectionEvent e) {
+            }
+        });
+        return editorControl;
+    }
+
 }
index 3ea68336217d9483b89c782149697330a75caed4..bb9f0108a747334d68d58457aeba3b74b5930f94 100644 (file)
@@ -13,6 +13,7 @@ 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;
@@ -20,10 +21,12 @@ 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.model.description.CategoricalData;
+import eu.etaxonomy.cdm.model.description.QuantitativeData;
 import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
+import eu.etaxonomy.taxeditor.editor.workingSet.matrix.CharacterMatrix;
 
 /**
  * @author pplitzner
@@ -38,17 +41,25 @@ public class QuantitativeDataCellEditor extends AbstractCellEditor{
 
     private Map<StatisticalMeasure, Text> measureToTextMap = new HashMap<>();
 
-    public QuantitativeDataCellEditor(Set<StatisticalMeasure> statisticalMeasures) {
+    private Object editorValue;
+
+    private CharacterMatrix matrix;
+
+    private boolean dirty = false;
+
+    public QuantitativeDataCellEditor(Set<StatisticalMeasure> statisticalMeasures, CharacterMatrix matrix) {
         super();
+        this.matrix = matrix;
         this.statisticalMeasures = statisticalMeasures;
     }
 
+
     /**
      * {@inheritDoc}
      */
     @Override
     public Object getEditorValue() {
-        return null;
+        return this.editorValue;
     }
 
     /**
@@ -56,8 +67,7 @@ public class QuantitativeDataCellEditor extends AbstractCellEditor{
      */
     @Override
     public void setEditorValue(Object value) {
-        if(value instanceof CategoricalData){
-        }
+        this.editorValue = value;
     }
 
     /**
@@ -101,15 +111,51 @@ public class QuantitativeDataCellEditor extends AbstractCellEditor{
         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) {
-        System.out.println(originalCanonicalValue);
         this.editorControl = createEditorControl(parent);
+        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->{
+                    quantitativeData.setSpecificStatisticalValue(Float.parseFloat(text.getText()), null, value);
+                    dirty = true;
+                });
+
+                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;
     }
 
-
 }
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/quantitative/QuantitativeDataComposite.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/quantitative/QuantitativeDataComposite.java
deleted file mode 100644 (file)
index 30da285..0000000
+++ /dev/null
@@ -1,57 +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.workingSet.matrix.quantitative;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Text;
-
-/**
- * @author pplitzner
- * @since Dec 11, 2017
- *
- */
-public class QuantitativeDataComposite extends Composite {
-    private Text min;
-    private Text avg;
-    private Text max;
-
-    /**
-     * Create the composite.
-     * @param parent
-     * @param style
-     */
-    public QuantitativeDataComposite(Composite parent, int style) {
-        super(parent, style);
-        setLayout(new FillLayout(SWT.HORIZONTAL));
-
-        min = new Text(this, SWT.NONE);
-
-        avg = new Text(this, SWT.BORDER);
-
-        max = new Text(this, SWT.BORDER);
-
-    }
-
-    @Override
-    protected void checkSubclass() {
-        // Disable the check that prevents subclassing of SWT components
-    }
-
-    public Text getMin() {
-        return min;
-    }
-    public Text getAvg() {
-        return avg;
-    }
-    public Text getMax() {
-        return max;
-    }
-}
index 01bea4ad34d3dc74f8936b198cfcfbfdfabdfc9b..8f3338bdd0d6bcbafdae282fccf2bc0a87a2a26a 100644 (file)
@@ -28,7 +28,10 @@ public class QuantitativeDataDisplayConverter extends DisplayConverter {
         if(canonicalValue instanceof QuantitativeData){
             return DescriptionHelper.getLabel(canonicalValue);
         }
-        return canonicalValue.toString();
+        if(canonicalValue!=null){
+            return canonicalValue.toString();
+        }
+        return null;
     }
 
     /**