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.editor.workingSet;
|
10
|
|
11
|
import org.eclipse.jface.util.LocalSelectionTransfer;
|
12
|
import org.eclipse.jface.viewers.ISelection;
|
13
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
14
|
import org.eclipse.jface.viewers.ITreeSelection;
|
15
|
import org.eclipse.jface.viewers.ViewerDropAdapter;
|
16
|
import org.eclipse.swt.dnd.TransferData;
|
17
|
|
18
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
19
|
|
20
|
/**
|
21
|
* @author pplitzner
|
22
|
* @since Dec 19, 2017
|
23
|
*
|
24
|
*/
|
25
|
public class TaxonNodeDropAdapter extends ViewerDropAdapter {
|
26
|
|
27
|
private WorkingSetEditor workingSetEditor;
|
28
|
|
29
|
public TaxonNodeDropAdapter(WorkingSetEditor workingSetEditor) {
|
30
|
super(workingSetEditor.getTaxonTreeViewer());
|
31
|
this.workingSetEditor = workingSetEditor;
|
32
|
}
|
33
|
|
34
|
/**
|
35
|
* {@inheritDoc}
|
36
|
*/
|
37
|
@Override
|
38
|
public boolean performDrop(Object data) {
|
39
|
TaxonNode taxonNode= (TaxonNode) ((ITreeSelection) data).getFirstElement();
|
40
|
workingSetEditor.addTaxonNode(taxonNode);
|
41
|
return true;
|
42
|
}
|
43
|
|
44
|
/**
|
45
|
* {@inheritDoc}
|
46
|
*/
|
47
|
@Override
|
48
|
public boolean validateDrop(Object target, int operation, TransferData transferType) {
|
49
|
ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
|
50
|
if(selection instanceof ITreeSelection
|
51
|
&& ((IStructuredSelection) selection).size()==1
|
52
|
&& ((IStructuredSelection) selection).getFirstElement() instanceof TaxonNode){
|
53
|
return true;
|
54
|
}
|
55
|
return false;
|
56
|
}
|
57
|
|
58
|
|
59
|
}
|