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.Set;
|
13
|
|
14
|
import org.eclipse.jface.viewers.SelectionChangedEvent;
|
15
|
import org.eclipse.jface.viewers.StructuredSelection;
|
16
|
import org.eclipse.jface.viewers.TableViewer;
|
17
|
import org.eclipse.jface.viewers.TableViewerEditor;
|
18
|
import org.eclipse.jface.viewers.ViewerCell;
|
19
|
import org.eclipse.swt.widgets.TableColumn;
|
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
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
26
|
|
27
|
/**
|
28
|
* @author k.luther
|
29
|
* @date 28.09.2017
|
30
|
*
|
31
|
*/
|
32
|
public class DistributionEditorHelper {
|
33
|
|
34
|
public static Distribution getDistributionForColumn(SelectionChangedEvent event) {
|
35
|
// List<TaxonDescription> listTaxonDescriptions = descriptionService.listTaxonDescriptions(taxon, null, null,
|
36
|
// null, null, null, DESC_INIT_STRATEGY);
|
37
|
TableViewer viewer = null;
|
38
|
TableViewerEditor editor = null;
|
39
|
Taxon taxon = null;
|
40
|
int columnIndex;
|
41
|
if (event.getSource() instanceof TableViewer){
|
42
|
viewer = (TableViewer)event.getSource();
|
43
|
} else {
|
44
|
return null;
|
45
|
}
|
46
|
if (viewer.getColumnViewerEditor() instanceof TableViewerEditor){
|
47
|
editor = (TableViewerEditor) viewer.getColumnViewerEditor();
|
48
|
} else {
|
49
|
return null;
|
50
|
}
|
51
|
ViewerCell cell = editor.getFocusCell();
|
52
|
if (cell.getElement() instanceof Taxon){
|
53
|
taxon =(Taxon)cell.getElement();
|
54
|
} else {
|
55
|
return null;
|
56
|
}
|
57
|
columnIndex = cell.getColumnIndex();
|
58
|
Set<TaxonDescription> listTaxonDescriptions = taxon.getDescriptions();
|
59
|
TableColumn column = viewer.getTable().getColumn(columnIndex);
|
60
|
for (TaxonDescription td : listTaxonDescriptions) {
|
61
|
for (DescriptionElementBase deb : td.getElements()) {
|
62
|
if (deb instanceof Distribution) {
|
63
|
Distribution distribution = (Distribution) deb;
|
64
|
if (distribution.getArea() != null){
|
65
|
if (PreferencesUtil.isShowIdInVocabularyInChecklistEditor()){
|
66
|
if (column.getText().equalsIgnoreCase(distribution.getArea().getIdInVocabulary())) {
|
67
|
StructuredSelection selection = new StructuredSelection(distribution);
|
68
|
// SelectionChangedEvent newEvent = new SelectionChangedEvent(event.getSelectionProvider(), selection);
|
69
|
return distribution;
|
70
|
}
|
71
|
}else{
|
72
|
if (column.getText().equalsIgnoreCase(distribution.getArea().getTitleCache())) {
|
73
|
StructuredSelection selection = new StructuredSelection(distribution);
|
74
|
// SelectionChangedEvent newEvent = new SelectionChangedEvent(event.getSelectionProvider(), selection);
|
75
|
return distribution;
|
76
|
}
|
77
|
}
|
78
|
}
|
79
|
}
|
80
|
}
|
81
|
}
|
82
|
return null;
|
83
|
}
|
84
|
|
85
|
}
|