Project

General

Profile

Download (4.2 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.CellVisualChangeEvent;
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
import eu.etaxonomy.cdm.api.service.dto.TaxonDistributionDTO;
26

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

    
35
    public DistributionCellSelectionListener(
36
            ESelectionService service,
37
            SelectionLayer selectionLayer,
38
            IRowDataProvider<TaxonDistributionDTO> rowDataProvider,
39
            DistributionEditorPart 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>=part.getEditor().getFirstDataColumnIndex()){
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
                    }else{
58
                        part.getSelectionService().setSelection(new StructuredSelection());
59
                        return;
60
                    }
61
                }
62
            }
63
        }
64
        else if(event instanceof RowSelectionEvent){
65
            RowSelectionEvent rowSelectionEvent = (RowSelectionEvent) event;
66
            int[] fullySelectedRowPositions = rowSelectionEvent.getSelectionLayer().getFullySelectedRowPositions();
67
            if(fullySelectedRowPositions.length==1){
68
                Object rowObject = part.getEditor().getBodyDataProvider().getRowObject(fullySelectedRowPositions[0]);
69
                if(rowObject instanceof RowWrapperDTO){
70
                    part.getSelectionService().setSelection(new StructuredSelection(((RowWrapperDTO) rowObject).getDescription()));
71
                    return;
72
                }
73
            }
74
        }
75
        else if (event instanceof CellVisualChangeEvent){
76
            CellVisualChangeEvent cellSelectionEvent = (CellVisualChangeEvent)event;
77
            int columnPosition = cellSelectionEvent.getColumnPosition();
78
            int rowPosition = cellSelectionEvent.getRowPosition();
79
            if(columnPosition>=part.getEditor().getFirstDataColumnIndex()){
80
                Object dataValue = cellSelectionEvent.getLayer().getDataValueByPosition(columnPosition, rowPosition);
81
                if(dataValue!=null){
82
                    part.getSelectionService().setSelection(new StructuredSelection(dataValue));
83
                    return;
84
                }else{
85
                    part.getSelectionService().setSelection(new StructuredSelection());
86
                    return;
87
                }
88

    
89
            }
90
        }
91
      //  part.getSelectionService().setSelection(new StructuredSelection());
92
    }
93
}
(5-5/20)