Project

General

Profile

Download (3.08 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
            Object rowWrapper = matrix.getBodyDataProvider().getRowObject(this.getRowIndex());
47
            if(rowWrapper instanceof RowWrapper){
48
                canonicalValue = ((RowWrapper) rowWrapper).addCategoricalData(feature);
49
            }
50
        }
51
        else 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
        if(matrix.getBodyDataProvider().getRowObject(this.getRowIndex()) instanceof RowWrapper){
69
            Control editorControl = super.activateCell(parent, originalCanonicalValue);
70
            ((NatCombo)editorControl).addSelectionListener(new SelectionListener() {
71
                @Override
72
                public void widgetSelected(SelectionEvent e) {
73
                    matrix.setDirty();
74
                }
75
                @Override
76
                public void widgetDefaultSelected(SelectionEvent e) {
77
                }
78
            });
79
            return editorControl;
80
        }
81
        return null;
82
    }
83

    
84
}
(1-1/2)