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.ArrayList;
|
12
|
import java.util.HashMap;
|
13
|
import java.util.HashSet;
|
14
|
import java.util.List;
|
15
|
import java.util.Set;
|
16
|
|
17
|
import org.eclipse.nebula.widgets.nattable.edit.editor.ComboBoxCellEditor;
|
18
|
import org.eclipse.nebula.widgets.nattable.widget.NatCombo;
|
19
|
import org.eclipse.swt.events.SelectionEvent;
|
20
|
import org.eclipse.swt.events.SelectionListener;
|
21
|
import org.eclipse.swt.widgets.Composite;
|
22
|
import org.eclipse.swt.widgets.Control;
|
23
|
|
24
|
import eu.etaxonomy.cdm.api.service.dto.DescriptionElementDto;
|
25
|
import eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO;
|
26
|
import eu.etaxonomy.cdm.persistence.dto.FeatureDto;
|
27
|
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.CharacterMatrix;
|
28
|
import eu.etaxonomy.taxeditor.event.EventUtility;
|
29
|
import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
|
30
|
|
31
|
/**
|
32
|
* Cell editor for CategoricalData
|
33
|
* @author pplitzner
|
34
|
* @since Dec 7, 2017
|
35
|
*
|
36
|
*/
|
37
|
public class CategoricalDataCellEditor extends ComboBoxCellEditor{
|
38
|
|
39
|
private CharacterMatrix matrix;
|
40
|
|
41
|
public CategoricalDataCellEditor(CharacterMatrix matrix, CategoricalComboBoxDataProvider categoricalComboBoxDataProvider) {
|
42
|
super(categoricalComboBoxDataProvider, 10);
|
43
|
this.matrix = matrix;
|
44
|
setUseCheckbox(true);
|
45
|
setMultiselect(true);
|
46
|
setShowDropdownFilter(true);
|
47
|
}
|
48
|
|
49
|
@Override
|
50
|
public void setCanonicalValue(Object canonicalValue) {
|
51
|
if(canonicalValue==null){
|
52
|
Object rowWrapper = matrix.getBodyDataProvider().getRowObject(this.getRowIndex());
|
53
|
if(rowWrapper instanceof RowWrapperDTO){
|
54
|
FeatureDto feature = matrix.getIndexToFeatureMap().get(getColumnIndex());
|
55
|
// FIXME avoid creating empty CategoricalData
|
56
|
// ((RowWrapperDTO) rowWrapper).addCategoricalData(feature);
|
57
|
}
|
58
|
|
59
|
}
|
60
|
List canonicalValueList = new ArrayList<>();
|
61
|
|
62
|
if (canonicalValue instanceof String[]){
|
63
|
String[] stringArray = (String[])canonicalValue;
|
64
|
for (int i = 0; i<stringArray.length; i++){
|
65
|
canonicalValueList.add(stringArray[i]);
|
66
|
}
|
67
|
}else if (canonicalValue instanceof List){
|
68
|
canonicalValueList = (List<String>)canonicalValue;
|
69
|
}else if (canonicalValue instanceof String){
|
70
|
canonicalValueList.add((String)canonicalValue);
|
71
|
}else if (canonicalValue instanceof HashSet){
|
72
|
canonicalValueList = new ArrayList(((HashSet)canonicalValue));
|
73
|
}
|
74
|
super.setCanonicalValue(canonicalValueList);
|
75
|
}
|
76
|
|
77
|
@Override
|
78
|
protected Control activateCell(Composite parent, Object originalCanonicalValue) {
|
79
|
|
80
|
if(matrix.getBodyDataProvider().getRowObject(this.getRowIndex()) instanceof RowWrapperDTO){
|
81
|
NatCombo natCombo = (NatCombo) super.activateCell(parent, originalCanonicalValue);
|
82
|
natCombo.addSelectionListener(new SelectionListener() {
|
83
|
@Override
|
84
|
public void widgetSelected(SelectionEvent e) {
|
85
|
matrix.setDirty();
|
86
|
EventUtility.postEvent(WorkbenchEventConstants.REFRESH_MATRIX, originalCanonicalValue);
|
87
|
}
|
88
|
@Override
|
89
|
public void widgetDefaultSelected(SelectionEvent e) {
|
90
|
}
|
91
|
});
|
92
|
return natCombo;
|
93
|
}
|
94
|
return null;
|
95
|
}
|
96
|
|
97
|
}
|