Project

General

Profile

Download (1.69 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2017 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.featuretree.e4;
10

    
11
import org.eclipse.jface.viewers.ISelection;
12
import org.eclipse.jface.viewers.IStructuredSelection;
13
import org.eclipse.jface.viewers.TreeViewer;
14
import org.eclipse.swt.dnd.DragSourceAdapter;
15
import org.eclipse.swt.dnd.DragSourceEvent;
16

    
17
import eu.etaxonomy.cdm.model.term.TermNode;
18
import eu.etaxonomy.taxeditor.featuretree.TermNodeTransfer;
19

    
20
public class TermNodeDragListener extends DragSourceAdapter {
21

    
22
	private final TreeViewer viewer;
23

    
24
	public TermNodeDragListener(TreeViewer viewer) {
25
		this.viewer = viewer;
26
	}
27

    
28
    /**
29
     * Method declared on DragSourceListener
30
     */
31
    @Override
32
    public void dragSetData(DragSourceEvent event) {
33
        IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
34
        if(selection!=null && !selection.isEmpty()){
35
            TermNode[] featureNodes = (TermNode[]) selection.toList().toArray(new TermNode[selection.size()]);
36
            if (TermNodeTransfer.getInstance().isSupportedType(event.dataType)) {
37
                event.data = featureNodes;
38
            }
39

    
40
        }
41

    
42
    }
43

    
44
	/**
45
	 * Method declared on DragSourceListener
46
	 */
47
	@Override
48
	public void dragStart(DragSourceEvent event) {
49
	    ISelection sel = viewer.getSelection();
50
	    event.doit = !viewer.getSelection().isEmpty()
51
                && ((IStructuredSelection) viewer.getSelection()).toList()
52
                .stream().allMatch(element -> element instanceof TermNode);
53

    
54
	}
55

    
56
}
(4-4/9)