1
|
/**
|
2
|
* Copyright (C) 2018 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.view.checklist.e4;
|
10
|
|
11
|
import java.util.HashMap;
|
12
|
import java.util.Map;
|
13
|
import java.util.Set;
|
14
|
|
15
|
import org.eclipse.nebula.widgets.nattable.edit.editor.ComboBoxCellEditor;
|
16
|
import org.eclipse.nebula.widgets.nattable.widget.NatCombo;
|
17
|
import org.eclipse.swt.events.SelectionEvent;
|
18
|
import org.eclipse.swt.events.SelectionListener;
|
19
|
import org.eclipse.swt.widgets.Composite;
|
20
|
import org.eclipse.swt.widgets.Control;
|
21
|
|
22
|
import eu.etaxonomy.cdm.api.service.dto.TaxonDistributionDTO;
|
23
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
24
|
import eu.etaxonomy.cdm.model.description.Distribution;
|
25
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
26
|
|
27
|
/**
|
28
|
* @author k.luther
|
29
|
* @since 05.12.2018
|
30
|
*
|
31
|
*/
|
32
|
public class StatusDataCellEditor extends ComboBoxCellEditor {
|
33
|
private DistributionEditor editor;
|
34
|
|
35
|
|
36
|
|
37
|
public StatusDataCellEditor(DistributionEditor editor, StatusComboBoxDataProvider statusComboBoxDataProvider) {
|
38
|
super(statusComboBoxDataProvider, statusComboBoxDataProvider.getMaxVisibleItems());
|
39
|
this.editor = editor;
|
40
|
setUseCheckbox(false);
|
41
|
setMultiselect(false);
|
42
|
maxVisibleItems = 10;
|
43
|
|
44
|
}
|
45
|
|
46
|
@Override
|
47
|
public void setCanonicalValue(Object canonicalValue) {
|
48
|
if(canonicalValue instanceof Distribution){
|
49
|
Object rowWrapper = editor.getBodyDataProvider().getRowObject(this.getRowIndex());
|
50
|
if(rowWrapper instanceof TaxonDistributionDTO){
|
51
|
NamedArea area = editor.getAreaToColumnIndexMap().get(getColumnIndex());
|
52
|
System.err.println("StatusDataCellEditor: " + ((TaxonDistributionDTO)rowWrapper).getNameCache());
|
53
|
Map<NamedArea, Set<DescriptionElementBase>> distributionMap = editor.taxonDistributionMap.get(((TaxonDistributionDTO) rowWrapper).getTaxonUuid());
|
54
|
if (distributionMap == null){
|
55
|
distributionMap = new HashMap();
|
56
|
editor.taxonDistributionMap.put(((TaxonDistributionDTO) rowWrapper).getTaxonUuid(),distributionMap);
|
57
|
}
|
58
|
Set<DescriptionElementBase> elements = distributionMap.get(area);
|
59
|
if (elements == null){
|
60
|
|
61
|
}else if (elements.size() == 1){
|
62
|
DescriptionElementBase base = elements.iterator().next();
|
63
|
Distribution distr = (Distribution) base;
|
64
|
//editor.descriptionsToSave.add( (TaxonDistributionDTO) rowWrapper);
|
65
|
//TODO set value corresponding to preference
|
66
|
if (distr.getStatus() != null){
|
67
|
if (distr.getStatus().getLabel() == ""){
|
68
|
distr.setStatus(null);
|
69
|
super.setCanonicalValue("");
|
70
|
|
71
|
}else{
|
72
|
super.setCanonicalValue(distr.getStatus().getLabel());
|
73
|
}
|
74
|
}
|
75
|
}
|
76
|
}
|
77
|
}else if (canonicalValue != null){
|
78
|
super.setCanonicalValue(canonicalValue);
|
79
|
}
|
80
|
}
|
81
|
|
82
|
@Override
|
83
|
protected Control activateCell(Composite parent, Object originalCanonicalValue) {
|
84
|
if (originalCanonicalValue instanceof Distribution || originalCanonicalValue == null){
|
85
|
NatCombo natCombo = (NatCombo) super.activateCell(parent, originalCanonicalValue);
|
86
|
natCombo.addSelectionListener(new SelectionListener() {
|
87
|
@Override
|
88
|
public void widgetSelected(SelectionEvent e) {
|
89
|
editor.setDirty();
|
90
|
}
|
91
|
@Override
|
92
|
public void widgetDefaultSelected(SelectionEvent e) {
|
93
|
}
|
94
|
});
|
95
|
return natCombo;
|
96
|
}else{
|
97
|
return null;
|
98
|
}
|
99
|
|
100
|
|
101
|
}
|
102
|
}
|