Project

General

Profile

Download (4.62 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 org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration;
13
import org.eclipse.nebula.widgets.nattable.config.CellConfigAttributes;
14
import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
15
import org.eclipse.nebula.widgets.nattable.config.IEditableRule;
16
import org.eclipse.nebula.widgets.nattable.edit.EditConfigAttributes;
17
import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
18

    
19
import eu.etaxonomy.cdm.model.description.Feature;
20
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.categorical.CategoricalDataCellEditor;
21
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.categorical.CategoricalDataDisplayConverter;
22
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.quantitative.QuantitativeDataCellEditor;
23
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.quantitative.QuantitativeDataDisplayConverter;
24
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.supplementalInfo.SupplementalInfoDisplayConverter;
25

    
26
/**
27
 * @author pplitzner
28
 * @date 09.07.2018
29
 *
30
 */
31
final class DataConversionConfiguration extends AbstractRegistryConfiguration {
32

    
33
    private CharacterMatrix matrix;
34

    
35
    public DataConversionConfiguration(CharacterMatrix matrix) {
36
        super();
37
        this.matrix = matrix;
38
    }
39

    
40
    @Override
41
    public void configureRegistry(IConfigRegistry configRegistry) {
42

    
43
        //add display converter for string representation
44
        configRegistry.registerConfigAttribute(
45
                CellConfigAttributes.DISPLAY_CONVERTER,
46
                new SupplementalInfoDisplayConverter(),
47
                DisplayMode.NORMAL,
48
                CharacterMatrix.TAXON_COLUMN);
49
        configRegistry.registerConfigAttribute(
50
                CellConfigAttributes.DISPLAY_CONVERTER,
51
                new SupplementalInfoDisplayConverter(),
52
                DisplayMode.NORMAL,
53
                CharacterMatrix.COLLECTOR_COLUMN);
54
        configRegistry.registerConfigAttribute(
55
                CellConfigAttributes.DISPLAY_CONVERTER,
56
                new SupplementalInfoDisplayConverter(),
57
                DisplayMode.NORMAL,
58
                CharacterMatrix.IDENTIFIER_COLUMN);
59
        configRegistry.registerConfigAttribute(
60
                CellConfigAttributes.DISPLAY_CONVERTER,
61
                new SupplementalInfoDisplayConverter(),
62
                DisplayMode.NORMAL,
63
                CharacterMatrix.COUNTRY_COLUMN);
64
        matrix.getFeatures().forEach(feature->registerColumnConfiguration(feature, configRegistry));
65
    }
66

    
67
    private void registerColumnConfiguration(Feature feature, IConfigRegistry configRegistry) {
68
        //make cell editable
69
        configRegistry.registerConfigAttribute(
70
                EditConfigAttributes.CELL_EDITABLE_RULE,
71
                IEditableRule.ALWAYS_EDITABLE,
72
                DisplayMode.EDIT,
73
                MatrixUtility.getProperty(feature)
74
                );
75
        if(feature.isSupportsQuantitativeData()){
76
            //add display converter for string representation
77
            configRegistry.registerConfigAttribute(
78
                    CellConfigAttributes.DISPLAY_CONVERTER,
79
                    new QuantitativeDataDisplayConverter(),
80
                    DisplayMode.NORMAL,
81
                    MatrixUtility.getProperty(feature));
82
            //register quantitative editor
83
            configRegistry.registerConfigAttribute(
84
                    EditConfigAttributes.CELL_EDITOR,
85
                    new QuantitativeDataCellEditor(feature, matrix),
86
                    DisplayMode.EDIT,
87
                    MatrixUtility.getProperty(feature));
88
        }
89
        else if(feature.isSupportsCategoricalData()){
90
            //add display converter for string representation
91
            configRegistry.registerConfigAttribute(
92
                    CellConfigAttributes.DISPLAY_CONVERTER,
93
                    new CategoricalDataDisplayConverter(),
94
                    DisplayMode.NORMAL,
95
                    MatrixUtility.getProperty(feature));
96

    
97
            //add combo box cell editor
98
            //register editor
99
            configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR,
100
                    new CategoricalDataCellEditor(matrix.getSupportedStatesForCategoricalFeature(feature), matrix, feature),
101
                    DisplayMode.EDIT,
102
                    MatrixUtility.getProperty(feature));
103

    
104
        }
105

    
106
    }
107
}
(8-8/15)