Project

General

Profile

Download (7.24 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
import java.util.Set;
15

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

    
27
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.categorical.CategoricalComboBoxDataProvider;
28
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.categorical.CategoricalDataCellEditor;
29
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.categorical.CategoricalDataDisplayConverter;
30
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.quantitative.QuantitativeDataDialogEditor;
31
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.quantitative.QuantitativeDataEditModeDisplayConverter;
32
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.quantitative.QuantitativeDataNormalModeDisplayConverter;
33
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.supplementalInfo.SupplementalInfoDisplayConverter;
34

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

    
42
    private CharacterMatrix matrix;
43

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

    
49
    @Override
50
    public void configureRegistry(IConfigRegistry configRegistry) {
51

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

    
74
        //---register cell editors---
75

    
76
        /**
77
         * categorical cell editor
78
         */
79
        //make cell editable
80
        configRegistry.registerConfigAttribute(
81
                EditConfigAttributes.CELL_EDITABLE_RULE,
82
//                getEditRule(matrix.getBodyDataProvider()),
83
                IEditableRule.ALWAYS_EDITABLE,
84
                DisplayMode.EDIT,
85
                CharacterMatrixConfigLabelAccumulator.CATEGORICAL_EDITABLE
86
                );
87
        //add display converter for string representation
88
        configRegistry.registerConfigAttribute(
89
                CellConfigAttributes.DISPLAY_CONVERTER,
90
                new CategoricalDataDisplayConverter(),
91
                DisplayMode.NORMAL,
92
                CharacterMatrixConfigLabelAccumulator.CATEGORICAL
93
                );
94
        //register categorical editor
95
        configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR,
96
                new CategoricalDataCellEditor(matrix, new CategoricalComboBoxDataProvider(matrix)),
97
                DisplayMode.EDIT,
98
                CharacterMatrixConfigLabelAccumulator.CATEGORICAL_EDITABLE
99
                );
100

    
101

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

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

    
144
        Point size = new Point(250, 300);
145
        editDialogSettings.put(ICellEditDialog.DIALOG_SHELL_SIZE, size);
146

    
147
        //FIXME: this is not displayed because the cell editor
148
        //is already a dialog. Maybe the cell editor and the
149
        //dialog can be merged
150
        editDialogSettings.put(ICellEditDialog.DIALOG_MESSAGE, "Enter exact values:");
151

    
152
        configRegistry.registerConfigAttribute(
153
                EditConfigAttributes.EDIT_DIALOG_SETTINGS,
154
                editDialogSettings,
155
                DisplayMode.EDIT,
156
                CharacterMatrixConfigLabelAccumulator.QUANTITATIVE_EDITABLE);
157
    }
158
   
159
    
160
//    private static IEditableRule getEditRule(final IDataProvider dataProvider) {
161
//    			return new EditableRule(){
162
//    			public boolean isEditable(int columnIndex, int rowIndex) {
163
//    				Object dataValue = dataProvider.getDataValue(columnIndex, rowIndex);
164
//    				if (dataValue instanceof Set && ((Set)dataValue).size()>1){
165
//    					return false;
166
//    				}else return true;
167
//    				}
168
//    			};
169
//    		}
170

    
171
}
(2-2/18)