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.IStructuredSelection;
|
12
|
import org.eclipse.jface.viewers.TreeViewer;
|
13
|
import org.eclipse.swt.dnd.DND;
|
14
|
import org.eclipse.swt.dnd.DragSourceAdapter;
|
15
|
import org.eclipse.swt.dnd.DragSourceEvent;
|
16
|
|
17
|
import eu.etaxonomy.cdm.model.description.FeatureNode;
|
18
|
import eu.etaxonomy.taxeditor.featuretree.FeatureNodeTransfer;
|
19
|
|
20
|
class FeatureNodeDragListener extends DragSourceAdapter {
|
21
|
|
22
|
private final TreeViewer viewer;
|
23
|
|
24
|
public FeatureNodeDragListener(TreeViewer viewer) {
|
25
|
this.viewer = viewer;
|
26
|
}
|
27
|
|
28
|
/**
|
29
|
* Method declared on DragSourceListener
|
30
|
*/
|
31
|
@Override
|
32
|
public void dragFinished(DragSourceEvent event) {
|
33
|
if (!event.doit) {
|
34
|
return;
|
35
|
}
|
36
|
// if the featureNode was moved, remove it from the source viewer
|
37
|
if (event.detail == DND.DROP_MOVE) {
|
38
|
IStructuredSelection selection = (IStructuredSelection) viewer
|
39
|
.getSelection();
|
40
|
viewer.remove(selection);
|
41
|
viewer.refresh();
|
42
|
}
|
43
|
}
|
44
|
|
45
|
/**
|
46
|
* Method declared on DragSourceListener
|
47
|
*/
|
48
|
@Override
|
49
|
public void dragSetData(DragSourceEvent event) {
|
50
|
IStructuredSelection selection = (IStructuredSelection) viewer
|
51
|
.getSelection();
|
52
|
FeatureNode[] featureNodes = (FeatureNode[]) selection.toList()
|
53
|
.toArray(new FeatureNode[selection.size()]);
|
54
|
if (FeatureNodeTransfer.getInstance().isSupportedType(
|
55
|
event.dataType)) {
|
56
|
event.data = featureNodes;
|
57
|
}
|
58
|
}
|
59
|
|
60
|
/**
|
61
|
* Method declared on DragSourceListener
|
62
|
*/
|
63
|
@Override
|
64
|
public void dragStart(DragSourceEvent event) {
|
65
|
event.doit = !viewer.getSelection().isEmpty();
|
66
|
}
|
67
|
|
68
|
}
|