Project

General

Profile

Download (3.06 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.bulkeditor.e4;
10

    
11
import org.eclipse.jface.window.DefaultToolTip;
12
import org.eclipse.jface.window.ToolTip;
13
import org.eclipse.nebula.widgets.nattable.NatTable;
14
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider;
15
import org.eclipse.nebula.widgets.nattable.layer.LabelStack;
16
import org.eclipse.swt.graphics.Point;
17
import org.eclipse.swt.widgets.Composite;
18
import org.eclipse.swt.widgets.Event;
19

    
20
import eu.etaxonomy.taxeditor.l10n.Messages;
21

    
22
/**
23
 * @author pplitzner
24
 * @since Jul 6, 2018
25
 *
26
 */
27
public class BulkEditorTooltip extends DefaultToolTip {
28

    
29
    private NatTable natTable;
30
    private DefaultColumnHeaderDataProvider colHeaderDataProvider;
31

    
32
    public BulkEditorTooltip(NatTable natTable, DefaultColumnHeaderDataProvider colHeaderDataProvider) {
33
        super(natTable, ToolTip.NO_RECREATE, false);
34
        this.natTable = natTable;
35
        this.colHeaderDataProvider = colHeaderDataProvider;
36
}
37

    
38
    @Override
39
    protected Object getToolTipArea(Event event) {
40
        int col = this.natTable.getColumnPositionByX(event.x);
41
        int row = this.natTable.getRowPositionByY(event.y);
42

    
43
        return new Point(col, row);
44
    }
45

    
46
    @Override
47
    protected String getText(Event event) {
48
        int col = this.natTable.getColumnPositionByX(event.x);
49
        int row = this.natTable.getRowPositionByY(event.y);
50

    
51
        LabelStack configLabels = natTable.getConfigLabelsByPosition(col, row);
52
        if(configLabels.hasLabel(BulkEditorComposite.LABEL_TARGET)){
53
            return Messages.BulkEditorTooltip_TARGET;
54
        }
55
        else if(configLabels.hasLabel(BulkEditorComposite.LABEL_CANDIDATE)){
56
            return Messages.BulkEditorTooltip_CANDIDATE;
57
        }
58
        int colIndex = this.natTable.getColumnIndexByPosition(col);
59
        int rowIndex = this.natTable.getRowIndexByPosition(row);
60
        if(row==0){
61
            return colHeaderDataProvider.getDataValue(colIndex, rowIndex).toString();
62
        }
63
        return natTable.getCellByPosition(col, row).getDataValue().toString();
64

    
65
    }
66

    
67
    @Override
68
    protected Composite createToolTipContentArea(Event event,
69
            Composite parent) {
70
        return super.createToolTipContentArea(event, parent);
71
    }
72

    
73
    @Override
74
    protected boolean shouldCreateToolTip(Event event) {
75
        int col = this.natTable.getColumnPositionByX(event.x);
76
        int row = this.natTable.getRowPositionByY(event.y);
77

    
78
        LabelStack configLabels = natTable.getConfigLabelsByPosition(col, row);
79
        if(configLabels.hasLabel(BulkEditorComposite.LABEL_CANDIDATE)
80
                || configLabels.hasLabel(BulkEditorComposite.LABEL_TARGET)){
81
            return true;
82
        }
83

    
84
        int rowIndex = this.natTable.getRowIndexByPosition(row);
85
        if(row ==0 || col == 0){
86
            return false;
87
        }
88
        return true;
89
    }
90

    
91
}
(8-8/9)