commit 24b8f2f1ab3aa3fc2ab32e0b883bba6a6878973c
Author: Patrick Plitzner <p.plitzner@bgbm.org>
Date:   Mon Sep 4 18:26:07 2017 +0200

    ref #6595 migrate drag and drop functionality

diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/TaxonNameEditorE4.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/TaxonNameEditorE4.java
index d4373e041..9326674f6 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/TaxonNameEditorE4.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/TaxonNameEditorE4.java
@@ -34,6 +34,9 @@ import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.ISelectionProvider;
 import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.DropTarget;
+import org.eclipse.swt.dnd.Transfer;
 import org.eclipse.swt.graphics.Color;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.ui.ISelectionListener;
@@ -56,6 +59,7 @@ import eu.etaxonomy.cdm.model.taxon.TaxonBase;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
 import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
 import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
+import eu.etaxonomy.taxeditor.editor.CdmDataTransfer;
 import eu.etaxonomy.taxeditor.editor.ISecuredEditor;
 import eu.etaxonomy.taxeditor.editor.ITaxonEditor;
 import eu.etaxonomy.taxeditor.editor.e4.TaxonEditorInputE4;
@@ -67,6 +71,7 @@ import eu.etaxonomy.taxeditor.editor.name.e4.container.AcceptedNameContainerE4;
 import eu.etaxonomy.taxeditor.editor.name.e4.container.ContainerFactoryE4;
 import eu.etaxonomy.taxeditor.editor.name.e4.container.HomotypicalSynonymGroupE4;
 import eu.etaxonomy.taxeditor.editor.name.e4.container.MisappliedGroupE4;
+import eu.etaxonomy.taxeditor.editor.name.e4.dnd.NameEditorDropTargetListenerE4;
 import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
 import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
@@ -90,7 +95,7 @@ import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
  */
 public class TaxonNameEditorE4 implements IConversationEnabled, IDirtyMarkable, IPartContentHasDetails,
         IPartContentHasSupplementalData, IPartContentHasMedia, IPartContentHasFactualData, IPartChangeListener,
-        ISelectionListener, ISecuredEditor, IPostOperationEnabled, IE4SavablePart, ITaxonEditor {
+        ISelectionListener, ISecuredEditor, IPostOperationEnabled, IE4SavablePart, ITaxonEditor, IDropTargetableE4 {
 
 	private Taxon taxon;
 
@@ -107,8 +112,7 @@ public class TaxonNameEditorE4 implements IConversationEnabled, IDirtyMarkable,
 	private List<HomotypicalSynonymGroupE4> heterotypicSynonymGroups = new ArrayList<>();
 	private MisappliedGroupE4 misappliedGroup;
 
-	//FIXME E4 migrate dnd
-//	private DropTarget target;
+	private DropTarget target;
 
 	private TaxonBase objectAffectedByLastOperation;
 
@@ -393,20 +397,22 @@ public class TaxonNameEditorE4 implements IConversationEnabled, IDirtyMarkable,
 
         setFocus();
 
+        createDragSupport();
+
         setPartName();
 	}
 
-	//FIXME E4 migrate drag support
-//   private void createDragSupport() {
-//       // Listen for names being dragged outside of existing homotypic groups -
-//       // user wants to create a new group
-//       Transfer[] types = new Transfer[] { CdmDataTransfer.getInstance() };
-//       int operations = DND.DROP_MOVE;
-//       if (target == null) {
-//           target = new DropTarget(parent, operations);
-//           target.setTransfer(types);
-//           target.addDropListener(new NameEditorDropTargetListener(this));
-//       }
+   private void createDragSupport() {
+       // Listen for names being dragged outside of existing homotypic groups -
+       // user wants to create a new group
+       Transfer[] types = new Transfer[] { CdmDataTransfer.getInstance() };
+       int operations = DND.DROP_MOVE;
+       if (target == null) {
+           target = new DropTarget(parent, operations);
+           target.setTransfer(types);
+           target.addDropListener(new NameEditorDropTargetListenerE4(this));
+       }
+   }
 
 	public AcceptedNameContainerE4 getAcceptedNameContainer() {
 		return getAcceptedGroup().getAcceptedNameContainer();
@@ -504,19 +510,18 @@ public class TaxonNameEditorE4 implements IConversationEnabled, IDirtyMarkable,
 				: getAcceptedNameContainer();
 	}
 
-	//FIXME E4 migrate drag n drop
-//    @Override
-//    public void dragEntered() {
-//        // TODO change this
-//        getControl().setBackground(
-//                AbstractUtility.getColor(Resources.COLOR_DRAG_ENTER));
-//    }
-//
-//    @Override
-//    public void dragLeft() {
-//        getControl().setBackground(
-//                AbstractUtility.getColor(Resources.COLOR_COMPOSITE_BACKGROUND));
-//    }
+    @Override
+    public void dragEntered() {
+        // TODO change this
+        getControl().setBackground(
+                AbstractUtility.getColor(Resources.COLOR_DRAG_ENTER));
+    }
+
+    @Override
+    public void dragLeft() {
+        getControl().setBackground(
+                AbstractUtility.getColor(Resources.COLOR_COMPOSITE_BACKGROUND));
+    }
 
 
 	public void setMisapplicationsGroup(MisappliedGroupE4 misappliedGroup) {
@@ -652,6 +657,7 @@ public class TaxonNameEditorE4 implements IConversationEnabled, IDirtyMarkable,
         return undoContext;
     }
 
+    @Override
     public Composite getControl(){
         return managedForm.getForm().getBody();
     }
@@ -677,4 +683,12 @@ public class TaxonNameEditorE4 implements IConversationEnabled, IDirtyMarkable,
         return input;
     }
 
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public TaxonNameEditorE4 getEditor() {
+        return this;
+    }
+
 }
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/container/AbstractGroupedContainerE4.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/container/AbstractGroupedContainerE4.java
index 401e64bce..a896155d1 100755
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/container/AbstractGroupedContainerE4.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/container/AbstractGroupedContainerE4.java
@@ -15,7 +15,6 @@ import java.util.Set;
 
 import org.apache.commons.lang.StringUtils;
 import org.eclipse.core.runtime.Assert;
-import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
 import org.eclipse.jface.dialogs.Dialog;
 import org.eclipse.jface.text.IDocument;
 import org.eclipse.jface.text.Position;
@@ -60,7 +59,9 @@ import eu.etaxonomy.taxeditor.editor.name.container.IContainerConstants;
 import eu.etaxonomy.taxeditor.editor.name.container.LineBreakListener;
 import eu.etaxonomy.taxeditor.editor.name.container.LineWrapSupport;
 import eu.etaxonomy.taxeditor.editor.name.container.NameViewer;
+import eu.etaxonomy.taxeditor.editor.name.dnd.NameEditorDragSourceEffect;
 import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
+import eu.etaxonomy.taxeditor.editor.name.e4.dnd.NameEditorDragListenerE4;
 import eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInNewGroupOperation;
 import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.model.IElementHasDetails;
@@ -682,10 +683,9 @@ abstract public class AbstractGroupedContainerE4<T extends TaxonBase> implements
 						operations);
 				dragSource.setTransfer(types);
 
-				//FIXME E4 migrate dnd
-//				dragSource.addDragListener(new NameEditorDragListener(this));
-//				dragSource.setDragSourceEffect(new NameEditorDragSourceEffect(
-//						control));
+				dragSource.addDragListener(new NameEditorDragListenerE4(this));
+				dragSource.setDragSourceEffect(new NameEditorDragSourceEffect(
+						control));
 			}
 		}
 	}
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/dnd/NameEditorDragListenerE4.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/dnd/NameEditorDragListenerE4.java
new file mode 100644
index 000000000..965ba317b
--- /dev/null
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/dnd/NameEditorDragListenerE4.java
@@ -0,0 +1,57 @@
+/**
+ *
+ */
+package eu.etaxonomy.taxeditor.editor.name.e4.dnd;
+
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.DragSourceAdapter;
+import org.eclipse.swt.dnd.DragSourceEvent;
+import org.eclipse.ui.forms.ManagedForm;
+
+import eu.etaxonomy.cdm.model.common.ICdmBase;
+import eu.etaxonomy.taxeditor.editor.CdmDataTransfer;
+import eu.etaxonomy.taxeditor.editor.name.e4.container.AbstractGroupedContainerE4;
+
+/**
+ *
+ * @author pplitzner
+ * @date 04.09.2017
+ *
+ */
+public class NameEditorDragListenerE4 extends DragSourceAdapter {
+
+	private AbstractGroupedContainerE4 container;
+
+	public NameEditorDragListenerE4(AbstractGroupedContainerE4 container){
+		this.container = container;
+	}
+
+	/** {@inheritDoc} */
+	@Override
+    public void dragFinished(DragSourceEvent event) {
+		if(!event.doit) {
+            return;
+        }
+		if(event.detail == DND.DROP_MOVE){
+			ManagedForm managedForm = container.getGroup().getEditor().getManagedForm();
+			container.getGroup().remove(container);
+			managedForm.reflow(true);
+		}
+
+	};
+
+	/** {@inheritDoc} */
+	@Override
+	public void dragSetData(DragSourceEvent event) {
+		ICdmBase[] cdmBaseObjects = new ICdmBase[]{container.getData()};
+		if(CdmDataTransfer.getInstance().isSupportedType(event.dataType)){
+			event.data = cdmBaseObjects;
+		}
+	}
+
+	/** {@inheritDoc} */
+	@Override
+	public void dragStart(DragSourceEvent event) {
+		event.doit = container.getData() != null;
+	}
+}
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/dnd/NameEditorDropTargetListenerE4.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/dnd/NameEditorDropTargetListenerE4.java
index dd072747f..d131550db 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/dnd/NameEditorDropTargetListenerE4.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/dnd/NameEditorDropTargetListenerE4.java
@@ -10,13 +10,21 @@ import org.eclipse.swt.dnd.DropTargetEvent;
 
 import eu.etaxonomy.cdm.model.common.ICdmBase;
 import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
+import eu.etaxonomy.cdm.model.taxon.Synonym;
+import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
-import eu.etaxonomy.taxeditor.editor.EditorUtil;
+import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
 import eu.etaxonomy.taxeditor.editor.l10n.Messages;
-import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
-import eu.etaxonomy.taxeditor.editor.name.container.AbstractHomotypicalGroupContainer;
 import eu.etaxonomy.taxeditor.editor.name.e4.IDropTargetableE4;
 import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
+import eu.etaxonomy.taxeditor.editor.name.e4.container.AbstractHomotypicalGroupContainerE4;
+import eu.etaxonomy.taxeditor.editor.name.e4.container.MisappliedGroupE4;
+import eu.etaxonomy.taxeditor.editor.name.operation.ChangeConceptRelationshipTypeOperation;
+import eu.etaxonomy.taxeditor.editor.name.operation.ChangeConceptToSynonymOperation;
+import eu.etaxonomy.taxeditor.editor.name.operation.ChangeHomotypicGroupOperation;
+import eu.etaxonomy.taxeditor.editor.name.operation.ChangeSynonymToMisapplicationOperation;
+import eu.etaxonomy.taxeditor.editor.name.operation.MoveSynonymToAnotherAcceptedTaxonOperation;
+import eu.etaxonomy.taxeditor.event.EventUtility;
 import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
@@ -72,9 +80,9 @@ public class NameEditorDropTargetListenerE4 extends DropTargetAdapter {
 			AbstractUtility.executeOperation(operation);
 		}
 		target.getEditor().getConversationHolder().commit();
-		if (!target.equals(EditorUtil.getActiveMultiPageTaxonEditor().getActiveEditor())){
-			((TaxonNameEditor)EditorUtil.getActiveMultiPageTaxonEditor().getActiveEditor()).redraw();
-			((TaxonNameEditor)EditorUtil.getActiveMultiPageTaxonEditor().getActiveEditor()).getConversationHolder().commit();
+		if (!target.equals(EventUtility.getEditor())){
+			((TaxonNameEditorE4)EventUtility.getEditor()).redraw();
+			((TaxonNameEditorE4)EventUtility.getEditor()).getConversationHolder().commit();
 
 		}
 		target.getEditor().redraw();
@@ -83,48 +91,46 @@ public class NameEditorDropTargetListenerE4 extends DropTargetAdapter {
 
 	private AbstractPostOperation createOperation(TaxonBase taxonBase) {
 
-	    //FIXME E4 migrate dnd
-
-//		if(taxonBase instanceof Synonym){
-//			Synonym synonym = (Synonym) taxonBase;
-//
-//			if(target instanceof AbstractHomotypicalGroupContainer){
-//				HomotypicalGroup homotypicalGroup = ((AbstractHomotypicalGroupContainer) target).getGroup();
-//
-//				return new ChangeHomotypicGroupOperation(Messages.NameEditorDropTargetListener_CHANGE_HOMOTYPICAL_GROUP, getEditor().getUndoContext(),
-//						getEditor().getTaxon(), synonym, homotypicalGroup, target);
-//			}
-//			else if(target instanceof MisappliedGroup){
-//				return new ChangeSynonymToMisapplicationOperation(Messages.NameEditorDropTargetListener_CHANGE_SYNONYM_TO_MISAPP, getEditor().getUndoContext(),
-//						getEditor().getTaxon(), synonym, target);
-//			}
-//			else if(target instanceof TaxonNameEditor){
-//				if (target.equals(getEditor())){
-//					return new ChangeHomotypicGroupOperation(Messages.NameEditorDropTargetListener_CHANGE_HOMOTYPICAL_GROUP, getEditor().getUndoContext(),
-//						getEditor().getTaxon(), synonym, null, target);
-//				} else{
-//					getEditor().getConversationHolder().commit();
-//					((TaxonNameEditor) target).getConversationHolder().commit();
-//
-//					return new MoveSynonymToAnotherAcceptedTaxonOperation(Messages.NameEditorDropTargetListener_CHANGE_ACC_TAXON, getEditor().getUndoContext(), getEditor().getTaxon().getUuid(), synonym.getUuid(), ((TaxonNameEditor) target).getTaxon(), null );
-//
-//				}
-//			}
-//
-//		}else if(taxonBase instanceof Taxon){
-//			Taxon concept = (Taxon) taxonBase;
-//
-//			if(target instanceof AbstractHomotypicalGroupContainer){
-//				HomotypicalGroup homotypicalGroup = ((AbstractHomotypicalGroupContainer) target).getGroup();
-//
-//				return new ChangeConceptToSynonymOperation(Messages.NameEditorDropTargetListener_CHANGE_SYNONYM, getEditor().getUndoContext(),
-//						getEditor().getTaxon(), concept, homotypicalGroup, target);
-//			}
-//			else if(target instanceof MisappliedGroup ){
-//				return new ChangeConceptRelationshipTypeOperation(Messages.NameEditorDropTargetListener_CHANGE, getEditor().getUndoContext(),
-//						getEditor().getTaxon(), concept, TaxonRelationshipType.MISAPPLIED_NAME_FOR(), target);
-//			}
-//		}
+		if(taxonBase instanceof Synonym){
+			Synonym synonym = (Synonym) taxonBase;
+
+			if(target instanceof AbstractHomotypicalGroupContainerE4){
+				HomotypicalGroup homotypicalGroup = ((AbstractHomotypicalGroupContainerE4) target).getGroup();
+
+				return new ChangeHomotypicGroupOperation(Messages.NameEditorDropTargetListener_CHANGE_HOMOTYPICAL_GROUP, getEditor().getUndoContext(),
+						getEditor().getTaxon(), synonym, homotypicalGroup, target);
+			}
+			else if(target instanceof MisappliedGroupE4){
+				return new ChangeSynonymToMisapplicationOperation(Messages.NameEditorDropTargetListener_CHANGE_SYNONYM_TO_MISAPP, getEditor().getUndoContext(),
+						getEditor().getTaxon(), synonym, target);
+			}
+			else if(target instanceof TaxonNameEditorE4){
+				if (target.equals(getEditor())){
+					return new ChangeHomotypicGroupOperation(Messages.NameEditorDropTargetListener_CHANGE_HOMOTYPICAL_GROUP, getEditor().getUndoContext(),
+						getEditor().getTaxon(), synonym, null, target);
+				} else{
+					getEditor().getConversationHolder().commit();
+					((TaxonNameEditorE4) target).getConversationHolder().commit();
+
+					return new MoveSynonymToAnotherAcceptedTaxonOperation(Messages.NameEditorDropTargetListener_CHANGE_ACC_TAXON, getEditor().getUndoContext(), getEditor().getTaxon().getUuid(), synonym.getUuid(), ((TaxonNameEditorE4) target).getTaxon(), null );
+
+				}
+			}
+
+		}else if(taxonBase instanceof Taxon){
+			Taxon concept = (Taxon) taxonBase;
+
+			if(target instanceof AbstractHomotypicalGroupContainerE4){
+				HomotypicalGroup homotypicalGroup = ((AbstractHomotypicalGroupContainerE4) target).getGroup();
+
+				return new ChangeConceptToSynonymOperation(Messages.NameEditorDropTargetListener_CHANGE_SYNONYM, getEditor().getUndoContext(),
+						getEditor().getTaxon(), concept, homotypicalGroup, target);
+			}
+			else if(target instanceof MisappliedGroupE4){
+				return new ChangeConceptRelationshipTypeOperation(Messages.NameEditorDropTargetListener_CHANGE, getEditor().getUndoContext(),
+						getEditor().getTaxon(), concept, TaxonRelationshipType.MISAPPLIED_NAME_FOR(), target);
+			}
+		}
 
 
 		return null;
@@ -138,8 +144,8 @@ public class NameEditorDropTargetListenerE4 extends DropTargetAdapter {
 
 
 	private HomotypicalGroup getHomotypicalGroup() {
-		if(target instanceof AbstractHomotypicalGroupContainer){
-			return ((AbstractHomotypicalGroupContainer) target).getGroup();
+		if(target instanceof AbstractHomotypicalGroupContainerE4){
+			return ((AbstractHomotypicalGroupContainerE4) target).getGroup();
 		}
 		return null;
 	}
@@ -157,6 +163,6 @@ public class NameEditorDropTargetListenerE4 extends DropTargetAdapter {
 	}
 
 	private TaxonNameEditorE4 getEditor() {
-		return (TaxonNameEditorE4) EditorUtil.getActiveMultiPageTaxonEditor().getActiveEditor();
+		return (TaxonNameEditorE4) EventUtility.getEditor();
 	}
 }
