Project

General

Profile

« Previous | Next » 

Revision d12e0f5d

Added by Patrick Plitzner almost 6 years ago

ref #7575 Enable quantitative dialog cell editor

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CellEditorDataConversionConfiguration.java
9 9
*/
10 10
package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix;
11 11

  
12
import java.util.HashMap;
13
import java.util.Map;
14

  
12 15
import org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration;
13 16
import org.eclipse.nebula.widgets.nattable.config.CellConfigAttributes;
14 17
import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
15 18
import org.eclipse.nebula.widgets.nattable.config.IEditableRule;
16 19
import org.eclipse.nebula.widgets.nattable.edit.EditConfigAttributes;
20
import org.eclipse.nebula.widgets.nattable.edit.gui.ICellEditDialog;
17 21
import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
22
import org.eclipse.swt.graphics.Point;
18 23

  
19 24
import eu.etaxonomy.cdm.model.description.Feature;
20 25
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.categorical.CategoricalDataCellEditor;
21 26
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.categorical.CategoricalDataDisplayConverter;
22
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.quantitative.QuantitativeDataCellEditor;
23
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.quantitative.QuantitativeDataDisplayConverter;
27
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.quantitative.QuantitativeDataDialogEditor;
28
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.quantitative.QuantitativeDataNormalModeDisplayConverter;
29
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.quantitative.QuantitativeDataEditModeDisplayConverter;
24 30
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.supplementalInfo.SupplementalInfoDisplayConverter;
25 31

  
26 32
/**
......
28 34
 * @date 09.07.2018
29 35
 *
30 36
 */
31
final class DataConversionConfiguration extends AbstractRegistryConfiguration {
37
final class CellEditorDataConversionConfiguration extends AbstractRegistryConfiguration {
32 38

  
33 39
    private CharacterMatrix matrix;
34 40

  
35
    public DataConversionConfiguration(CharacterMatrix matrix) {
41
    public CellEditorDataConversionConfiguration(CharacterMatrix matrix) {
36 42
        super();
37 43
        this.matrix = matrix;
38 44
    }
......
76 82
            //add display converter for string representation
77 83
            configRegistry.registerConfigAttribute(
78 84
                    CellConfigAttributes.DISPLAY_CONVERTER,
79
                    new QuantitativeDataDisplayConverter(),
85
                    new QuantitativeDataEditModeDisplayConverter(),
86
                    DisplayMode.EDIT,
87
                    MatrixUtility.getProperty(feature));
88
            configRegistry.registerConfigAttribute(
89
                    CellConfigAttributes.DISPLAY_CONVERTER,
90
                    new QuantitativeDataNormalModeDisplayConverter(),
80 91
                    DisplayMode.NORMAL,
81 92
                    MatrixUtility.getProperty(feature));
93
            //Open cell editorin dialog
94
            configRegistry.registerConfigAttribute(
95
                    EditConfigAttributes.OPEN_IN_DIALOG,
96
                    Boolean.TRUE,
97
                    DisplayMode.EDIT,
98
                    MatrixUtility.getProperty(feature));
82 99
            //register quantitative editor
83 100
            configRegistry.registerConfigAttribute(
84 101
                    EditConfigAttributes.CELL_EDITOR,
85
                    new QuantitativeDataCellEditor(feature, matrix),
102
                    new QuantitativeDataDialogEditor(matrix),
86 103
                    DisplayMode.EDIT,
87 104
                    MatrixUtility.getProperty(feature));
105
            // configure custom dialog settings
106
            Map<String, Object> editDialogSettings = new HashMap<>();
107
            editDialogSettings.put(ICellEditDialog.DIALOG_SHELL_TITLE, "Quantitative Data");
108
            editDialogSettings.put(ICellEditDialog.DIALOG_SHELL_RESIZABLE, Boolean.TRUE);
109

  
110
            Point size = new Point(230, 300);
111
            editDialogSettings.put(ICellEditDialog.DIALOG_SHELL_SIZE, size);
112

  
113
            // add custum message
114
            //FIXME: this is not displayed because the cell editor
115
            //is already a dialog. Maybe the cell editor and the
116
            //dialog can be merged
117
            editDialogSettings.put(ICellEditDialog.DIALOG_MESSAGE, "Enter exact values:");
118

  
119
            configRegistry.registerConfigAttribute(
120
                    EditConfigAttributes.EDIT_DIALOG_SETTINGS,
121
                    editDialogSettings,
122
                    DisplayMode.EDIT,
123
                    MatrixUtility.getProperty(feature));
124

  
88 125
        }
89 126
        else if(feature.isSupportsCategoricalData()){
90 127
            //add display converter for string representation
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/MatrixUtility.java
9 9
package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix;
10 10

  
11 11
import java.util.Set;
12
import java.util.stream.Collectors;
12 13

  
13 14
import eu.etaxonomy.cdm.model.description.DescriptiveDataSet;
14 15
import eu.etaxonomy.cdm.model.description.Feature;
......
40 41
     * @return a string representation of the data
41 42
     */
42 43
    public static String getQuantitativeLabel(QuantitativeData data) {
43
        Float min = data.getMin();
44
        Float max = data.getMax();
45
        Float exact = data.getSpecificStatisticalValue(StatisticalMeasure.EXACT_VALUE());
46
        return getQuantitativeLabel(min, exact, max);
44
        return data.getStatisticalValues().stream().
45
        filter(value->value.getType().equals(StatisticalMeasure.EXACT_VALUE()))
46
        .map(exact->Float.toString(exact.getValue()))
47
        .collect(Collectors.joining(", "));
47 48
    }
48 49

  
49 50
    /**
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/quantitative/QuantitativeDataComposite.java
1
// $Id$
2
/**
3
* Copyright (C) 2018 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.quantitative;
11

  
12
import org.eclipse.swt.SWT;
13
import org.eclipse.swt.layout.GridData;
14
import org.eclipse.swt.layout.GridLayout;
15
import org.eclipse.swt.widgets.Button;
16
import org.eclipse.swt.widgets.Composite;
17
import org.eclipse.swt.widgets.Text;
18

  
19
/**
20
 * @author pplitzner
21
 * @date 17.07.2018
22
 *
23
 */
24
public class QuantitativeDataComposite extends Composite {
25
    private Text text;
26
    private Button btnAdvancedEdit;
27

  
28
    public QuantitativeDataComposite(Composite parent, int style) {
29
        super(parent, style);
30
        setLayout(new GridLayout(2, false));
31

  
32
        text = new Text(this, SWT.BORDER);
33
        text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
34

  
35
        btnAdvancedEdit = new Button(this, SWT.NONE);
36
        btnAdvancedEdit.setText("+");
37
        // TODO Auto-generated constructor stub
38
    }
39

  
40
    public Text getText() {
41
        return text;
42
    }
43
    public Button getBtnAdvancedEdit() {
44
        return btnAdvancedEdit;
45
    }
46
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/quantitative/QuantitativeDataDialog.java
11 11
import java.util.List;
12 12
import java.util.stream.Collectors;
13 13

  
14
import org.eclipse.jface.window.Window;
14 15
import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
15 16
import org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor;
16 17
import org.eclipse.nebula.widgets.nattable.edit.gui.CellEditDialog;
......
24 25
import eu.etaxonomy.cdm.model.description.QuantitativeData;
25 26
import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
26 27
import eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue;
28
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.CharacterMatrix;
27 29

  
28 30
/**
29 31
 * @author pplitzner
......
34 36

  
35 37
    private Character initialInput;
36 38

  
37
    public QuantitativeDataDialog(Character initialInput, Shell parentShell, Object originalCanonicalValue, ILayerCell cell,
39
    private CharacterMatrix matrix;
40

  
41
    public QuantitativeDataDialog(Character initialInput, CharacterMatrix matrix, Shell parentShell, Object originalCanonicalValue, ILayerCell cell,
38 42
            ICellEditor cellEditor, IConfigRegistry configRegistry) {
39 43
        super(parentShell, originalCanonicalValue, cell, cellEditor, configRegistry);
40 44
        this.initialInput = initialInput;
45
        this.matrix = matrix;
41 46
    }
42 47

  
43 48
    private QuantitativeData editorValue;
......
54 59
        this.editorValue = editorValue;
55 60
    }
56 61

  
62
    @Override
63
    public boolean close() {
64
        if(getReturnCode()==Window.OK){
65
            updateQuantitativeData(editorValue);
66
            matrix.setDirty();
67
        }
68
        return super.close();
69
    }
70

  
57 71
    void updateQuantitativeData(QuantitativeData object){
58 72
        QuantitativeData quantitativeData = object;
59 73
        //get all non-exact values
......
74 88
            } catch (NumberFormatException e) {
75 89
            }
76 90
        }
77

  
78 91
    }
79 92

  
80 93
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/quantitative/QuantitativeDataDialogComposite.java
78 78
        textFields.add(text);
79 79

  
80 80
        Button btnNewButton_2 = new Button(composite_2, SWT.NONE);
81
        btnNewButton_2.setImage(ImageResources.getImage(ImageResources.ACTIVE_DELETE_ICON));
81
        btnNewButton_2.setImage(ImageResources.getImage(ImageResources.TRASH_ICON));
82 82
        btnNewButton_2.addSelectionListener(new SelectionAdapter() {
83 83
            @Override
84 84
            public void widgetSelected(SelectionEvent e) {
85 85
                text.setText("");
86
                textFields.remove(text);
87
                ((GridData)composite_2.getLayoutData()).exclude = true;
88
                valuesComposite.layout();
89 86
            }
90 87
        });
91 88
        return text;
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/quantitative/QuantitativeDataDialogEditor.java
15 15
import org.eclipse.nebula.widgets.nattable.edit.ICellEditHandler;
16 16
import org.eclipse.nebula.widgets.nattable.edit.gui.AbstractDialogCellEditor;
17 17
import org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell;
18
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer.MoveDirectionEnum;
19 18
import org.eclipse.nebula.widgets.nattable.widget.EditModeEnum;
20 19
import org.eclipse.swt.widgets.Composite;
21 20
import org.eclipse.swt.widgets.Control;
......
53 52

  
54 53
    @Override
55 54
    public QuantitativeDataDialog createDialogInstance() {
56
        return new QuantitativeDataDialog(this.initialInput, this.parent.getShell(), getCanonicalValue(), this.layerCell, this, this.configRegistry);
55
        return new QuantitativeDataDialog(this.initialInput, matrix, this.parent.getShell(), getCanonicalValue(), this.layerCell, this, this.configRegistry);
57 56
    }
58 57

  
59 58
    @Override
......
73 72
    }
74 73

  
75 74
    @Override
76
    public boolean commit(MoveDirectionEnum direction, boolean closeAfterCommit, boolean skipValidation) {
77
        boolean commit = super.commit(direction, closeAfterCommit, skipValidation);
78
        return commit;
79
    }
80

  
81
    @Override
82 75
    public void close() {
83
        if(((QuantitativeDataDialog)this.dialog).getReturnCode()==Window.OK
84
                && getCommittedValue() instanceof QuantitativeData){
85
            ((QuantitativeDataDialog)this.dialog).updateQuantitativeData((QuantitativeData) getCommittedValue());
86
            matrix.setDirty();
87
        }
88 76
        this.closed = true;
89 77
        this.dialog = null;
90 78
        this.editorValue = null;
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/quantitative/QuantitativeDataDisplayConverter.java
1
/**
2
* Copyright (C) 2017 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.quantitative;
10

  
11
import org.eclipse.nebula.widgets.nattable.data.convert.DisplayConverter;
12

  
13
import eu.etaxonomy.cdm.model.description.QuantitativeData;
14
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.MatrixUtility;
15

  
16
/**
17
 * Converts QuantitativeData of one cell of the character matrix to a String.
18
 *
19
 * @author pplitzner
20
 * @since Dec 1, 2017
21
 *
22
 */
23
public class QuantitativeDataDisplayConverter extends DisplayConverter {
24

  
25
    /**
26
     * {@inheritDoc}
27
     */
28
    @Override
29
    public Object canonicalToDisplayValue(Object canonicalValue) {
30
        if(canonicalValue instanceof QuantitativeData){
31
            return MatrixUtility.getQuantitativeLabel((QuantitativeData) canonicalValue);
32
        }
33
        if(canonicalValue!=null){
34
            return canonicalValue.toString();
35
        }
36
        return null;
37
    }
38

  
39
    /**
40
     * {@inheritDoc}
41
     */
42
    @Override
43
    public Object displayToCanonicalValue(Object displayValue) {
44
        return null;
45
    }
46

  
47
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/quantitative/QuantitativeDataEditModeDisplayConverter.java
1
/**
2
* Copyright (C) 2017 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.quantitative;
10

  
11
import org.eclipse.nebula.widgets.nattable.data.convert.DisplayConverter;
12

  
13
import eu.etaxonomy.cdm.model.description.QuantitativeData;
14

  
15
/**
16
 * Converts QuantitativeData of one cell of the character matrix to a String.
17
 *
18
 * @author pplitzner
19
 * @since Dec 1, 2017
20
 *
21
 */
22
public class QuantitativeDataEditModeDisplayConverter extends DisplayConverter {
23

  
24
    @Override
25
    public Object canonicalToDisplayValue(Object canonicalValue) {
26
        if(canonicalValue instanceof QuantitativeData){
27
            return canonicalValue;
28
        }
29
        if(canonicalValue!=null){
30
            return canonicalValue.toString();
31
        }
32
        return null;
33
    }
34

  
35
    @Override
36
    public Object displayToCanonicalValue(Object displayValue) {
37
        return displayValue;
38
    }
39

  
40
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/quantitative/QuantitativeDataExactValueCellEditor.java
1
/**
2
* Copyright (C) 2017 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.quantitative;
10

  
11
import java.util.HashMap;
12
import java.util.Map;
13

  
14
import org.eclipse.nebula.widgets.nattable.edit.editor.AbstractCellEditor;
15
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer.MoveDirectionEnum;
16
import org.eclipse.swt.SWT;
17
import org.eclipse.swt.widgets.Composite;
18
import org.eclipse.swt.widgets.Control;
19
import org.eclipse.swt.widgets.Listener;
20
import org.eclipse.swt.widgets.Text;
21

  
22
import eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO;
23
import eu.etaxonomy.cdm.model.description.Feature;
24
import eu.etaxonomy.cdm.model.description.QuantitativeData;
25
import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
26
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.CharacterMatrix;
27

  
28
/**
29
 *
30
 * Cell editor for QuantitativeData
31
 * @author pplitzner
32
 * @date 17.07.2018
33
 *
34
 */
35
public class QuantitativeDataExactValueCellEditor extends AbstractCellEditor{
36

  
37
    private Control editorControl;
38

  
39
    private Feature feature;
40

  
41
    private Map<StatisticalMeasure, Text> measureToTextMap = new HashMap<>();
42

  
43
    private Object editorValue;
44

  
45
    private CharacterMatrix matrix;
46

  
47
    private boolean dirty = false;
48

  
49
    private QuantitativeDataComposite dataComposite;
50

  
51
    public QuantitativeDataExactValueCellEditor(Feature feature, CharacterMatrix matrix) {
52
        super();
53
        this.matrix = matrix;
54
        this.feature = feature;
55
    }
56

  
57

  
58
    @Override
59
    public Object getEditorValue() {
60
        return this.editorValue;
61
    }
62

  
63
    @Override
64
    public void setEditorValue(Object value) {
65
        this.editorValue = value;
66
    }
67

  
68
    @Override
69
    public Control getEditorControl() {
70
        return editorControl;
71
    }
72

  
73
    @Override
74
    public Control createEditorControl(Composite parent) {
75
        dataComposite = new QuantitativeDataComposite(parent, SWT.NONE);
76
        return dataComposite;
77
    }
78

  
79
    @Override
80
    public boolean commit(MoveDirectionEnum direction, boolean closeAfterCommit, boolean skipValidation) {
81
        if(dirty){
82
            matrix.setDirty();
83
            dirty = false;
84
        }
85
        return super.commit(direction, closeAfterCommit, skipValidation);
86
    }
87

  
88
    @Override
89
    protected Control activateCell(Composite parent, Object originalCanonicalValue) {
90
        Object rowObject = matrix.getBodyDataProvider().getRowObject(this.getRowIndex());
91
        if(rowObject instanceof RowWrapperDTO){
92
            this.editorControl = createEditorControl(parent);
93
            if(originalCanonicalValue==null){
94
                originalCanonicalValue = ((RowWrapperDTO) rowObject).addQuantitativeData(feature);
95
            }
96
            this.setEditorValue(originalCanonicalValue);
97

  
98
                //Fill text controls with actual values and add modify listeners for editing
99
            if(originalCanonicalValue instanceof QuantitativeData){
100
                QuantitativeData quantitativeData = (QuantitativeData)originalCanonicalValue;
101
                long exactValuesCount = quantitativeData.getStatisticalValues().stream()
102
                .filter(val->val.getType().equals(StatisticalMeasure.EXACT_VALUE()))
103
                .count();
104
                if(exactValuesCount>1){
105
                    dataComposite.getText().setText("...");
106
                    dataComposite.getText().setEnabled(false);
107
                }
108
                else if(exactValuesCount==1){
109
                    Float exactValue = quantitativeData.getSpecificStatisticalValue(StatisticalMeasure.EXACT_VALUE());
110
                    dataComposite.getText().setText(exactValue.toString());
111
                    dataComposite.getText().addModifyListener(e->{
112
                        try {
113
                            float parseFloat = Float.parseFloat(dataComposite.getText().getText());
114
                            quantitativeData.setSpecificStatisticalValue(parseFloat, null, StatisticalMeasure.EXACT_VALUE());
115
                            dirty = true;
116
                        } catch (NumberFormatException|NullPointerException ex) {
117
                            // ignore exception for wrong number format
118
                        }
119
                    });
120
                }
121
            }
122
        }
123
        return this.editorControl;
124
    }
125

  
126
    private void setText(Float specificStatisticalValue, Text text){
127
        if(specificStatisticalValue!=null){
128
            Listener[] listeners = text.getListeners(SWT.Modify);
129
            for (Listener listener : listeners) {
130
                text.removeListener(SWT.Modify, listener);
131
            }
132
            text.setText(Float.toString(specificStatisticalValue));
133
            for (Listener listener : listeners) {
134
                text.addListener(SWT.Modify, listener);
135
            }
136
        }
137
    }
138

  
139
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/quantitative/QuantitativeDataNormalModeDisplayConverter.java
1
/**
2
* Copyright (C) 2017 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.quantitative;
10

  
11
import org.eclipse.nebula.widgets.nattable.data.convert.DisplayConverter;
12

  
13
import eu.etaxonomy.cdm.model.description.QuantitativeData;
14
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.MatrixUtility;
15

  
16
/**
17
 * Converts QuantitativeData of one cell of the character matrix to a String.
18
 *
19
 * @author pplitzner
20
 * @since Dec 1, 2017
21
 *
22
 */
23
public class QuantitativeDataNormalModeDisplayConverter extends DisplayConverter {
24

  
25
    @Override
26
    public Object canonicalToDisplayValue(Object canonicalValue) {
27
        if(canonicalValue instanceof QuantitativeData){
28
            return MatrixUtility.getQuantitativeLabel((QuantitativeData) canonicalValue);
29
        }
30
        if(canonicalValue!=null){
31
            return canonicalValue.toString();
32
        }
33
        return null;
34
    }
35

  
36
    @Override
37
    public Object displayToCanonicalValue(Object displayValue) {
38
        return displayValue;
39
    }
40

  
41
}

Also available in: Unified diff