1
|
/**
|
2
|
* Copyright (C) 2009 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.viewers.Viewer;
|
12
|
import org.eclipse.jface.viewers.ViewerDropAdapter;
|
13
|
import org.eclipse.swt.dnd.TransferData;
|
14
|
|
15
|
import eu.etaxonomy.cdm.model.description.Character;
|
16
|
import eu.etaxonomy.cdm.model.description.FeatureNode;
|
17
|
import eu.etaxonomy.cdm.model.description.FeatureTree;
|
18
|
import eu.etaxonomy.taxeditor.featuretree.FeatureNodeTransfer;
|
19
|
|
20
|
/**
|
21
|
*
|
22
|
* @author pplitzner
|
23
|
* @date Jun 1, 2017
|
24
|
*
|
25
|
*/
|
26
|
public class CharacterDropAdapter extends ViewerDropAdapter {
|
27
|
|
28
|
protected CharacterDropAdapter(Viewer viewer) {
|
29
|
super(viewer);
|
30
|
}
|
31
|
|
32
|
@Override
|
33
|
public boolean performDrop(Object data) {
|
34
|
|
35
|
FeatureNode target = (FeatureNode) getCurrentTarget();
|
36
|
int currentLocation = getCurrentLocation();
|
37
|
Object[] characterData = (Object[]) data;
|
38
|
|
39
|
//create new Character
|
40
|
if(characterData.length==2){
|
41
|
FeatureNode structureNode = (FeatureNode) characterData[0];
|
42
|
FeatureNode propertyNode = (FeatureNode) characterData[1];
|
43
|
String label = structureNode.getFeature().toString()+" "+propertyNode.getFeature().toString();
|
44
|
Character character = Character.NewInstance(structureNode, propertyNode, null, label, label);
|
45
|
FeatureNode characterNode = FeatureNode.NewInstance(character);
|
46
|
|
47
|
Object input = getViewer().getInput();
|
48
|
if(input==null){
|
49
|
//create new feature tree
|
50
|
FeatureTree featureTree = FeatureTree.NewInstance();
|
51
|
getViewer().setInput(featureTree);
|
52
|
}
|
53
|
if(target==null){
|
54
|
FeatureNode root = ((FeatureTree)input).getRoot();
|
55
|
root.addChild(characterNode);
|
56
|
}
|
57
|
else{
|
58
|
target.addChild(characterNode);
|
59
|
}
|
60
|
}
|
61
|
getViewer().refresh();
|
62
|
return true;
|
63
|
}
|
64
|
|
65
|
@Override
|
66
|
public boolean validateDrop(Object target, int operation,
|
67
|
TransferData transferType) {
|
68
|
boolean transferDataIsSupported = FeatureNodeTransfer.getInstance().isSupportedType(transferType);
|
69
|
return transferDataIsSupported;
|
70
|
}
|
71
|
|
72
|
}
|