Project

General

Profile

Download (2.7 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.bulkeditor.e4;
11

    
12
import java.util.Collection;
13

    
14
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
15
import org.eclipse.jface.viewers.StructuredSelection;
16
import org.eclipse.nebula.widgets.nattable.data.IRowDataProvider;
17
import org.eclipse.nebula.widgets.nattable.extension.e4.selection.E4SelectionListener;
18
import org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell;
19
import org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent;
20
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
21
import org.eclipse.nebula.widgets.nattable.selection.event.CellSelectionEvent;
22
import org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent;
23

    
24
import eu.etaxonomy.cdm.model.common.CdmBase;
25

    
26
/**
27
 * @author pplitzner
28
 * @date 09.07.2018
29
 *
30
 */
31
final class CellSelectionListener extends E4SelectionListener<CdmBase> {
32

    
33
    private BulkEditorE4Composite bulkEditor;
34

    
35
    public CellSelectionListener(
36
            ESelectionService service,
37
            SelectionLayer selectionLayer,
38
            IRowDataProvider<CdmBase> rowDataProvider,
39
            BulkEditorE4Composite bulkEditor) {
40
        super(service, selectionLayer, rowDataProvider);
41
        this.bulkEditor = bulkEditor;
42
    }
43

    
44
    @Override
45
    public void handleLayerEvent(ILayerEvent event) {
46
        if(event instanceof CellSelectionEvent){
47
            CellSelectionEvent cellSelectionEvent = (CellSelectionEvent)event;
48
            Collection<ILayerCell> selectedCells = cellSelectionEvent.getSelectionLayer().getSelectedCells();
49
            if(selectedCells.size()==1){
50
                Object rowObject = bulkEditor.getBodyDataProvider().getRowObject(cellSelectionEvent.getRowPosition());
51
                bulkEditor.getSelService().setSelection(new StructuredSelection(rowObject));
52
                return;
53
            }
54
        }
55
        else if(event instanceof RowSelectionEvent){
56
            RowSelectionEvent rowSelectionEvent = (RowSelectionEvent) event;
57
            int[] fullySelectedRowPositions = rowSelectionEvent.getSelectionLayer().getFullySelectedRowPositions();
58
            if(fullySelectedRowPositions.length==1){
59
                Object rowObject = bulkEditor.getBodyDataProvider().getRowObject(fullySelectedRowPositions[0]);
60
                bulkEditor.getSelService().setSelection(new StructuredSelection(rowObject));
61
                return;
62
            }
63
        }
64
        bulkEditor.getSelService().setSelection(new StructuredSelection());
65
    }
66
}
(9-9/9)