2 * Copyright (C) 2018 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.bulkeditor
.e4
;
11 import java
.util
.Collection
;
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
;
23 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
29 final class CellSelectionListener
extends E4SelectionListener
<CdmBase
> {
31 private BulkEditorComposite bulkEditor
;
33 public CellSelectionListener(
34 ESelectionService service
,
35 SelectionLayer selectionLayer
,
36 IRowDataProvider
<CdmBase
> rowDataProvider
,
37 BulkEditorComposite bulkEditor
) {
38 super(service
, selectionLayer
, rowDataProvider
);
39 this.bulkEditor
= bulkEditor
;
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
));
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
));
64 bulkEditor
.getSelService().setSelection(new StructuredSelection());