Project

General

Profile

Download (3.18 KB) Statistics
| Branch: | Tag: | Revision:
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.editor.view.checklist.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.api.service.dto.RowWrapperDTO;
24
import eu.etaxonomy.cdm.api.service.dto.TaxonDistributionDTO;
25

    
26
/**
27
 * @author k.luther
28
 * @since 28.11.2018
29
 *
30
 */
31
public class DistributionCellSelectionListener extends E4SelectionListener<TaxonDistributionDTO>{
32
    private DistributionEditorPart part;
33

    
34
    public DistributionCellSelectionListener(
35
            ESelectionService service,
36
            SelectionLayer selectionLayer,
37
            IRowDataProvider<TaxonDistributionDTO> rowDataProvider,
38
            DistributionEditorPart part) {
39
        super(service, selectionLayer, rowDataProvider);
40
        this.part = part;
41
    }
42

    
43
    @Override
44
    public void handleLayerEvent(ILayerEvent event) {
45
        if(event instanceof CellSelectionEvent){
46
            CellSelectionEvent cellSelectionEvent = (CellSelectionEvent)event;
47
            int columnPosition = cellSelectionEvent.getColumnPosition();
48
            if(columnPosition>=part.getEditor().getFirstDataColumnIndex()){
49
                Collection<ILayerCell> selectedCells = cellSelectionEvent.getSelectionLayer().getSelectedCells();
50
                if(selectedCells.size()==1){
51
                    ILayerCell cell = selectedCells.iterator().next();
52
                    Object dataValue = cell.getDataValue();
53
                    if(dataValue!=null){
54
                        part.getSelectionService().setSelection(new StructuredSelection(dataValue));
55
                        return;
56
                    }
57
                }
58
            }
59
        }
60
        else if(event instanceof RowSelectionEvent){
61
            RowSelectionEvent rowSelectionEvent = (RowSelectionEvent) event;
62
            int[] fullySelectedRowPositions = rowSelectionEvent.getSelectionLayer().getFullySelectedRowPositions();
63
            if(fullySelectedRowPositions.length==1){
64
                Object rowObject = part.getEditor().getBodyDataProvider().getRowObject(fullySelectedRowPositions[0]);
65
                if(rowObject instanceof RowWrapperDTO){
66
                    part.getSelectionService().setSelection(new StructuredSelection(((RowWrapperDTO) rowObject).getDescription()));
67
                    return;
68
                }
69
            }
70
        }
71
        part.getSelectionService().setSelection(new StructuredSelection());
72
    }
73
}
(5-5/19)