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 java.util.Set;
|
12
|
|
13
|
import org.eclipse.jface.util.LocalSelectionTransfer;
|
14
|
import org.eclipse.jface.viewers.ISelection;
|
15
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
16
|
import org.eclipse.jface.viewers.ITreeSelection;
|
17
|
import org.eclipse.jface.viewers.ViewerDropAdapter;
|
18
|
import org.eclipse.swt.dnd.TransferData;
|
19
|
|
20
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
21
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
22
|
|
23
|
/**
|
24
|
* @author pplitzner
|
25
|
* @since Dec 19, 2017
|
26
|
*
|
27
|
*/
|
28
|
public class TaxonNodeDropAdapter extends ViewerDropAdapter {
|
29
|
|
30
|
private WorkingSetEditor workingSetEditor;
|
31
|
|
32
|
public TaxonNodeDropAdapter(WorkingSetEditor workingSetEditor) {
|
33
|
super(workingSetEditor.getTaxonTreeViewer());
|
34
|
this.workingSetEditor = workingSetEditor;
|
35
|
}
|
36
|
|
37
|
/**
|
38
|
* {@inheritDoc}
|
39
|
*/
|
40
|
@Override
|
41
|
public boolean performDrop(Object data) {
|
42
|
TaxonNode taxonNode= (TaxonNode) ((ITreeSelection) data).getFirstElement();
|
43
|
//check if node belongs to same classification
|
44
|
Set<TaxonNode> taxonSubtreeFilter = workingSetEditor.getWorkingSet().getTaxonSubtreeFilter();
|
45
|
if(taxonSubtreeFilter!=null && !taxonSubtreeFilter.isEmpty()){
|
46
|
if(!taxonSubtreeFilter.iterator().next().getClassification().equals(taxonNode.getClassification())){
|
47
|
MessagingUtils.warningDialog("Classifications do not match", this.getClass(),
|
48
|
"The taxon node you are trying to add belongs to another classification "
|
49
|
+ "than the node(s) belonging to the working set.");
|
50
|
return false;
|
51
|
}
|
52
|
|
53
|
}
|
54
|
workingSetEditor.addTaxonNode(taxonNode);
|
55
|
return true;
|
56
|
}
|
57
|
|
58
|
/**
|
59
|
* {@inheritDoc}
|
60
|
*/
|
61
|
@Override
|
62
|
public boolean validateDrop(Object target, int operation, TransferData transferType) {
|
63
|
ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
|
64
|
if(selection instanceof ITreeSelection
|
65
|
&& ((IStructuredSelection) selection).size()==1
|
66
|
&& ((IStructuredSelection) selection).getFirstElement() instanceof TaxonNode){
|
67
|
return true;
|
68
|
}
|
69
|
return false;
|
70
|
}
|
71
|
|
72
|
|
73
|
}
|