Project

General

Profile

Download (1.88 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2018 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.descriptiveDataSet.matrix;
11

    
12
import java.util.Collection;
13

    
14
import org.eclipse.jface.viewers.StructuredSelection;
15
import org.eclipse.nebula.widgets.nattable.layer.ILayerListener;
16
import org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell;
17
import org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent;
18
import org.eclipse.nebula.widgets.nattable.selection.event.CellSelectionEvent;
19

    
20
/**
21
 * @author pplitzner
22
 * @date 09.07.2018
23
 *
24
 */
25
final class CellSelectionListener implements ILayerListener {
26

    
27
    private CharacterMatrixPart part;
28

    
29
    public CellSelectionListener(CharacterMatrixPart part) {
30
        super();
31
        this.part = part;
32
    }
33

    
34
    @Override
35
    public void handleLayerEvent(ILayerEvent event) {
36
        if(event instanceof CellSelectionEvent){
37
            CellSelectionEvent cellSelectionEvent = (CellSelectionEvent)event;
38
            int columnPosition = cellSelectionEvent.getColumnPosition();
39
            if(columnPosition>CharacterMatrix.LEADING_COLUMN_COUNT){
40
                Collection<ILayerCell> selectedCells = cellSelectionEvent.getSelectionLayer().getSelectedCells();
41
                StructuredSelection selection = new StructuredSelection();
42
                if(selectedCells.size()==1){
43
                    ILayerCell cell = selectedCells.iterator().next();
44
                    Object dataValue = cell.getDataValue();
45
                    if(dataValue!=null){
46
                        selection = new StructuredSelection(dataValue);
47
                    }
48
                }
49
                part.getSelectionService().setSelection(selection);
50
            }
51
        }
52
    }
53
}
(5-5/20)