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.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.api.service.dto.RowWrapperDTO;
|
25
|
|
26
|
/**
|
27
|
* @author pplitzner
|
28
|
* @date 09.07.2018
|
29
|
*
|
30
|
*/
|
31
|
final class CellSelectionListener extends E4SelectionListener<Object> {
|
32
|
|
33
|
private CharacterMatrixPart part;
|
34
|
|
35
|
public CellSelectionListener(
|
36
|
ESelectionService service,
|
37
|
SelectionLayer selectionLayer,
|
38
|
IRowDataProvider<Object> rowDataProvider,
|
39
|
CharacterMatrixPart part) {
|
40
|
super(service, selectionLayer, rowDataProvider);
|
41
|
this.part = part;
|
42
|
}
|
43
|
|
44
|
@Override
|
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();
|
54
|
if(dataValue!=null){
|
55
|
part.getSelectionService().setSelection(new StructuredSelection(dataValue));
|
56
|
return;
|
57
|
}
|
58
|
}
|
59
|
}
|
60
|
}
|
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()));
|
68
|
return;
|
69
|
}
|
70
|
}
|
71
|
}
|
72
|
part.getSelectionService().setSelection(new StructuredSelection());
|
73
|
}
|
74
|
}
|