Project

General

Profile

Download (2.44 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.ComboBoxCellEditor;
14
import org.eclipse.nebula.widgets.nattable.widget.NatCombo;
15
import org.eclipse.swt.events.SelectionEvent;
16
import org.eclipse.swt.events.SelectionListener;
17
import org.eclipse.swt.widgets.Composite;
18
import org.eclipse.swt.widgets.Control;
19

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

    
25
/**
26
 * @author pplitzner
27
 * @since Dec 7, 2017
28
 *
29
 */
30
public class CategoricalDataCellEditor extends ComboBoxCellEditor{
31

    
32
    private CharacterMatrix matrix;
33
    private Feature feature;
34

    
35
    public CategoricalDataCellEditor(List<State> list, CharacterMatrix matrix, Feature feature) {
36
        super(list, 10);
37
        this.matrix = matrix;
38
        this.feature = feature;
39
        setUseCheckbox(true);
40
        setMultiselect(true);
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
                ((RowWrapper) rowWrapper).addCategoricalData(feature);
49
            }
50
        }
51
        super.setCanonicalValue(canonicalValue);
52
    }
53

    
54
    /**
55
     * {@inheritDoc}
56
     */
57
    @Override
58
    protected Control activateCell(Composite parent, Object originalCanonicalValue) {
59
        if(matrix.getBodyDataProvider().getRowObject(this.getRowIndex()) instanceof RowWrapper){
60
            NatCombo natCombo = (NatCombo) super.activateCell(parent, originalCanonicalValue);
61
            natCombo.addSelectionListener(new SelectionListener() {
62
                @Override
63
                public void widgetSelected(SelectionEvent e) {
64
                    matrix.setDirty();
65
                }
66
                @Override
67
                public void widgetDefaultSelected(SelectionEvent e) {
68
                }
69
            });
70
            return natCombo;
71
        }
72
        return null;
73
    }
74

    
75
}
(1-1/2)