commit 4aa3c52a4e3b60a495ddebf031bef3de40ffcb7d
Author: Katja Luther <k.luther@bgbm.org>
Date:   Fri Jan 12 11:58:03 2018 +0100

    improve name editor update for navigator operations

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 2d7b0015e..b97f2ab04 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
@@ -323,8 +323,12 @@ public class EditorUtil extends AbstractUtility {
             if(object instanceof TaxonNameEditorE4){
                 TaxonNameEditorE4 taxonEditor = (TaxonNameEditorE4)object;
                 TaxonNode node = taxonEditor.getEditorInput().getTaxonNode();
-                if(node.treeIndex().startsWith(treeIndex)){
-                    partService.hidePart(part, true);
+                if (node.treeIndex()!= null){
+	                if(node.treeIndex().startsWith(treeIndex)){
+	                    partService.hidePart(part, true);
+	                }
+                }else{
+                	logger.debug("The taxonnode of taxon " + node.getTaxon().getTitleCache() + " uuid: " + node.getUuid() + " has no treeindex");;
                 }
             }
         }
diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/l10n/Messages.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/l10n/Messages.java
index 20894c911..885c0ea75 100644
--- a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/l10n/Messages.java
+++ b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/l10n/Messages.java
@@ -41,6 +41,7 @@ public class Messages extends NLS {
     public static String DeleteHandler_DELETE_ALL;
     public static String DeleteHandler_DELETE_CLASSIFICATION;
     public static String DeleteHandler_DELETE_NODE;
+    public static String DeleteHandler_DELETE_NODES;
     public static String DeleteHandler_MOVE_TO_PARENT;
     public static String DeleteHandler_SKIP;
     public static String DeleteHandler_DELETE;
@@ -181,6 +182,7 @@ public class Messages extends NLS {
     public static String TaxonNavigatorLabels_SET_PUBLISH_FOR_CHILDREN;
 	public static String TaxonNavigatorLabels_ACCEPTED_TAXA_NEED_TO_BE_FROM_SAME_CLASSIFICATION;
 	
+	
 
 
     static {
diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/l10n/messages.properties b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/l10n/messages.properties
index c2e1c0b4e..f229f72f6 100644
--- a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/l10n/messages.properties
+++ b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/l10n/messages.properties
@@ -21,7 +21,8 @@ DeleteHandler_CONFIRM_DELETE=Confirm Deletion
 DeleteHandler_CONFIRM_MESSAGE=Do you want to delete the selected key(s)?
 DeleteHandler_DELETE_ALL=Delete all children
 DeleteHandler_DELETE_CLASSIFICATION=Do you really want to delete the classification?
-DeleteHandler_DELETE_NODE=Do you really want to delete the selected node(s)?
+DeleteHandler_DELETE_NODE=Do you really want to delete the selected node?
+DeleteHandler_DELETE_NODES=Do you really want to delete the selected nodes?
 DeleteHandler_MOVE_TO_PARENT=Move children to parent node
 DeleteHandler_SKIP=Cancel
 DeleteHandler_DELETE=Delete
diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/l10n/messages_de.properties b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/l10n/messages_de.properties
index cf3178cd8..80f97f2dd 100644
--- a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/l10n/messages_de.properties
+++ b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/l10n/messages_de.properties
@@ -21,7 +21,8 @@ DeleteHandler_CONFIRM_DELETE=L
 DeleteHandler_CONFIRM_MESSAGE=Wollen wie Sie die ausgewählten Schlüssen löschen?
 DeleteHandler_DELETE_ALL=Alle Kinder löschen
 DeleteHandler_DELETE_CLASSIFICATION=Wollen Sie die Klassifikation wirklich löschen?
-DeleteHandler_DELETE_NODE=Wollen Sie die ausgewählten Knoten wirklich löschen?
+DeleteHandler_DELETE_NODE=Wollen Sie den ausgewählten Knoten wirklich löschen?
+DeleteHandler_DELETE_NODES=Wollen Sie die ausgewählten Knoten wirklich löschen?
 DeleteHandler_MOVE_TO_PARENT=Verschiebe Kinder zu Elternknoten
 DeleteHandler_SKIP=Abbrechen
 DeleteHandler_DELETE=Löschen
diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/e4/handler/DeleteHandlerE4.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/e4/handler/DeleteHandlerE4.java
index aebbf15b3..cc31ef384 100644
--- a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/e4/handler/DeleteHandlerE4.java
+++ b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/e4/handler/DeleteHandlerE4.java
@@ -53,7 +53,8 @@ public class DeleteHandlerE4 {
     protected static final String DELETE_ALL_CHILDREN = Messages.DeleteHandler_DELETE_ALL;
     protected static final String THERE_ARE_CHILDNODES_WHICH_WILL_BE_DELETED_TOO = Messages.DeleteHandler_THERE_ARE_CHILDNODES;
     protected static final String THE_TREE_HAS_CHILDREN_THEY_WILL_BE_DELETED_TOO = Messages.DeleteHandler_THERE_ARE_CHILDREN;
-    protected static final String DO_YOU_REALLY_WANT_TO_DELETE_THE_SELECTED_NODE_S = Messages.DeleteHandler_DELETE_NODE;
+    protected static final String DO_YOU_REALLY_WANT_TO_DELETE_THE_SELECTED_NODE_S = Messages.DeleteHandler_DELETE_NODES;
+    protected static final String DO_YOU_REALLY_WANT_TO_DELETE_THE_SELECTED_NODE = Messages.DeleteHandler_DELETE_NODE;
     protected static final String DO_YOU_REALLY_WANT_TO_DELETE_THE_CLASSIFICATION = Messages.DeleteHandler_DELETE_CLASSIFICATION;
     protected static final String CONFIRM_DELETION = Messages.DeleteHandler_CONFIRM_DELETE;
     protected static final String DELETE = Messages.DeleteHandler_DELETE;
diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/e4/handler/RemotingChangeAcceptedTaxonToSynonymHandlerE4.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/e4/handler/RemotingChangeAcceptedTaxonToSynonymHandlerE4.java
index 26633e3d4..2e7cf24d1 100644
--- a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/e4/handler/RemotingChangeAcceptedTaxonToSynonymHandlerE4.java
+++ b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/e4/handler/RemotingChangeAcceptedTaxonToSynonymHandlerE4.java
@@ -23,6 +23,7 @@ import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.TreeSelection;
 import org.eclipse.swt.widgets.Shell;
 
+import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
 import eu.etaxonomy.cdm.model.taxon.Classification;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
 import eu.etaxonomy.taxeditor.editor.EditorUtil;
@@ -69,13 +70,16 @@ public class RemotingChangeAcceptedTaxonToSynonymHandlerE4 extends RemotingCdmHa
 
         // check that selected object is a taxon node
         Iterator it = selection.iterator();
+        Classification nextClassification;
+        oldTaxonNodes = new HashSet<>();
         while(it.hasNext()){
         	Object obj = it.next();
-	        if(obj instanceof TaxonNode && ((TaxonNode)obj).hasTaxon()) {
+        	if(obj instanceof TaxonNode && ((TaxonNode)obj).hasTaxon()) {
 	            oldTaxonNodes.add((TaxonNode)obj);
+	            nextClassification = HibernateProxyHelper.deproxy(((TaxonNode)obj).getClassification(), Classification.class);
 	            if (classification == null){
-	            	classification = ((TaxonNode)obj).getClassification();
-	            }else if (classification != ((TaxonNode)obj).getClassification()){
+	            	classification = nextClassification;
+	            }else if (!classification.equals(nextClassification)){
 	            	return new Status(IStatus.ERROR,
 	                        "unknown", //$NON-NLS-1$
 	                        TaxonNavigatorLabels.ACCEPTED_TAXA_NEED_TO_BE_FROM_SAME_CLASSIFICATION);
@@ -131,7 +135,7 @@ public class RemotingChangeAcceptedTaxonToSynonymHandlerE4 extends RemotingCdmHa
                 new RemotingChangeAcceptedTaxonToSynonymOperation(getTrigger(),
                         false,
                         nodeUuids,
-                        newAcceptedTaxonNode.getUuid());
+                        newAcceptedTaxonNode.getUuid(), partService, activePart, application);
 
         return rcattso;
     }
diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/RemotingChangeAcceptedTaxonToSynonymOperation.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/RemotingChangeAcceptedTaxonToSynonymOperation.java
index cf3b979fc..d1ecb132d 100644
--- a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/RemotingChangeAcceptedTaxonToSynonymOperation.java
+++ b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/RemotingChangeAcceptedTaxonToSynonymOperation.java
@@ -14,11 +14,19 @@ import java.util.UUID;
 
 import org.eclipse.core.runtime.IAdaptable;
 import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.e4.ui.model.application.MApplication;
+import org.eclipse.e4.ui.model.application.ui.basic.MPart;
+import org.eclipse.e4.ui.workbench.modeling.EPartService;
+import org.eclipse.swt.widgets.Display;
 
 import eu.etaxonomy.cdm.api.application.CdmApplicationState;
 import eu.etaxonomy.cdm.api.application.CdmChangeEvent.Action;
 import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
 import eu.etaxonomy.cdm.api.service.UpdateResult;
+import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.model.taxon.TaxonNode;
+import eu.etaxonomy.taxeditor.editor.EditorUtil;
+import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
 import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
 import eu.etaxonomy.taxeditor.operation.RemotingCdmUpdateOperation;
 
@@ -42,10 +50,29 @@ public class RemotingChangeAcceptedTaxonToSynonymOperation extends RemotingCdmUp
     public RemotingChangeAcceptedTaxonToSynonymOperation(Object source,
             boolean async,
             Set<UUID> oldTaxonNodeUuids,
-            UUID newAcceptedTaxonNodeUuid) {
-        super(LABEL, Action.Update, source, async);
+            UUID newAcceptedTaxonNodeUuid,
+            EPartService partService,
+            MPart activePart,
+            MApplication application) {
+        super(LABEL, Action.Update, source, async, partService, activePart, application);
         this.oldTaxonNodeUuids.addAll(oldTaxonNodeUuids);
         this.newAcceptedTaxonNodeUuid = newAcceptedTaxonNodeUuid;
+        
+    }
+    
+    /**
+     * @param label
+     */
+    public RemotingChangeAcceptedTaxonToSynonymOperation(Object source,
+            boolean async,
+            UUID oldTaxonNodeUuid,
+            UUID newAcceptedTaxonNodeUuid,
+            EPartService partService,
+    		MPart activePart,
+    		MApplication application) {
+        super(LABEL, Action.Update, source, async, partService, activePart, application);
+        this.oldTaxonNodeUuids.add(oldTaxonNodeUuid);
+        this.newAcceptedTaxonNodeUuid = newAcceptedTaxonNodeUuid;
     }
     
     /**
@@ -65,20 +92,43 @@ public class RemotingChangeAcceptedTaxonToSynonymOperation extends RemotingCdmUp
      */
     @Override
     protected UpdateResult doUpdateExecute(IProgressMonitor monitor, IAdaptable info) throws Exception {
+    	
     	if (this.oldTaxonNodeUuids.size() == 1){
-    		return CdmApplicationState.getService(ITaxonNodeService.class).makeTaxonNodeASynonymOfAnotherTaxonNode(oldTaxonNodeUuids.iterator().next(),
+    		updateResult = CdmApplicationState.getService(ITaxonNodeService.class).makeTaxonNodeASynonymOfAnotherTaxonNode(oldTaxonNodeUuids.iterator().next(),
                     newAcceptedTaxonNodeUuid,
                     null,
                     null,
                     null);
     	}else{
-    		return CdmApplicationState.getService(ITaxonNodeService.class).makeTaxonNodeSynonymsOfAnotherTaxonNode(oldTaxonNodeUuids,
+    		updateResult = CdmApplicationState.getService(ITaxonNodeService.class).makeTaxonNodeSynonymsOfAnotherTaxonNode(oldTaxonNodeUuids,
                     newAcceptedTaxonNodeUuid,
                     null,
                     null,
                     null);
     	}
+    	updateNameEditor();
+    	return updateResult;
         
     }
-
+    
+    private void updateNameEditor(){
+    	if (partService != null){
+	    Display.getDefault().asyncExec(new Runnable() {
+		    public void run() {
+		    	for (MPart part : partService.getParts()){
+					Object object = part.getObject();
+					if (object instanceof TaxonNameEditorE4){
+						Set<TaxonNode> nodes = ((TaxonNameEditorE4)object).getTaxon().getTaxonNodes();
+						for (TaxonNode node: nodes){
+							if (node.getTaxon().getUuid().equals(newAcceptedTaxonNodeUuid)){
+								EditorUtil.updateEditor(node, partService, application);										   
+							}
+								
+						}
+					}
+				} 
+		    }
+		});
+    	}
+    }
 }
diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/UpdateSubtreeOperation.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/UpdateSubtreeOperation.java
index 9fdba5ee8..85b1d53ec 100644
--- a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/UpdateSubtreeOperation.java
+++ b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/UpdateSubtreeOperation.java
@@ -32,9 +32,7 @@ public abstract class UpdateSubtreeOperation extends RemotingCdmUpdateOperation
 	ForSubtreeConfiguratorBase config;
 	
 	UUID parentUuid;
-	 EPartService partService;
-	 MPart activePart;
-	 MApplication application;
+	
 	 TaxonNode subtreeNode; 
 	 ITaxonNodeService taxonNodeService;
 	 
@@ -46,13 +44,11 @@ public abstract class UpdateSubtreeOperation extends RemotingCdmUpdateOperation
 	            MApplication application,
 	            ForSubtreeConfiguratorBase config,
 	            String label) {
-	        super(label, Action.Update, source, async);
+	        super(label, Action.Update, source, async, partService, activePart, application);
 	        parentUuid = taxonNodeUuid;
 	        this.config = config;
 	        this.updateResult = new UpdateResult();
-	        this.partService= partService;
-	        this.activePart = activePart;
-	        this.application = application;
+	       
 	        try {
 				taxonNodeService = CdmApplicationState.getService(ITaxonNodeService.class);
 			} catch (CdmApplicationException e) {
@@ -61,37 +57,37 @@ public abstract class UpdateSubtreeOperation extends RemotingCdmUpdateOperation
 			}
 	        subtreeNode = taxonNodeService.load(config.getSubtreeUuid());
 	    }
-	 
-	 public void updateNameEditors(){
-		 for (CdmBase object: updateResult.getUpdatedObjects()){
-				Taxon taxon = null;
-				TaxonNode node = null;
-				if (object instanceof Taxon){
-					taxon = HibernateProxyHelper.deproxy(object, Taxon.class);
-					node = taxon.getTaxonNode(subtreeNode.getClassification());
+	  public void updateNameEditors(){
+			 for (CdmBase object: updateResult.getUpdatedObjects()){
+					Taxon taxon = null;
+					TaxonNode node = null;
+					if (object instanceof Taxon){
+						taxon = HibernateProxyHelper.deproxy(object, Taxon.class);
+						node = taxon.getTaxonNode(subtreeNode.getClassification());
+						
+					}else if (object instanceof Synonym){
+						Synonym syn = HibernateProxyHelper.deproxy(object, Synonym.class);
+						taxon = syn.getAcceptedTaxon();
+						node = taxon.getTaxonNode(subtreeNode.getClassification());
+					}
 					
-				}else if (object instanceof Synonym){
-					Synonym syn = HibernateProxyHelper.deproxy(object, Synonym.class);
-					taxon = syn.getAcceptedTaxon();
-					node = taxon.getTaxonNode(subtreeNode.getClassification());
-				}
-				
-				Display.getDefault().asyncExec(new Runnable() {
-				    public void run() {
-				    	for (MPart part : partService.getParts()){
-							Object object = part.getObject();
-							if (object instanceof TaxonNameEditorE4){
-								Set<TaxonNode> nodes = ((TaxonNameEditorE4)object).getTaxon().getTaxonNodes();
-								for (TaxonNode node: nodes){
-									if (node.treeIndex().startsWith(subtreeNode.treeIndex())){
-										EditorUtil.updateEditor(node, partService, application);										   
+					Display.getDefault().asyncExec(new Runnable() {
+					    public void run() {
+					    	for (MPart part : partService.getParts()){
+								Object object = part.getObject();
+								if (object instanceof TaxonNameEditorE4){
+									Set<TaxonNode> nodes = ((TaxonNameEditorE4)object).getTaxon().getTaxonNodes();
+									for (TaxonNode node: nodes){
+										if (node.treeIndex().startsWith(subtreeNode.treeIndex())){
+											EditorUtil.updateEditor(node, partService, application);										   
+										}
+											
 									}
-										
 								}
-							}
-						} 
-				    }
-				});
+							} 
+					    }
+					});
+			 }
 		 }
-	 }
+	 
 }
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/operation/RemotingCdmUpdateOperation.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/operation/RemotingCdmUpdateOperation.java
index aa1a080f2..4b95767ea 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/operation/RemotingCdmUpdateOperation.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/operation/RemotingCdmUpdateOperation.java
@@ -17,9 +17,19 @@ import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.MultiStatus;
 import org.eclipse.core.runtime.Status;
+import org.eclipse.e4.ui.model.application.MApplication;
+import org.eclipse.e4.ui.model.application.ui.basic.MPart;
+import org.eclipse.e4.ui.workbench.modeling.EPartService;
+import org.eclipse.swt.widgets.Display;
 
 import eu.etaxonomy.cdm.api.application.CdmChangeEvent.Action;
 import eu.etaxonomy.cdm.api.service.UpdateResult;
+import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
+import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.model.taxon.Synonym;
+import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.cdm.model.taxon.TaxonNode;
+
 
 /**
  * @author cmathew
@@ -30,12 +40,26 @@ public abstract class RemotingCdmUpdateOperation extends RemotingCdmOperation {
 
     protected UpdateResult updateResult;
     public static boolean throwExceptions = false;
+    protected EPartService partService = null;
+    protected MPart activePart = null;
+    protected MApplication application = null;
 
     /**
      * @param label
      */
-    public RemotingCdmUpdateOperation(String label, Action action, Object source, boolean async) {
+    public RemotingCdmUpdateOperation(String label, Action action, Object source, boolean async, 
+    		EPartService partService,
+    		MPart activePart,
+    		MApplication application) {
+        super(label, action, source, async);
+        this.partService= partService;
+        this.activePart = activePart;
+        this.application = application;
+    }
+    
+    public RemotingCdmUpdateOperation(String label, Action action, Object source, boolean async){
         super(label, action, source, async);
+       
     }
 
     /* (non-Javadoc)
@@ -119,4 +143,6 @@ public abstract class RemotingCdmUpdateOperation extends RemotingCdmOperation {
         }
         return null;
     }
+    
+  
 }
