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
.model
.description
.FeatureNode
;
17 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
18 import eu
.etaxonomy
.taxeditor
.featuretree
.FeatureNodeTransfer
;
19 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
21 class FeatureNodeDropAdapter
extends ViewerDropAdapter
{
26 private final FeatureTreeEditor featureTreeEditor
;
28 protected FeatureNodeDropAdapter(FeatureTreeEditor featureTreeEditor
, Viewer viewer
) {
30 this.featureTreeEditor
= featureTreeEditor
;
34 public boolean performDrop(Object data
) {
35 FeatureNode target
= (FeatureNode
) getCurrentTarget();
39 int location
= getCurrentLocation();
40 FeatureNode parent
= target
.getParent();
41 if (location
== LOCATION_BEFORE
) {
42 position
= Math
.max(0, parent
.getIndex(target
) - 1);
46 if (location
== LOCATION_AFTER
) {
47 position
= parent
.getIndex(target
);
52 // set target to root node if there is no target specified
54 FeatureTree featureTree
= (FeatureTree
) getViewer().getInput();
55 target
= featureTree
.getRoot();
58 Object
[] droppedObjects
= (Object
[]) data
;
59 TreeViewer viewer
= (TreeViewer
) getViewer();
61 // cannot drop a feature node onto itself
62 for (Object droppedObject
: droppedObjects
) {
63 if (droppedObject
== null) {
64 MessagingUtils
.warningDialog(
65 "Operation not supported yet",
67 "We are currently unable to change the order of freshly created "
68 + "feature trees nodes. Please close and reopen the dialog to change the order of features.");
71 if (droppedObject
.equals(target
)) {
75 for (Object droppedObject
: droppedObjects
) {
76 FeatureNode droppedNode
= (FeatureNode
) droppedObject
;
77 target
.addChild(droppedNode
, position
);
78 viewer
.add(target
, droppedNode
);
79 viewer
.reveal(droppedNode
);
81 this.featureTreeEditor
.setDirty(true);
86 public boolean validateDrop(Object target
, int operation
,
87 TransferData transferData
) {
88 return FeatureNodeTransfer
.getInstance().isSupportedType(