Project

General

Profile

Download (6.48 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.taxeditor.editor.descriptiveDataSet.matrix.categorical.CategoricalComboBoxDataProvider;
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
        /**
74
         * categorical cell editor
75
         */
76
        //make cell editable
77
        configRegistry.registerConfigAttribute(
78
                EditConfigAttributes.CELL_EDITABLE_RULE,
79
                IEditableRule.ALWAYS_EDITABLE,
80
                DisplayMode.EDIT,
81
                CharacterMatrixConfigLabelAccumulator.CATEGORICAL
82
                );
83
        //add display converter for string representation
84
        configRegistry.registerConfigAttribute(
85
                CellConfigAttributes.DISPLAY_CONVERTER,
86
                new CategoricalDataDisplayConverter(),
87
                DisplayMode.NORMAL,
88
                CharacterMatrixConfigLabelAccumulator.CATEGORICAL
89
                );
90
        //register categorical editor
91
        configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR,
92
                new CategoricalDataCellEditor(matrix, new CategoricalComboBoxDataProvider(matrix)),
93
                DisplayMode.EDIT,
94
                CharacterMatrixConfigLabelAccumulator.CATEGORICAL
95
                );
96

    
97

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

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

    
137
        Point size = new Point(250, 300);
138
        editDialogSettings.put(ICellEditDialog.DIALOG_SHELL_SIZE, size);
139

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

    
145
        configRegistry.registerConfigAttribute(
146
                EditConfigAttributes.EDIT_DIALOG_SETTINGS,
147
                editDialogSettings,
148
                DisplayMode.EDIT,
149
                CharacterMatrixConfigLabelAccumulator.QUANTITATIVE);
150
    }
151

    
152
}
(4-4/20)