2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.editor
.workingSet
;
11 import org
.eclipse
.jface
.viewers
.Viewer
;
12 import org
.eclipse
.jface
.viewers
.ViewerDropAdapter
;
13 import org
.eclipse
.swt
.dnd
.TransferData
;
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
;
26 public class CharacterDropAdapter
extends ViewerDropAdapter
{
28 protected CharacterDropAdapter(Viewer viewer
) {
33 public boolean performDrop(Object data
) {
35 FeatureNode target
= (FeatureNode
) getCurrentTarget();
36 int currentLocation
= getCurrentLocation();
37 Object
[] characterData
= (Object
[]) data
;
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
);
47 if(getViewer().getInput()==null){
48 //create new feature tree
49 FeatureTree featureTree
= FeatureTree
.NewInstance();
50 getViewer().setInput(featureTree
);
53 FeatureNode root
= ((FeatureTree
)getViewer().getInput()).getRoot();
54 root
.addChild(characterNode
);
57 target
.addChild(characterNode
);
60 getViewer().refresh();
65 public boolean validateDrop(Object target
, int operation
,
66 TransferData transferType
) {
67 boolean transferDataIsSupported
= FeatureNodeTransfer
.getInstance().isSupportedType(transferType
);
68 return transferDataIsSupported
;