1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2017 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
package eu.etaxonomy.taxeditor.editor.view.checklist.e4;
|
11
|
|
12
|
import java.util.Map;
|
13
|
import java.util.Set;
|
14
|
import java.util.UUID;
|
15
|
|
16
|
import org.eclipse.jface.viewers.SelectionChangedEvent;
|
17
|
import org.eclipse.jface.viewers.TableViewer;
|
18
|
import org.eclipse.jface.viewers.TableViewerEditor;
|
19
|
import org.eclipse.jface.viewers.ViewerCell;
|
20
|
|
21
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
22
|
import eu.etaxonomy.cdm.model.description.Distribution;
|
23
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
24
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
25
|
|
26
|
/**
|
27
|
* @author k.luther
|
28
|
* @date 28.09.2017
|
29
|
*
|
30
|
*/
|
31
|
public class DistributionEditorHelper {
|
32
|
|
33
|
public static Distribution getDistributionForColumn(SelectionChangedEvent event, Map<UUID, Integer> areaPosition) {
|
34
|
// List<TaxonDescription> listTaxonDescriptions = descriptionService.listTaxonDescriptions(taxon, null, null,
|
35
|
// null, null, null, DESC_INIT_STRATEGY);
|
36
|
TableViewer viewer = null;
|
37
|
TableViewerEditor editor = null;
|
38
|
Taxon taxon = null;
|
39
|
int columnIndex;
|
40
|
if (event.getSource() instanceof TableViewer){
|
41
|
viewer = (TableViewer)event.getSource();
|
42
|
} else {
|
43
|
return null;
|
44
|
}
|
45
|
if (viewer.getColumnViewerEditor() instanceof TableViewerEditor){
|
46
|
editor = (TableViewerEditor) viewer.getColumnViewerEditor();
|
47
|
} else {
|
48
|
return null;
|
49
|
}
|
50
|
ViewerCell cell = editor.getFocusCell();
|
51
|
if (cell == null){
|
52
|
return null;
|
53
|
}
|
54
|
if (cell.getElement() instanceof Taxon){
|
55
|
taxon =(Taxon)cell.getElement();
|
56
|
} else {
|
57
|
return null;
|
58
|
}
|
59
|
columnIndex = cell.getColumnIndex();
|
60
|
UUID areaUuid = null;
|
61
|
for (Map.Entry<UUID,Integer> entry: areaPosition.entrySet()){
|
62
|
if (entry.getValue().intValue()== columnIndex){
|
63
|
areaUuid = entry.getKey();
|
64
|
break;
|
65
|
}
|
66
|
}
|
67
|
if (areaUuid == null){
|
68
|
return null;
|
69
|
}
|
70
|
Set<TaxonDescription> listTaxonDescriptions = taxon.getDescriptions();
|
71
|
|
72
|
for (TaxonDescription td : listTaxonDescriptions) {
|
73
|
for (DescriptionElementBase deb : td.getElements()) {
|
74
|
if (deb instanceof Distribution) {
|
75
|
Distribution distribution = (Distribution) deb;
|
76
|
if (distribution != null && distribution.getArea() != null && distribution.getArea().getUuid().equals(areaUuid)){
|
77
|
return distribution;
|
78
|
}
|
79
|
}
|
80
|
}
|
81
|
}
|
82
|
return null;
|
83
|
}
|
84
|
|
85
|
}
|