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
|
// FIXME avoid creating empty CategoricalData
|
52
|
((RowWrapperDTO) rowWrapper).addCategoricalData(feature);
|
53
|
}
|
54
|
}
|
55
|
if(canonicalValue instanceof CategoricalData){
|
56
|
List<State> statesOnly = ((CategoricalData) canonicalValue).getStatesOnly();
|
57
|
super.setCanonicalValue(statesOnly.stream().map(state->state.getTitleCache()).collect(Collectors.toList()));
|
58
|
return;
|
59
|
}
|
60
|
super.setCanonicalValue(canonicalValue);
|
61
|
}
|
62
|
|
63
|
@Override
|
64
|
protected Control activateCell(Composite parent, Object originalCanonicalValue) {
|
65
|
if(matrix.getBodyDataProvider().getRowObject(this.getRowIndex()) instanceof RowWrapperDTO){
|
66
|
NatCombo natCombo = (NatCombo) super.activateCell(parent, originalCanonicalValue);
|
67
|
natCombo.addSelectionListener(new SelectionListener() {
|
68
|
@Override
|
69
|
public void widgetSelected(SelectionEvent e) {
|
70
|
matrix.setDirty();
|
71
|
}
|
72
|
@Override
|
73
|
public void widgetDefaultSelected(SelectionEvent e) {
|
74
|
}
|
75
|
});
|
76
|
return natCombo;
|
77
|
}
|
78
|
return null;
|
79
|
}
|
80
|
|
81
|
}
|