Merge branch 'develop' into featureTreeEditor
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / featuretree / FeatureNodeDragListener.java
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;
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
19 /**
20 * @author pplitzner
21 * @since Jun 2, 2017
22 *
23 */
24 public class FeatureNodeDragListener extends DragSourceAdapter {
25
26 private final TreeViewer viewer;
27
28 public FeatureNodeDragListener(TreeViewer viewer) {
29 this.viewer = viewer;
30 }
31
32 /**
33 * Method declared on DragSourceListener
34 */
35 @Override
36 public void dragFinished(DragSourceEvent event) {
37 if (!event.doit) {
38 return;
39 }
40 if (event.detail == DND.DROP_MOVE) {
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 }