commit 733c1cfb1fe804d50ade82a84cdfc281e1d4f863
Author: Katja Luther <k.luther@bgbm.org>
Date:   Fri Sep 7 12:51:58 2018 +0200

    ref #3535: add check for dirty target when move description or description elements

diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorUtil.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorUtil.java
index 12f2adf94..35cb4040b 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorUtil.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorUtil.java
@@ -163,6 +163,24 @@ public class EditorUtil extends AbstractUtility {
         editor.init(input);
     }
 
+    public static MPart checkForChanges(UUID taxonUUID, EPartService partService ){
+        Collection<MPart> parts = partService.getParts();
+        //check if part is already opened
+        boolean isDirty = false;
+        for (MPart part : parts) {
+            if(part.getObject() instanceof TaxonNameEditorE4
+                    && ((TaxonNameEditorE4) part.getObject()).getTaxon()!=null
+                    && ((TaxonNameEditorE4) part.getObject()).getTaxon().getUuid().equals(taxonUUID)){
+                if (part.isDirty()){
+                    return part;
+                }
+
+                break;
+            }
+        }
+        return null;
+    }
+
 	/**
 	 * An uninitialized taxon is one that hasn't been saved yet. As such, it
 	 * should appear in neither the list of recent names nor in the taxonomic
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/e4/handler/MoveDescriptionElementsHandlerE4.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/e4/handler/MoveDescriptionElementsHandlerE4.java
index 1fadf38dc..4478aa631 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/e4/handler/MoveDescriptionElementsHandlerE4.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/e4/handler/MoveDescriptionElementsHandlerE4.java
@@ -155,6 +155,18 @@ public class MoveDescriptionElementsHandlerE4 implements IPostOperationEnabled{
             }
             newAcceptedTaxonNodeUuid = newAcceptedTaxonNode.getUuid();
 
+            MPart targetEditor = EditorUtil.checkForChanges(targetTaxon.getUuid(), partService);
+            if (targetEditor != null && targetEditor.getElementId().equals("eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4")){
+                boolean proceed = MessageDialog.openQuestion(null,
+                        Messages.MoveDescriptionToOtherTaxonHandler_SAVE_CHANGES, Messages.MoveDescriptionToOtherTaxonHandler_SAVE_CHANGES_MESSAGE);
+                if (proceed) {
+                    e4WrappedPart = WorkbenchUtility.getE4WrappedPart(targetEditor);
+                    ((TaxonNameEditorE4)e4WrappedPart).save(AbstractUtility.getMonitor());
+                } else {
+                    return;
+                }
+            }
+
             String moveMessage = String.format(Messages.MoveDescriptionElementsHandler_ELEMENTS_MOVED, editor.getTaxon());
 
             AbstractPostOperation operation = new MoveDescriptionElementsOperation(
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/e4/handler/MoveDescriptionToOtherTaxonHandlerE4.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/e4/handler/MoveDescriptionToOtherTaxonHandlerE4.java
index 091b7ae17..0a1c0fa56 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/e4/handler/MoveDescriptionToOtherTaxonHandlerE4.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/e4/handler/MoveDescriptionToOtherTaxonHandlerE4.java
@@ -130,6 +130,17 @@ public class MoveDescriptionToOtherTaxonHandlerE4 implements IPostOperationEnabl
 
         newAcceptedTaxonNodeUuid = newAcceptedTaxonNode.getUuid();
         newAcceptedTaxonUuid = newAcceptedTaxonNode.getTaxon().getUuid();
+
+        MPart targetEditor = EditorUtil.checkForChanges(newAcceptedTaxonUuid, partService);
+        if (targetEditor != null && targetEditor instanceof TaxonNameEditorE4){
+            boolean proceed = MessageDialog.openQuestion(null,
+                    Messages.MoveDescriptionToOtherTaxonHandler_SAVE_CHANGES, Messages.MoveDescriptionToOtherTaxonHandler_SAVE_CHANGES_MESSAGE);
+            if (proceed) {
+                ((TaxonNameEditorE4)targetEditor).save(AbstractUtility.getMonitor());
+            } else {
+                return;
+            }
+        }
         for(TaxonDescription taxonDescription : descriptions){
             operation = new MoveDescriptionToOtherTaxonOperation(menuItem.getLocalizedLabel(),
                     editor.getUndoContext(),
