1 |
e8f9b86d
|
U-BGBM\k.luther
|
/**
|
2 |
|
|
* Copyright (C) 2015 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.navigation.navigator;
|
10 |
|
|
|
11 |
|
|
import java.util.ArrayList;
|
12 |
|
|
import java.util.List;
|
13 |
|
|
|
14 |
|
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
15 |
|
|
import org.eclipse.jface.viewers.Viewer;
|
16 |
|
|
import org.eclipse.swt.dnd.DragSourceAdapter;
|
17 |
|
|
import org.eclipse.swt.dnd.DragSourceEvent;
|
18 |
|
|
import org.eclipse.ui.navigator.CommonViewer;
|
19 |
|
|
|
20 |
|
|
|
21 |
|
|
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
|
22 |
|
|
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
|
23 |
|
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
24 |
|
|
import eu.etaxonomy.taxeditor.dnd.transfer.TaxonNodeTransfer;
|
25 |
|
|
import eu.etaxonomy.taxeditor.editor.definedterm.TermTransfer;
|
26 |
|
|
|
27 |
|
|
/**
|
28 |
|
|
* @author k.luther
|
29 |
|
|
* @date 02.06.2015
|
30 |
|
|
*
|
31 |
|
|
*/
|
32 |
|
|
public class TreeNodeDragListener extends DragSourceAdapter {
|
33 |
|
|
private CommonViewer viewer;
|
34 |
|
|
|
35 |
|
|
/**
|
36 |
|
|
*
|
37 |
|
|
*/
|
38 |
|
|
public TreeNodeDragListener(CommonViewer viewer) {
|
39 |
|
|
this.viewer = viewer;
|
40 |
|
|
}
|
41 |
|
|
|
42 |
|
|
|
43 |
|
|
public void setViewer(CommonViewer viewer){
|
44 |
|
|
this.viewer = viewer;
|
45 |
|
|
}
|
46 |
|
|
/* (non-Javadoc)
|
47 |
|
|
* @see org.eclipse.swt.dnd.DragSourceAdapter#dragStart(org.eclipse.swt.dnd.DragSourceEvent)
|
48 |
|
|
*/
|
49 |
|
|
@Override
|
50 |
|
|
public void dragStart(DragSourceEvent event) {
|
51 |
|
|
|
52 |
|
|
event.doit = true;// set to false if needed - default is true
|
53 |
|
|
}
|
54 |
|
|
|
55 |
|
|
/* (non-Javadoc)
|
56 |
|
|
* @see org.eclipse.swt.dnd.DragSourceAdapter#dragFinished(org.eclipse.swt.dnd.DragSourceEvent)
|
57 |
|
|
*/
|
58 |
|
|
@Override
|
59 |
|
|
public void dragFinished(DragSourceEvent event) {
|
60 |
|
|
// TODO Auto-generated method stub
|
61 |
|
|
super.dragFinished(event);
|
62 |
|
|
}
|
63 |
|
|
|
64 |
|
|
/* (non-Javadoc)
|
65 |
|
|
* @see org.eclipse.swt.dnd.DragSourceAdapter#dragSetData(org.eclipse.swt.dnd.DragSourceEvent)
|
66 |
|
|
*/
|
67 |
|
|
@Override
|
68 |
|
|
public void dragSetData(DragSourceEvent event) {
|
69 |
|
|
|
70 |
|
|
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
|
71 |
|
|
List<ITaxonTreeNode> taxonNodes = new ArrayList<ITaxonTreeNode>();
|
72 |
|
|
|
73 |
|
|
for (Object object : selection.toList()){
|
74 |
|
|
taxonNodes.add((ITaxonTreeNode)object);
|
75 |
|
|
}
|
76 |
|
|
|
77 |
|
|
if (TaxonNodeTransfer.getInstance().isSupportedType(
|
78 |
|
|
event.dataType)) {
|
79 |
|
|
event.data = taxonNodes.toArray(new TaxonNode[taxonNodes.size()]);
|
80 |
|
|
}
|
81 |
|
|
}
|
82 |
|
|
}
|