Project

General

Profile

Download (3 KB) Statistics
| Branch: | Tag: | Revision:
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.TableViewer;
16
import org.eclipse.jface.viewers.TableViewerEditor;
17
import org.eclipse.jface.viewers.ViewerCell;
18
import org.eclipse.swt.widgets.TableColumn;
19

    
20
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
21
import eu.etaxonomy.cdm.model.description.Distribution;
22
import eu.etaxonomy.cdm.model.description.TaxonDescription;
23
import eu.etaxonomy.cdm.model.taxon.Taxon;
24
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
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) {
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
        Set<TaxonDescription> listTaxonDescriptions = taxon.getDescriptions();
61
        TableColumn column = viewer.getTable().getColumn(columnIndex);
62
        for (TaxonDescription td : listTaxonDescriptions) {
63
          for (DescriptionElementBase deb : td.getElements()) {
64
              if (deb instanceof Distribution) {
65
                  Distribution distribution = (Distribution) deb;
66
                  if (distribution.getArea() != null){
67
                      if (PreferencesUtil.isShowIdInVocabularyInChecklistEditor()){
68
                          if (column.getText().equalsIgnoreCase(distribution.getArea().getIdInVocabulary())) {
69
                              return distribution;
70
                          }
71
                      }else{
72
                          if (column.getText().equalsIgnoreCase(distribution.getArea().getTitleCache())) {
73
                              return distribution;
74
                          }
75
                      }
76
                  }
77
              }
78
          }
79
        }
80
        return null;
81
    }
82

    
83
}
(4-4/4)