ref #6694 Fix session handling when moving feature nodes
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / featuretree / e4 / 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.e4;
10
11 import org.eclipse.jface.viewers.IStructuredSelection;
12 import org.eclipse.jface.viewers.TreeViewer;
13 import org.eclipse.swt.dnd.DragSourceAdapter;
14 import org.eclipse.swt.dnd.DragSourceEvent;
15
16 import eu.etaxonomy.cdm.model.description.FeatureNode;
17 import eu.etaxonomy.taxeditor.featuretree.FeatureNodeTransfer;
18
19 class FeatureNodeDragListener extends DragSourceAdapter {
20
21 private final TreeViewer viewer;
22
23 public FeatureNodeDragListener(TreeViewer viewer) {
24 this.viewer = viewer;
25 }
26
27 /**
28 * Method declared on DragSourceListener
29 */
30 @Override
31 public void dragSetData(DragSourceEvent event) {
32 IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
33 FeatureNode[] featureNodes = (FeatureNode[]) selection.toList().toArray(new FeatureNode[selection.size()]);
34 if (FeatureNodeTransfer.getInstance().isSupportedType(event.dataType)) {
35 event.data = featureNodes;
36 }
37 }
38
39 /**
40 * Method declared on DragSourceListener
41 */
42 @Override
43 public void dragStart(DragSourceEvent event) {
44 event.doit = !viewer.getSelection().isEmpty();
45 }
46
47 }