Project

General

Profile

Download (2.94 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
import java.util.stream.Collectors;
13

    
14
import org.eclipse.nebula.widgets.nattable.edit.editor.ComboBoxCellEditor;
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.api.service.dto.RowWrapperDTO;
22
import eu.etaxonomy.cdm.model.description.CategoricalData;
23
import eu.etaxonomy.cdm.model.description.Feature;
24
import eu.etaxonomy.cdm.model.description.State;
25
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.CharacterMatrix;
26

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

    
35
    private CharacterMatrix matrix;
36

    
37
    public CategoricalDataCellEditor(CharacterMatrix matrix, CategoricalComboBoxDataProvider categoricalComboBoxDataProvider) {
38
        super(categoricalComboBoxDataProvider, 10);
39
        this.matrix = matrix;
40
        setUseCheckbox(true);
41
        setMultiselect(true);
42
        setShowDropdownFilter(true);
43
    }
44

    
45
    @Override
46
    public void setCanonicalValue(Object canonicalValue) {
47
        if(canonicalValue==null){
48
            Object rowWrapper = matrix.getBodyDataProvider().getRowObject(this.getRowIndex());
49
            if(rowWrapper instanceof RowWrapperDTO){
50
                Feature feature = matrix.getIndexToFeatureMap().get(getColumnIndex());
51
                ((RowWrapperDTO) rowWrapper).addCategoricalData(feature);
52
            }
53
        }
54
        if(canonicalValue instanceof CategoricalData){
55
            List<State> statesOnly = ((CategoricalData) canonicalValue).getStatesOnly();
56
            super.setCanonicalValue(statesOnly.stream().map(state->state.getTitleCache()).collect(Collectors.toList()));
57
            return;
58
        }
59
        super.setCanonicalValue(canonicalValue);
60
    }
61

    
62
    @Override
63
    protected Control activateCell(Composite parent, Object originalCanonicalValue) {
64
        if(matrix.getBodyDataProvider().getRowObject(this.getRowIndex()) instanceof RowWrapperDTO){
65
            NatCombo natCombo = (NatCombo) super.activateCell(parent, originalCanonicalValue);
66
            natCombo.addSelectionListener(new SelectionListener() {
67
                @Override
68
                public void widgetSelected(SelectionEvent e) {
69
                    matrix.setDirty();
70
                }
71
                @Override
72
                public void widgetDefaultSelected(SelectionEvent e) {
73
                }
74
            });
75
            return natCombo;
76
        }
77
        return null;
78
    }
79

    
80
}
(2-2/3)