1 |
739cbae5
|
Patrick Plitzner
|
/**
|
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 |
652496d7
|
Andreas Müller
|
package eu.etaxonomy.taxeditor.editor.descriptiveDataSet;
|
10 |
739cbae5
|
Patrick Plitzner
|
|
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 |
df5f3355
|
Patrick Plitzner
|
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
|
19 |
739cbae5
|
Patrick Plitzner
|
|
20 |
|
|
/**
|
21 |
|
|
* @author pplitzner
|
22 |
|
|
* @since Dec 19, 2017
|
23 |
|
|
*
|
24 |
|
|
*/
|
25 |
|
|
public class TaxonNodeDropAdapter extends ViewerDropAdapter {
|
26 |
|
|
|
27 |
652496d7
|
Andreas Müller
|
private DescriptiveDataSetEditor descriptiveDataSetEditor;
|
28 |
739cbae5
|
Patrick Plitzner
|
|
29 |
652496d7
|
Andreas Müller
|
public TaxonNodeDropAdapter(DescriptiveDataSetEditor descriptiveDataSetEditor) {
|
30 |
|
|
super(descriptiveDataSetEditor.getTaxonTreeViewer());
|
31 |
|
|
this.descriptiveDataSetEditor = descriptiveDataSetEditor;
|
32 |
739cbae5
|
Patrick Plitzner
|
}
|
33 |
|
|
|
34 |
|
|
/**
|
35 |
|
|
* {@inheritDoc}
|
36 |
|
|
*/
|
37 |
|
|
@Override
|
38 |
|
|
public boolean performDrop(Object data) {
|
39 |
df5f3355
|
Patrick Plitzner
|
TaxonNodeDto taxonNodeDto = (TaxonNodeDto) ((ITreeSelection) data).getFirstElement();
|
40 |
652496d7
|
Andreas Müller
|
descriptiveDataSetEditor.addTaxonNode(taxonNodeDto);
|
41 |
|
|
descriptiveDataSetEditor.setFocus();
|
42 |
739cbae5
|
Patrick Plitzner
|
return true;
|
43 |
|
|
}
|
44 |
|
|
|
45 |
|
|
/**
|
46 |
|
|
* {@inheritDoc}
|
47 |
|
|
*/
|
48 |
|
|
@Override
|
49 |
|
|
public boolean validateDrop(Object target, int operation, TransferData transferType) {
|
50 |
|
|
ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
|
51 |
|
|
if(selection instanceof ITreeSelection
|
52 |
|
|
&& ((IStructuredSelection) selection).size()==1
|
53 |
df5f3355
|
Patrick Plitzner
|
&& ((IStructuredSelection) selection).getFirstElement() instanceof TaxonNodeDto){
|
54 |
739cbae5
|
Patrick Plitzner
|
return true;
|
55 |
|
|
}
|
56 |
|
|
return false;
|
57 |
|
|
}
|
58 |
|
|
|
59 |
|
|
|
60 |
|
|
}
|