ref #7981 include unpublished to taxon filter (explicit checkbox is still missing)
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / descriptiveDataSet / TaxonNodeDropAdapter.java
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.descriptiveDataSet;
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.persistence.dto.TaxonNodeDto;
19
20 /**
21 * @author pplitzner
22 * @since Dec 19, 2017
23 *
24 */
25 public class TaxonNodeDropAdapter extends ViewerDropAdapter {
26
27 private DescriptiveDataSetEditor descriptiveDataSetEditor;
28
29 public TaxonNodeDropAdapter(DescriptiveDataSetEditor descriptiveDataSetEditor) {
30 super(descriptiveDataSetEditor.getTaxonTreeViewer());
31 this.descriptiveDataSetEditor = descriptiveDataSetEditor;
32 }
33
34 /**
35 * {@inheritDoc}
36 */
37 @Override
38 public boolean performDrop(Object data) {
39 TaxonNodeDto taxonNodeDto = (TaxonNodeDto) ((ITreeSelection) data).getFirstElement();
40 descriptiveDataSetEditor.addTaxonNode(taxonNodeDto);
41 descriptiveDataSetEditor.setFocus();
42 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 && ((IStructuredSelection) selection).getFirstElement() instanceof TaxonNodeDto){
54 return true;
55 }
56 return false;
57 }
58
59
60 }