2 * Copyright (C) 2018 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.editor
.descriptiveDataSet
.matrix
.quantitative
;
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
;
22 import eu
.etaxonomy
.cdm
.api
.service
.dto
.RowWrapperDTO
;
23 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
24 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
25 import eu
.etaxonomy
.cdm
.model
.description
.QuantitativeData
;
26 import eu
.etaxonomy
.taxeditor
.editor
.descriptiveDataSet
.matrix
.CharacterMatrix
;
33 public class QuantitativeDataDialogEditor
extends AbstractDialogCellEditor
{
35 private QuantitativeData editorValue
;
36 private RowWrapperDTO
<?
> rowWrapperDTO
;
37 private boolean closed
;
38 private CharacterMatrix matrix
;
39 private Character initialInput
;
41 public QuantitativeDataDialogEditor(CharacterMatrix matrix
) {
48 Object rowObject
= matrix
.getBodyDataProvider().getRowObject(getRowIndex());
49 if(rowObject
instanceof RowWrapperDTO
){
51 return getDialogInstance().open();
57 public QuantitativeDataDialog
createDialogInstance() {
58 return new QuantitativeDataDialog(this.initialInput
, matrix
, this.parent
.getShell(), getCanonicalValue(), this.layerCell
, this, this.configRegistry
);
62 public QuantitativeDataDialog
getDialogInstance() {
63 return (QuantitativeDataDialog
) this.dialog
;
67 public Object
getEditorValue() {
68 return this.editorValue
;
72 public void setEditorValue(Object value
) {
73 ((QuantitativeDataDialog
)this.dialog
).setEditorValue((QuantitativeData
) value
);
74 ((QuantitativeDataDialog
)this.dialog
).setRowWrapper(rowWrapperDTO
);
75 this.editorValue
= (QuantitativeData
) value
;
82 this.editorValue
= null;
86 public boolean isClosed() {
91 public Control
activateCell(Composite parent
, Object originalCanonicalValue
, EditModeEnum editMode
,
92 ICellEditHandler editHandler
, ILayerCell cell
, IConfigRegistry configRegistry
) {
93 this.initialInput
= null;
94 Object rowObject
= matrix
.getBodyDataProvider().getRowObject(cell
.getRowIndex());
95 Feature feature
= matrix
.getIndexToFeatureMap().get(cell
.getColumnIndex());
96 QuantitativeData quantitativeData
= null;
97 if(rowObject
instanceof RowWrapperDTO
){
98 rowWrapperDTO
= (RowWrapperDTO
<?
>) rowObject
;
99 DescriptionElementBase dataValueForFeature
= rowWrapperDTO
.getDataValueForFeature(feature
);
100 if(dataValueForFeature
instanceof QuantitativeData
){
101 quantitativeData
= (QuantitativeData
) dataValueForFeature
;
103 //create new Quantitative Data
104 if (quantitativeData
== null) {
105 quantitativeData
= ((RowWrapperDTO
) rowObject
).addQuantitativeData(feature
);
108 * when opening the the dialog by a key stroke, store the key pressed
109 * and pass it to the dialog. This is common behavior but by overriding
110 * this method we always pass the QuantitativeData object to the dialog
111 * so we need to buffer the key stroke
113 if(originalCanonicalValue
instanceof Character
){
114 this.initialInput
= (Character
) originalCanonicalValue
;
117 return super.activateCell(parent
, quantitativeData
, editMode
, editHandler
, cell
, configRegistry
);
121 public void setDialogSettings(Map
<String
, Object
> editDialogSettings
) {
122 //pass through dialog setting to wrapped dialog
123 ((QuantitativeDataDialog
)this.dialog
).setDialogSettings(editDialogSettings
);