Project

General

Profile

Download (4.26 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2018 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.Map;
12

    
13
import org.eclipse.jface.window.Window;
14
import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
15
import org.eclipse.nebula.widgets.nattable.edit.ICellEditHandler;
16
import org.eclipse.nebula.widgets.nattable.edit.gui.AbstractDialogCellEditor;
17
import org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell;
18
import org.eclipse.nebula.widgets.nattable.widget.EditModeEnum;
19
import org.eclipse.swt.widgets.Composite;
20
import org.eclipse.swt.widgets.Control;
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.taxeditor.editor.descriptiveDataSet.matrix.CharacterMatrix;
26

    
27
/**
28
 * @author pplitzner
29
 * @since Jul 19, 2018
30
 *
31
 */
32
public class QuantitativeDataDialogEditor extends AbstractDialogCellEditor {
33

    
34
    private QuantitativeData editorValue;
35
    private boolean closed;
36
    private CharacterMatrix matrix;
37
    private Character initialInput;
38

    
39
    public QuantitativeDataDialogEditor(CharacterMatrix matrix) {
40
        super();
41
        this.matrix = matrix;
42
    }
43

    
44
    @Override
45
    public int open() {
46
        Object rowObject = matrix.getBodyDataProvider().getRowObject(getRowIndex());
47
        if(rowObject instanceof RowWrapperDTO){
48
            this.closed = false;
49
            return getDialogInstance().open();
50
        }
51
        return Window.CANCEL;
52
    }
53

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

    
59
    @Override
60
    public QuantitativeDataDialog getDialogInstance() {
61
        return (QuantitativeDataDialog) this.dialog;
62
    }
63

    
64
    @Override
65
    public Object getEditorValue() {
66
        return this.editorValue;
67
    }
68

    
69
    @Override
70
    public void setEditorValue(Object value) {
71
        ((QuantitativeDataDialog)this.dialog).setEditorValue((QuantitativeData) value);
72
        this.editorValue = (QuantitativeData) value;
73
    }
74

    
75
    @Override
76
    public void close() {
77
        this.closed = true;
78
        this.dialog = null;
79
        this.editorValue = null;
80
    }
81

    
82
    @Override
83
    public boolean isClosed() {
84
        return closed;
85
    }
86

    
87
    @Override
88
    public Control activateCell(Composite parent, Object originalCanonicalValue, EditModeEnum editMode,
89
            ICellEditHandler editHandler, ILayerCell cell, IConfigRegistry configRegistry) {
90
        this.initialInput = null;
91
        Object rowObject = matrix.getBodyDataProvider().getRowObject(cell.getRowIndex());
92
        Feature feature = matrix.getIndexToFeatureMap().get(cell.getColumnIndex());
93
        QuantitativeData quantitativeData = null;
94
        if(rowObject instanceof RowWrapperDTO){
95
            if(cell.getDataValue() instanceof QuantitativeData){
96
                quantitativeData = (QuantitativeData) cell.getDataValue();
97
            }
98
            //create new Quantitative Data
99
            if (cell.getDataValue() == null) {
100
                quantitativeData = ((RowWrapperDTO) rowObject).addQuantitativeData(feature);
101
            }
102
            /**
103
             * when opening the the dialog by a key stroke, store the key pressed
104
             * and pass it to the dialog. This is common behavior but by overriding
105
             * this method we always pass the QuantitativeData object to the dialog
106
             * so we need to buffer the key stroke
107
             */
108
            if(originalCanonicalValue instanceof Character){
109
                this.initialInput = (Character) originalCanonicalValue;
110
            }
111
        }
112
        return super.activateCell(parent, quantitativeData, editMode, editHandler, cell, configRegistry);
113
    }
114

    
115
    @Override
116
    public void setDialogSettings(Map<String, Object> editDialogSettings) {
117
        //pass through dialog setting to wrapped dialog
118
        ((QuantitativeDataDialog)this.dialog).setDialogSettings(editDialogSettings);
119
    }
120

    
121
}
(3-3/5)