Project

General

Profile

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

    
11
import java.util.List;
12

    
13
import org.eclipse.jface.util.LocalSelectionTransfer;
14
import org.eclipse.jface.viewers.IStructuredSelection;
15
import org.eclipse.jface.viewers.TreeSelection;
16
import org.eclipse.jface.viewers.Viewer;
17
import org.eclipse.swt.dnd.DragSourceAdapter;
18
import org.eclipse.swt.dnd.DragSourceEvent;
19

    
20
import eu.etaxonomy.cdm.persistence.dto.TermDto;
21
import eu.etaxonomy.taxeditor.editor.definedterm.TermTransfer;
22

    
23
/**
24
 *
25
 * @author pplitzner
26
 * @since Aug 22, 2017
27
 *
28
 */
29
public class DefinedTermDragListenerE4 extends DragSourceAdapter {
30

    
31
	private Viewer viewer;
32

    
33
	public DefinedTermDragListenerE4(Viewer viewer) {
34
		this.viewer = viewer;
35
	}
36

    
37
	@Override
38
	public void dragStart(DragSourceEvent event) {
39
	    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
40
	    List list = selection.toList();
41
	    for (Object object : list) {
42
            if(!(object instanceof TermDto)){
43
                event.doit = false;
44
                return;
45
            }
46
        }
47
		event.doit = true;
48
	}
49

    
50
	@Override
51
	public void dragFinished(DragSourceEvent event) {
52
	    super.dragFinished(event);
53
	    LocalSelectionTransfer.getTransfer().setSelection(null);
54
	}
55

    
56
	@Override
57
	public void dragSetData(DragSourceEvent event) {
58
	    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
59
        if (LocalSelectionTransfer.getTransfer().isSupportedType(event.dataType)) {
60
            LocalSelectionTransfer.getTransfer().setSelection(selection);
61
            if (selection.getFirstElement() instanceof TermDto){
62
                TermTransfer.getInstance().setSelection((TermDto)selection.getFirstElement());
63
            }
64
        }
65

    
66
        if(selection!=null && !selection.isEmpty()){
67
            if (selection instanceof TreeSelection && ((TreeSelection)selection).getFirstElement() instanceof TermDto){
68
                TermDto[] featureNodes = (TermDto[]) selection.toList().toArray(new TermDto[selection.size()]);
69

    
70
                    event.data = featureNodes;
71
            }
72
        }
73

    
74
	}
75

    
76
}
(1-1/5)