Project

General

Profile

Download (2.52 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.descriptiveDataSet.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.api.service.dto.RowWrapperDTO;
21
import eu.etaxonomy.cdm.model.description.Feature;
22
import eu.etaxonomy.cdm.model.description.State;
23
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.CharacterMatrix;
24

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

    
33
    private CharacterMatrix matrix;
34
    private Feature feature;
35

    
36
    public CategoricalDataCellEditor(List<State> list, CharacterMatrix matrix, Feature feature) {
37
        super(list, Math.max(3, Math.min(list.size()-1, 10)));
38
        this.matrix = matrix;
39
        this.feature = feature;
40
        setUseCheckbox(true);
41
        setMultiselect(true);
42
    }
43

    
44
    @Override
45
    public void setCanonicalValue(Object canonicalValue) {
46
        if(canonicalValue==null){
47
            Object rowWrapper = matrix.getBodyDataProvider().getRowObject(this.getRowIndex());
48
            if(rowWrapper instanceof RowWrapperDTO){
49
                ((RowWrapperDTO) rowWrapper).addCategoricalData(feature);
50
            }
51
        }
52
        super.setCanonicalValue(canonicalValue);
53
    }
54

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

    
76
}
(1-1/2)