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.Set;
|
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.TaxonDistributionDTO;
|
21
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
22
|
import eu.etaxonomy.cdm.model.description.Distribution;
|
23
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
24
|
|
25
|
/**
|
26
|
* @author k.luther
|
27
|
* @since 05.12.2018
|
28
|
*
|
29
|
*/
|
30
|
public class StatusDataCellEditor extends ComboBoxCellEditor {
|
31
|
private DistributionEditor editor;
|
32
|
|
33
|
public StatusDataCellEditor(DistributionEditor editor, StatusComboBoxDataProvider statusComboBoxDataProvider) {
|
34
|
super(statusComboBoxDataProvider, statusComboBoxDataProvider.getMaxVisibleItems());
|
35
|
this.editor = editor;
|
36
|
setUseCheckbox(true);
|
37
|
setMultiselect(false);
|
38
|
}
|
39
|
|
40
|
@Override
|
41
|
public void setCanonicalValue(Object canonicalValue) {
|
42
|
if(canonicalValue instanceof Distribution){
|
43
|
Object rowWrapper = editor.getBodyDataProvider().getRowObject(this.getRowIndex());
|
44
|
if(rowWrapper instanceof TaxonDistributionDTO){
|
45
|
NamedArea area = editor.getAreaToColumnIndexMap().get(getColumnIndex());
|
46
|
Set<DescriptionElementBase> elements = ((TaxonDistributionDTO) rowWrapper).getDistributionMap().get(area);
|
47
|
if (elements == null){
|
48
|
|
49
|
}else if (elements.size() == 1){
|
50
|
DescriptionElementBase base = elements.iterator().next();
|
51
|
Distribution distr = (Distribution) base;
|
52
|
//TODO set value corresponding to preference
|
53
|
super.setCanonicalValue(distr.getStatus().getLabel());
|
54
|
}
|
55
|
}
|
56
|
}
|
57
|
super.setCanonicalValue(canonicalValue);
|
58
|
}
|
59
|
|
60
|
@Override
|
61
|
protected Control activateCell(Composite parent, Object originalCanonicalValue) {
|
62
|
if(editor.getBodyDataProvider().getRowObject(this.getRowIndex()) instanceof TaxonDistributionDTO){
|
63
|
NatCombo natCombo = (NatCombo) super.activateCell(parent, originalCanonicalValue);
|
64
|
natCombo.addSelectionListener(new SelectionListener() {
|
65
|
@Override
|
66
|
public void widgetSelected(SelectionEvent e) {
|
67
|
editor.setDirty();
|
68
|
}
|
69
|
@Override
|
70
|
public void widgetDefaultSelected(SelectionEvent e) {
|
71
|
}
|
72
|
});
|
73
|
return natCombo;
|
74
|
}
|
75
|
return null;
|
76
|
}
|
77
|
}
|