Project

General

Profile

Download (7.33 KB) Statistics
| Branch: | Tag: | Revision:
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;
11

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

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

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

    
33
/**
34
 * @author pplitzner
35
 * @date 09.07.2018
36
 *
37
 */
38
final class CellEditorDataConversionConfiguration extends AbstractRegistryConfiguration {
39

    
40
    private CharacterMatrix matrix;
41

    
42
    public CellEditorDataConversionConfiguration(CharacterMatrix matrix) {
43
        super();
44
        this.matrix = matrix;
45
    }
46

    
47
    @Override
48
    public void configureRegistry(IConfigRegistry configRegistry) {
49

    
50
        //add display converter for string representation
51
        configRegistry.registerConfigAttribute(
52
                CellConfigAttributes.DISPLAY_CONVERTER,
53
                new SupplementalInfoDisplayConverter(),
54
                DisplayMode.NORMAL,
55
                CharacterMatrix.TAXON_COLUMN);
56
        configRegistry.registerConfigAttribute(
57
                CellConfigAttributes.DISPLAY_CONVERTER,
58
                new SupplementalInfoDisplayConverter(),
59
                DisplayMode.NORMAL,
60
                CharacterMatrix.COLLECTOR_COLUMN);
61
        configRegistry.registerConfigAttribute(
62
                CellConfigAttributes.DISPLAY_CONVERTER,
63
                new SupplementalInfoDisplayConverter(),
64
                DisplayMode.NORMAL,
65
                CharacterMatrix.IDENTIFIER_COLUMN);
66
        configRegistry.registerConfigAttribute(
67
                CellConfigAttributes.DISPLAY_CONVERTER,
68
                new SupplementalInfoDisplayConverter(),
69
                DisplayMode.NORMAL,
70
                CharacterMatrix.COUNTRY_COLUMN);
71

    
72
        //---register cell editors---
73

    
74
        /**
75
         * categorical cell editor
76
         */
77
        //make cell editable
78
        configRegistry.registerConfigAttribute(
79
                EditConfigAttributes.CELL_EDITABLE_RULE,
80
                IEditableRule.ALWAYS_EDITABLE,
81
                DisplayMode.EDIT,
82
                CharacterMatrixConfigLabelAccumulator.CATEGORICAL
83
                );
84
        //add display converter for string representation
85
        configRegistry.registerConfigAttribute(
86
                CellConfigAttributes.DISPLAY_CONVERTER,
87
                new CategoricalDataDisplayConverter(),
88
                DisplayMode.NORMAL,
89
                CharacterMatrixConfigLabelAccumulator.CATEGORICAL
90
                );
91

    
92

    
93
        /**
94
         * quantitative cell editor
95
         */
96
        //make cell editable
97
        configRegistry.registerConfigAttribute(
98
                EditConfigAttributes.CELL_EDITABLE_RULE,
99
                IEditableRule.ALWAYS_EDITABLE,
100
                DisplayMode.EDIT,
101
                CharacterMatrixConfigLabelAccumulator.QUANTITATIVE
102
                );
103
        //add display converter for string representation
104
        configRegistry.registerConfigAttribute(
105
                CellConfigAttributes.DISPLAY_CONVERTER,
106
                new QuantitativeDataEditModeDisplayConverter(),
107
                DisplayMode.EDIT,
108
                CharacterMatrixConfigLabelAccumulator.QUANTITATIVE);
109
        configRegistry.registerConfigAttribute(
110
                CellConfigAttributes.DISPLAY_CONVERTER,
111
                new QuantitativeDataNormalModeDisplayConverter(),
112
                DisplayMode.NORMAL,
113
                CharacterMatrixConfigLabelAccumulator.QUANTITATIVE);
114

    
115
        /**
116
         * exact value editor
117
         */
118
        //Open cell editor in dialog
119
        configRegistry.registerConfigAttribute(
120
                EditConfigAttributes.OPEN_IN_DIALOG,
121
                Boolean.TRUE,
122
                DisplayMode.EDIT,
123
                CharacterMatrixConfigLabelAccumulator.QUANT_EXACT);
124
        //register quantitative editor
125
        configRegistry.registerConfigAttribute(
126
                EditConfigAttributes.CELL_EDITOR,
127
                new QuantitativeDataDialogEditor(matrix),
128
                DisplayMode.EDIT,
129
                CharacterMatrixConfigLabelAccumulator.QUANT_EXACT);
130
        // configure custom dialog settings
131
        Map<String, Object> editDialogSettings = new HashMap<>();
132
        editDialogSettings.put(ICellEditDialog.DIALOG_SHELL_TITLE, "Quantitative Data");
133
        editDialogSettings.put(ICellEditDialog.DIALOG_SHELL_RESIZABLE, Boolean.TRUE);
134

    
135
        Point size = new Point(230, 300);
136
        editDialogSettings.put(ICellEditDialog.DIALOG_SHELL_SIZE, size);
137

    
138
        // add custum message
139
        //FIXME: this is not displayed because the cell editor
140
        //is already a dialog. Maybe the cell editor and the
141
        //dialog can be merged
142
        editDialogSettings.put(ICellEditDialog.DIALOG_MESSAGE, "Enter exact values:");
143

    
144
        configRegistry.registerConfigAttribute(
145
                EditConfigAttributes.EDIT_DIALOG_SETTINGS,
146
                editDialogSettings,
147
                DisplayMode.EDIT,
148
                CharacterMatrixConfigLabelAccumulator.QUANT_EXACT);
149

    
150

    
151
        //TODO: this for loop can maybe be avoided
152
        matrix.getFeatures().forEach(feature->registerColumnConfiguration(feature, configRegistry));
153
    }
154

    
155
    private void registerColumnConfiguration(Feature feature, IConfigRegistry configRegistry) {
156
        if(feature.isSupportsQuantitativeData()){
157
        /**
158
         * aggregated value editor
159
         */
160
        configRegistry.registerConfigAttribute(
161
                EditConfigAttributes.CELL_EDITOR,
162
                new QuantitativeDataCellEditor(feature, matrix),
163
                DisplayMode.EDIT,
164
                CharacterMatrixConfigLabelAccumulator.QUANT_AGGREGATED);
165
        }
166
        else if(feature.isSupportsCategoricalData()){
167
            //add combo box cell editor
168
            //register editor
169
            configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR,
170
                    new CategoricalDataCellEditor(matrix.getSupportedStatesForCategoricalFeature(feature), matrix, feature),
171
                    DisplayMode.EDIT,
172
                    MatrixUtility.getProperty(feature));
173

    
174
        }
175

    
176
    }
177
}
(4-4/20)