2 * Copyright (C) 2017 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.featuretree
.e4
;
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
;
17 import eu
.etaxonomy
.cdm
.model
.description
.FeatureNode
;
18 import eu
.etaxonomy
.taxeditor
.featuretree
.FeatureNodeTransfer
;
20 class FeatureNodeDragListener
extends DragSourceAdapter
{
22 private final TreeViewer viewer
;
24 public FeatureNodeDragListener(TreeViewer viewer
) {
29 * Method declared on DragSourceListener
32 public void dragFinished(DragSourceEvent event
) {
36 // if the featureNode was moved, remove it from the source viewer
37 if (event
.detail
== DND
.DROP_MOVE
) {
38 IStructuredSelection selection
= (IStructuredSelection
) viewer
40 viewer
.remove(selection
);
46 * Method declared on DragSourceListener
49 public void dragSetData(DragSourceEvent event
) {
50 IStructuredSelection selection
= (IStructuredSelection
) viewer
52 FeatureNode
[] featureNodes
= (FeatureNode
[]) selection
.toList()
53 .toArray(new FeatureNode
[selection
.size()]);
54 if (FeatureNodeTransfer
.getInstance().isSupportedType(
56 event
.data
= featureNodes
;
61 * Method declared on DragSourceListener
64 public void dragStart(DragSourceEvent event
) {
65 event
.doit
= !viewer
.getSelection().isEmpty();