Project

General

Profile

« Previous | Next » 

Revision bd0b8f0e

Added by Patrick Plitzner over 5 years ago

Refactor categorical combo box creation

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CellEditorDataConversionConfiguration.java
21 21
import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
22 22
import org.eclipse.swt.graphics.Point;
23 23

  
24
import eu.etaxonomy.cdm.model.description.Feature;
24
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.categorical.CategoricalComboBoxDataProvider;
25 25
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.categorical.CategoricalDataCellEditor;
26 26
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.categorical.CategoricalDataDisplayConverter;
27 27
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.quantitative.QuantitativeDataDialogEditor;
......
87 87
                DisplayMode.NORMAL,
88 88
                CharacterMatrixConfigLabelAccumulator.CATEGORICAL
89 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
                );
90 96

  
91 97

  
92 98
        /**
......
141 147
                editDialogSettings,
142 148
                DisplayMode.EDIT,
143 149
                CharacterMatrixConfigLabelAccumulator.QUANTITATIVE);
144

  
145

  
146
        //TODO: this for loop can maybe be avoided
147
        matrix.getFeatures().forEach(feature->registerColumnConfiguration(feature, configRegistry));
148 150
    }
149 151

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

  
159
        }
160
    }
161 152
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/categorical/CategoricalComboBoxDataProvider.java
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.categorical;
11

  
12
import java.util.List;
13

  
14
import org.eclipse.nebula.widgets.nattable.edit.editor.IComboBoxDataProvider;
15

  
16
import eu.etaxonomy.cdm.model.description.Feature;
17
import eu.etaxonomy.cdm.model.description.State;
18
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.CharacterMatrix;
19

  
20
/**
21
 * @author pplitzner
22
 * @date 24.07.2018
23
 *
24
 */
25
public class CategoricalComboBoxDataProvider implements IComboBoxDataProvider {
26

  
27
    private CharacterMatrix matrix;
28
    private int maxVisibleItems;
29

  
30
    public CategoricalComboBoxDataProvider(CharacterMatrix matrix) {
31
        super();
32
        this.matrix = matrix;
33
    }
34

  
35
    @Override
36
    public List<?> getValues(int columnIndex, int rowIndex) {
37
        Feature feature = matrix.getIndexToFeatureMap().get(columnIndex);
38
        List<State> supportedStatesForCategoricalFeature = matrix.getSupportedStatesForCategoricalFeature(feature);
39
        maxVisibleItems = Math.max(3, Math.min(supportedStatesForCategoricalFeature.size()-1, 10));
40
        return supportedStatesForCategoricalFeature;
41
    }
42

  
43
    int getMaxVisibleItems(){
44
        return maxVisibleItems;
45
    }
46
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/categorical/CategoricalDataCellEditor.java
8 8
*/
9 9
package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.categorical;
10 10

  
11
import java.util.List;
12

  
13 11
import org.eclipse.nebula.widgets.nattable.edit.editor.ComboBoxCellEditor;
14 12
import org.eclipse.nebula.widgets.nattable.widget.NatCombo;
15 13
import org.eclipse.swt.events.SelectionEvent;
......
19 17

  
20 18
import eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO;
21 19
import eu.etaxonomy.cdm.model.description.Feature;
22
import eu.etaxonomy.cdm.model.description.State;
23 20
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.CharacterMatrix;
24 21

  
25 22
/**
......
31 28
public class CategoricalDataCellEditor extends ComboBoxCellEditor{
32 29

  
33 30
    private CharacterMatrix matrix;
34
    private Feature feature;
35 31

  
36
    public CategoricalDataCellEditor(List<State> list, CharacterMatrix matrix, Feature feature) {
37
        super(list, Math.max(3, Math.min(list.size()-1, 10)));
32
    public CategoricalDataCellEditor(CharacterMatrix matrix, CategoricalComboBoxDataProvider categoricalComboBoxDataProvider) {
33
        super(categoricalComboBoxDataProvider, categoricalComboBoxDataProvider.getMaxVisibleItems());
38 34
        this.matrix = matrix;
39
        this.feature = feature;
40 35
        setUseCheckbox(true);
41 36
        setMultiselect(true);
42 37
    }
......
46 41
        if(canonicalValue==null){
47 42
            Object rowWrapper = matrix.getBodyDataProvider().getRowObject(this.getRowIndex());
48 43
            if(rowWrapper instanceof RowWrapperDTO){
44
                Feature feature = matrix.getIndexToFeatureMap().get(getColumnIndex());
49 45
                ((RowWrapperDTO) rowWrapper).addCategoricalData(feature);
50 46
            }
51 47
        }
52 48
        super.setCanonicalValue(canonicalValue);
53 49
    }
54 50

  
55
    /**
56
     * {@inheritDoc}
57
     */
58 51
    @Override
59 52
    protected Control activateCell(Composite parent, Object originalCanonicalValue) {
60 53
        if(matrix.getBodyDataProvider().getRowObject(this.getRowIndex()) instanceof RowWrapperDTO){

Also available in: Unified diff