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
.ISelection
;
12 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
13 import org
.eclipse
.jface
.viewers
.TreeSelection
;
14 import org
.eclipse
.jface
.viewers
.TreeViewer
;
15 import org
.eclipse
.swt
.dnd
.DragSourceAdapter
;
16 import org
.eclipse
.swt
.dnd
.DragSourceEvent
;
18 import eu
.etaxonomy
.cdm
.model
.term
.TermNode
;
19 import eu
.etaxonomy
.cdm
.persistence
.dto
.TermNodeDto
;
20 import eu
.etaxonomy
.taxeditor
.featuretree
.FeatureNodeDtoTransfer
;
22 public class FeatureNodeDtoDragListener
extends DragSourceAdapter
{
24 private final TreeViewer viewer
;
26 public FeatureNodeDtoDragListener(TreeViewer viewer
) {
31 * Method declared on DragSourceListener
34 public void dragSetData(DragSourceEvent event
) {
35 IStructuredSelection selection
= (IStructuredSelection
) viewer
.getSelection();
36 if(selection
!=null && !selection
.isEmpty()){
37 if (selection
instanceof TreeSelection
&& ((TreeSelection
)selection
).getFirstElement() instanceof TermNodeDto
){
38 TermNodeDto
[] featureNodes
= (TermNodeDto
[]) selection
.toList().toArray(new TermNodeDto
[selection
.size()]);
39 if (FeatureNodeDtoTransfer
.getInstance().isSupportedType(event
.dataType
)) {
40 event
.data
= featureNodes
;
48 * Method declared on DragSourceListener
51 public void dragStart(DragSourceEvent event
) {
52 ISelection sel
= viewer
.getSelection();
53 if (sel
instanceof TreeSelection
&& ((TreeSelection
)sel
).getFirstElement() instanceof TermNodeDto
){
54 event
.doit
= !viewer
.getSelection().isEmpty()
55 && ((IStructuredSelection
) viewer
.getSelection()).toList()
56 .stream().allMatch(element
-> element
instanceof TermNodeDto
);
58 event
.doit
= !viewer
.getSelection().isEmpty()
59 && ((IStructuredSelection
) viewer
.getSelection()).toList()
60 .stream().allMatch(element
-> element
instanceof TermNode
);