Project

General

Profile

Download (4.16 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.selection.SelectionLayer.MoveDirectionEnum;
19
import org.eclipse.nebula.widgets.nattable.widget.EditModeEnum;
20
import org.eclipse.swt.widgets.Composite;
21
import org.eclipse.swt.widgets.Control;
22

    
23
import eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO;
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, 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 boolean commit(MoveDirectionEnum direction, boolean closeAfterCommit, boolean skipValidation) {
77
        boolean commit = super.commit(direction, closeAfterCommit, skipValidation);
78
        return commit;
79
    }
80

    
81
    @Override
82
    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
        this.closed = true;
89
        this.dialog = null;
90
        this.editorValue = null;
91
    }
92

    
93
    @Override
94
    public boolean isClosed() {
95
        return closed;
96
    }
97

    
98
    @Override
99
    public Control activateCell(Composite parent, Object originalCanonicalValue, EditModeEnum editMode,
100
            ICellEditHandler editHandler, ILayerCell cell, IConfigRegistry configRegistry) {
101
        this.initialInput = null;
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
        return super.activateCell(parent, cell.getDataValue(), editMode, editHandler, cell, configRegistry);
112
    }
113

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

    
120
}
(5-5/7)