Project

General

Profile

Download (6.74 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.QuantitativeDataDialogEditor;
28
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.quantitative.QuantitativeDataEditModeDisplayConverter;
29
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.quantitative.QuantitativeDataNormalModeDisplayConverter;
30
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.supplementalInfo.SupplementalInfoDisplayConverter;
31

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

    
39
    private CharacterMatrix matrix;
40

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

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

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

    
71
        //---register cell editors---
72

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

    
89

    
90
        //quantitative cell editor
91
        //make cell editable
92
        configRegistry.registerConfigAttribute(
93
                EditConfigAttributes.CELL_EDITABLE_RULE,
94
                IEditableRule.ALWAYS_EDITABLE,
95
                DisplayMode.EDIT,
96
                CharacterMatrixConfigLabelAccumulator.QUANTITATIVE
97
                );
98
      //add display converter for string representation
99
        configRegistry.registerConfigAttribute(
100
                CellConfigAttributes.DISPLAY_CONVERTER,
101
                new QuantitativeDataEditModeDisplayConverter(),
102
                DisplayMode.EDIT,
103
                CharacterMatrixConfigLabelAccumulator.QUANTITATIVE);
104
        configRegistry.registerConfigAttribute(
105
                CellConfigAttributes.DISPLAY_CONVERTER,
106
                new QuantitativeDataNormalModeDisplayConverter(),
107
                DisplayMode.NORMAL,
108
                CharacterMatrixConfigLabelAccumulator.QUANTITATIVE);
109
        //Open cell editorin dialog
110
        configRegistry.registerConfigAttribute(
111
                EditConfigAttributes.OPEN_IN_DIALOG,
112
                Boolean.TRUE,
113
                DisplayMode.EDIT,
114
                CharacterMatrixConfigLabelAccumulator.QUANTITATIVE);
115
        //register quantitative editor
116
        configRegistry.registerConfigAttribute(
117
                EditConfigAttributes.CELL_EDITOR,
118
                new QuantitativeDataDialogEditor(matrix),
119
                DisplayMode.EDIT,
120
                CharacterMatrixConfigLabelAccumulator.QUANTITATIVE);
121
        // configure custom dialog settings
122
        Map<String, Object> editDialogSettings = new HashMap<>();
123
        editDialogSettings.put(ICellEditDialog.DIALOG_SHELL_TITLE, "Quantitative Data");
124
        editDialogSettings.put(ICellEditDialog.DIALOG_SHELL_RESIZABLE, Boolean.TRUE);
125

    
126
        Point size = new Point(230, 300);
127
        editDialogSettings.put(ICellEditDialog.DIALOG_SHELL_SIZE, size);
128

    
129
        // add custum message
130
        //FIXME: this is not displayed because the cell editor
131
        //is already a dialog. Maybe the cell editor and the
132
        //dialog can be merged
133
        editDialogSettings.put(ICellEditDialog.DIALOG_MESSAGE, "Enter exact values:");
134

    
135
        configRegistry.registerConfigAttribute(
136
                EditConfigAttributes.EDIT_DIALOG_SETTINGS,
137
                editDialogSettings,
138
                DisplayMode.EDIT,
139
                CharacterMatrixConfigLabelAccumulator.QUANTITATIVE);
140

    
141

    
142
        //TODO: this for loop can maybe be avoided
143
        matrix.getFeatures().forEach(feature->registerColumnConfiguration(feature, configRegistry));
144
    }
145

    
146
    private void registerColumnConfiguration(Feature feature, IConfigRegistry configRegistry) {
147
        if(feature.isSupportsCategoricalData()){
148
            //add combo box cell editor
149
            //register editor
150
            configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR,
151
                    new CategoricalDataCellEditor(matrix.getSupportedStatesForCategoricalFeature(feature), matrix, feature),
152
                    DisplayMode.EDIT,
153
                    MatrixUtility.getProperty(feature));
154

    
155
        }
156

    
157
    }
158
}
(4-4/20)