2 * Copyright (C) 2017 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
.featuretree
.e4
;
11 import org
.eclipse
.jface
.viewers
.TreeViewer
;
12 import org
.eclipse
.jface
.viewers
.Viewer
;
13 import org
.eclipse
.jface
.viewers
.ViewerDropAdapter
;
14 import org
.eclipse
.swt
.dnd
.TransferData
;
16 import eu
.etaxonomy
.cdm
.api
.service
.IFeatureNodeService
;
17 import eu
.etaxonomy
.cdm
.model
.description
.FeatureNode
;
18 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
19 import eu
.etaxonomy
.taxeditor
.featuretree
.FeatureNodeTransfer
;
20 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
22 class FeatureNodeDropAdapter
extends ViewerDropAdapter
{
24 private final FeatureTreeEditor featureTreeEditor
;
26 protected FeatureNodeDropAdapter(FeatureTreeEditor featureTreeEditor
, Viewer viewer
) {
28 this.featureTreeEditor
= featureTreeEditor
;
32 public boolean performDrop(Object data
) {
33 FeatureNode target
= (FeatureNode
) getCurrentTarget();
37 int location
= getCurrentLocation();
38 FeatureNode parent
= target
.getParent();
39 if (location
== LOCATION_BEFORE
) {
40 position
= Math
.max(0, parent
.getIndex(target
) - 1);
44 if (location
== LOCATION_AFTER
) {
45 position
= parent
.getIndex(target
);
50 // set target to root node if there is no target specified
52 FeatureTree featureTree
= (FeatureTree
) getViewer().getInput();
53 target
= featureTree
.getRoot();
56 Object
[] droppedObjects
= (Object
[]) data
;
57 TreeViewer viewer
= (TreeViewer
) getViewer();
59 // cannot drop a feature node onto itself
60 for (Object droppedObject
: droppedObjects
) {
61 if (droppedObject
.equals(target
)) {
65 for (Object droppedObject
: droppedObjects
) {
66 FeatureNode droppedNode
= (FeatureNode
) droppedObject
;
67 CdmStore
.getService(IFeatureNodeService
.class).moveFeatureNode(droppedNode
.getUuid(), target
.getUuid(), position
);
69 // viewer.reveal(droppedNode);
71 this.featureTreeEditor
.setDirty(true);
76 public boolean validateDrop(Object target
, int operation
, TransferData transferData
) {
77 return FeatureNodeTransfer
.getInstance().isSupportedType(transferData
);