Project

General

Profile

Download (2.22 KB) Statistics
| Branch: | Tag: | Revision:
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
		    if(getViewer().getInput()==null){
48
		        //create new feature tree
49
		        FeatureTree featureTree = FeatureTree.NewInstance();
50
		        getViewer().setInput(featureTree);
51
		    }
52
            if(target==null){
53
                FeatureNode root = ((FeatureTree)getViewer().getInput()).getRoot();
54
                root.addChild(characterNode);
55
            }
56
            else{
57
                target.addChild(characterNode);
58
            }
59
		}
60
		getViewer().refresh();
61
		return true;
62
	}
63

    
64
	@Override
65
	public boolean validateDrop(Object target, int operation,
66
			TransferData transferType) {
67
		boolean transferDataIsSupported = FeatureNodeTransfer.getInstance().isSupportedType(transferType);
68
		return transferDataIsSupported;
69
	}
70

    
71
}
(2-2/3)