3 * Copyright (C) 2018 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.editor
.descriptiveDataSet
.matrix
;
12 import java
.util
.Collection
;
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
;
24 import eu
.etaxonomy
.cdm
.api
.service
.dto
.RowWrapperDTO
;
31 final class CellSelectionListener
extends E4SelectionListener
<Object
> {
33 private CharacterMatrixPart part
;
35 public CellSelectionListener(
36 ESelectionService service
,
37 SelectionLayer selectionLayer
,
38 IRowDataProvider
<Object
> rowDataProvider
,
39 CharacterMatrixPart part
) {
40 super(service
, selectionLayer
, rowDataProvider
);
45 public void handleLayerEvent(ILayerEvent event
) {
46 if(event
instanceof CellSelectionEvent
){
47 CellSelectionEvent cellSelectionEvent
= (CellSelectionEvent
)event
;
48 int columnPosition
= cellSelectionEvent
.getColumnPosition();
49 if(columnPosition
>=CharacterMatrix
.LEADING_COLUMN_COUNT
){
50 Collection
<ILayerCell
> selectedCells
= cellSelectionEvent
.getSelectionLayer().getSelectedCells();
51 if(selectedCells
.size()==1){
52 ILayerCell cell
= selectedCells
.iterator().next();
53 Object dataValue
= cell
.getDataValue();
55 part
.getSelectionService().setSelection(new StructuredSelection(dataValue
));
61 else if(event
instanceof RowSelectionEvent
){
62 RowSelectionEvent rowSelectionEvent
= (RowSelectionEvent
) event
;
63 int[] fullySelectedRowPositions
= rowSelectionEvent
.getSelectionLayer().getFullySelectedRowPositions();
64 if(fullySelectedRowPositions
.length
==1){
65 Object rowObject
= part
.getMatrix().getBodyDataProvider().getRowObject(fullySelectedRowPositions
[0]);
66 if(rowObject
instanceof RowWrapperDTO
){
67 part
.getSelectionService().setSelection(new StructuredSelection(((RowWrapperDTO
) rowObject
).getDescription()));
72 part
.getSelectionService().setSelection(new StructuredSelection());