1
|
/**
|
2
|
* Copyright (C) 2018 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.taxeditor.bulkeditor.e4;
|
10
|
|
11
|
import java.util.Collection;
|
12
|
|
13
|
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
|
14
|
import org.eclipse.jface.viewers.StructuredSelection;
|
15
|
import org.eclipse.nebula.widgets.nattable.data.IRowDataProvider;
|
16
|
import org.eclipse.nebula.widgets.nattable.extension.e4.selection.E4SelectionListener;
|
17
|
import org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell;
|
18
|
import org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent;
|
19
|
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
|
20
|
import org.eclipse.nebula.widgets.nattable.selection.event.CellSelectionEvent;
|
21
|
import org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent;
|
22
|
|
23
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
24
|
|
25
|
/**
|
26
|
* @author pplitzner
|
27
|
* @date 09.07.2018
|
28
|
*/
|
29
|
final class CellSelectionListener extends E4SelectionListener<CdmBase> {
|
30
|
|
31
|
private BulkEditorE4Composite bulkEditor;
|
32
|
|
33
|
public CellSelectionListener(
|
34
|
ESelectionService service,
|
35
|
SelectionLayer selectionLayer,
|
36
|
IRowDataProvider<CdmBase> rowDataProvider,
|
37
|
BulkEditorE4Composite bulkEditor) {
|
38
|
super(service, selectionLayer, rowDataProvider);
|
39
|
this.bulkEditor = bulkEditor;
|
40
|
}
|
41
|
|
42
|
@Override
|
43
|
public void handleLayerEvent(ILayerEvent event) {
|
44
|
if(event instanceof CellSelectionEvent){
|
45
|
CellSelectionEvent cellSelectionEvent = (CellSelectionEvent)event;
|
46
|
Collection<ILayerCell> selectedCells = cellSelectionEvent.getSelectionLayer().getSelectedCells();
|
47
|
if(selectedCells.size()==1){
|
48
|
Object rowObject = bulkEditor.getBodyDataProvider().getRowObject(cellSelectionEvent.getRowPosition());
|
49
|
bulkEditor.getSelService().setSelection(new StructuredSelection(rowObject));
|
50
|
return;
|
51
|
}
|
52
|
}
|
53
|
else if(event instanceof RowSelectionEvent){
|
54
|
RowSelectionEvent rowSelectionEvent = (RowSelectionEvent) event;
|
55
|
int[] fullySelectedRowPositions = rowSelectionEvent.getSelectionLayer().getFullySelectedRowPositions();
|
56
|
if(fullySelectedRowPositions.length==1){
|
57
|
if (fullySelectedRowPositions[0]>=0){
|
58
|
Object rowObject = bulkEditor.getBodyDataProvider().getRowObject(fullySelectedRowPositions[0]);
|
59
|
bulkEditor.getSelService().setSelection(new StructuredSelection(rowObject));
|
60
|
}
|
61
|
return;
|
62
|
}
|
63
|
}
|
64
|
bulkEditor.getSelService().setSelection(new StructuredSelection());
|
65
|
}
|
66
|
}
|