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
.DragSourceAdapter
;
14 import org
.eclipse
.swt
.dnd
.DragSourceEvent
;
16 import eu
.etaxonomy
.cdm
.model
.description
.FeatureNode
;
17 import eu
.etaxonomy
.taxeditor
.featuretree
.FeatureNodeTransfer
;
19 public class FeatureNodeDragListener
extends DragSourceAdapter
{
21 private final TreeViewer viewer
;
23 public FeatureNodeDragListener(TreeViewer viewer
) {
28 * Method declared on DragSourceListener
31 public void dragSetData(DragSourceEvent event
) {
32 IStructuredSelection selection
= (IStructuredSelection
) viewer
.getSelection();
33 if(selection
!=null && !selection
.isEmpty()){
34 FeatureNode
[] featureNodes
= (FeatureNode
[]) selection
.toList().toArray(new FeatureNode
[selection
.size()]);
35 if (FeatureNodeTransfer
.getInstance().isSupportedType(event
.dataType
)) {
36 event
.data
= featureNodes
;
42 * Method declared on DragSourceListener
45 public void dragStart(DragSourceEvent event
) {
46 event
.doit
= !viewer
.getSelection().isEmpty()
47 && ((IStructuredSelection
) viewer
.getSelection()).toList()
48 .stream().allMatch(element
-> element
instanceof FeatureNode
);