Project

General

Profile

Revision 0c625cd1

ID0c625cd1b623b80519245a701dae5b74bdb0975a
Parent e3e487e3
Child e12ddaf5

Added by Patrick Plitzner 4 months ago

ref #7923 Show character combination during drag&drop

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/character/CharacterDragListener.java
9 9
package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.character;
10 10

  
11 11
import java.util.Collection;
12
import java.util.stream.Collectors;
12 13

  
13 14
import org.eclipse.jface.viewers.IStructuredSelection;
14 15
import org.eclipse.jface.viewers.TreeSelection;
15 16
import org.eclipse.jface.viewers.TreeViewer;
17
import org.eclipse.nebula.widgets.nattable.util.GUIHelper;
16 18
import org.eclipse.swt.dnd.DragSourceEvent;
19
import org.eclipse.swt.graphics.GC;
20
import org.eclipse.swt.graphics.Image;
21
import org.eclipse.swt.graphics.Point;
22
import org.eclipse.swt.widgets.Display;
17 23

  
18 24
import eu.etaxonomy.cdm.model.description.Character;
19 25
import eu.etaxonomy.cdm.model.description.FeatureNode;
......
29 35

  
30 36
    private TreeViewer structureViewer;
31 37
    private TreeViewer propertyViewer;
38
    Collection<Character> characters;
39
    private Image image;
40
    private GC gc;
32 41

  
33 42
    public CharacterDragListener(TreeViewer structureViewer, TreeViewer propertyViewer) {
34 43
        super(propertyViewer);
......
37 46
    }
38 47

  
39 48
    @Override
40
    public void dragSetData(DragSourceEvent event) {
41
        TreeSelection structureSelection = (TreeSelection) structureViewer.getSelection();
42
        TreeSelection propertySelection = (TreeSelection) propertyViewer.getSelection();
43
        if(structureSelection!=null && propertySelection!=null
44
                && !structureSelection.isEmpty() && !propertySelection.isEmpty()){
45
            //create all possible characters
46
            Collection<Character> characters = CharacterEditor.createCharacters(structureSelection, propertySelection);
49
    public void dragFinished(DragSourceEvent event) {
50
        characters = null;
51
        if(image!=null){
52
            image.dispose();
53
            image = null;
54
        }
55
        if(gc!=null){
56
            gc.dispose();
57
            gc = null;
58
        }
59
        super.dragFinished(event);
60
    }
47 61

  
48
            if (CharacterTransfer.getInstance().isSupportedType(event.dataType)) {
49
                event.data = characters;
50
            }
62
    @Override
63
    public void dragSetData(DragSourceEvent event) {
64
        if (CharacterTransfer.getInstance().isSupportedType(event.dataType)) {
65
            event.data = characters;
51 66
        }
52 67
    }
53 68

  
54
    /**
55
     * Method declared on DragSourceListener
56
     */
57 69
    @Override
58 70
    public void dragStart(DragSourceEvent event) {
59 71
        event.doit =
......
63 75
                .stream().allMatch(element -> element instanceof FeatureNode)
64 76
                && ((IStructuredSelection) propertyViewer.getSelection()).toList()
65 77
                .stream().allMatch(element -> element instanceof FeatureNode);
78
        if(!event.doit){
79
            return;
80
        }
81
        TreeSelection structureSelection = (TreeSelection) structureViewer.getSelection();
82
        TreeSelection propertySelection = (TreeSelection) propertyViewer.getSelection();
83
        if(structureSelection!=null && propertySelection!=null
84
                && !structureSelection.isEmpty() && !propertySelection.isEmpty()){
85
            //create all possible characters
86
            characters = CharacterEditor.createCharacters(structureSelection, propertySelection);
87

  
88
        }
89
        String text = characters.stream().map(character->character.generateTitle()).collect(Collectors.joining("\n"));
90

  
91
        // creating temporary GC for size calculation
92
        gc = new GC(Display.getDefault());
93
        // Calculate text extent
94
        Point compositeSize = gc.textExtent(text);
95
        //remove temporary gc
96
        gc.dispose();
97
        gc = null;
98
        // Creating new Image
99
        image = new Image(Display.getCurrent(),compositeSize.x+10,compositeSize.y+10);
100
        //create gc for image to be able to draw on it
101
        gc = new GC(image);
102
        //set and fill with bg color
103
        gc.setBackground(GUIHelper.COLOR_LIST_BACKGROUND);
104
        gc.fillRectangle(0, 0, compositeSize.x+10, compositeSize.y+10);
105
        //draw text
106
        gc.drawText(text, 5, 5, true);
107
        //draw border
108
        gc.drawRectangle(0, 0, compositeSize.x+9, compositeSize.y+9);
109
        // Setting widget to DnD image
110
        event.image = image;
111

  
66 112
    }
67 113

  
68 114
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)