Project

General

Profile

Download (2.93 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2017 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.editor.workingSet.matrix.categorical;
10

    
11
import java.util.List;
12

    
13
import org.eclipse.nebula.widgets.nattable.edit.editor.IComboBoxDataProvider;
14
import org.eclipse.nebula.widgets.nattable.filterrow.combobox.FilterRowComboBoxCellEditor;
15
import org.eclipse.nebula.widgets.nattable.widget.NatCombo;
16
import org.eclipse.swt.events.SelectionEvent;
17
import org.eclipse.swt.events.SelectionListener;
18
import org.eclipse.swt.widgets.Composite;
19
import org.eclipse.swt.widgets.Control;
20

    
21
import eu.etaxonomy.cdm.model.description.CategoricalData;
22
import eu.etaxonomy.cdm.model.description.Feature;
23
import eu.etaxonomy.cdm.model.description.State;
24
import eu.etaxonomy.taxeditor.editor.workingSet.matrix.CharacterMatrix;
25
import eu.etaxonomy.taxeditor.editor.workingSet.matrix.RowWrapper;
26

    
27
/**
28
 * @author pplitzner
29
 * @since Dec 7, 2017
30
 *
31
 */
32
public class CategoricalDataCellEditor extends FilterRowComboBoxCellEditor{
33

    
34
    private CharacterMatrix matrix;
35
    private Feature feature;
36

    
37
    public CategoricalDataCellEditor(IComboBoxDataProvider dataProvider, int maxVisibleItems, CharacterMatrix matrix, Feature feature) {
38
        super(dataProvider, maxVisibleItems);
39
        this.matrix = matrix;
40
        this.feature = feature;
41
    }
42

    
43
    @Override
44
    public void setCanonicalValue(Object canonicalValue) {
45
        if(canonicalValue==null){
46
            CategoricalData data = CategoricalData.NewInstance(feature);
47
            RowWrapper rowWrapper = matrix.getBodyDataProvider().getRowObject(this.getRowIndex());
48
            rowWrapper.getSpecimenDescription().addElement(data);
49
            canonicalValue = data;
50
        }
51
        if (canonicalValue instanceof CategoricalData) {
52
            CategoricalData data = (CategoricalData)canonicalValue;
53
            List<State> states = data.getStatesOnly();
54
            String[] result = new String[states.size()];
55
            for (int i = 0; i < states.size(); i++) {
56
                result[i] = (String) this.displayConverter.canonicalToDisplayValue(
57
                        this.layerCell, this.configRegistry, states.get(i));
58
            }
59
            setEditorValue(result);
60
        }
61
    }
62

    
63
    /**
64
     * {@inheritDoc}
65
     */
66
    @Override
67
    protected Control activateCell(Composite parent, Object originalCanonicalValue) {
68
        Control editorControl = super.activateCell(parent, originalCanonicalValue);
69
        ((NatCombo)editorControl).addSelectionListener(new SelectionListener() {
70
            @Override
71
            public void widgetSelected(SelectionEvent e) {
72
                matrix.setDirty();
73
            }
74
            @Override
75
            public void widgetDefaultSelected(SelectionEvent e) {
76
            }
77
        });
78
        return editorControl;
79
    }
80

    
81
}
(1-1/2)