Fix potential NPE
[taxeditor.git] / eu.etaxonomy.taxeditor.navigation / src / main / java / eu / etaxonomy / taxeditor / navigation / navigator / operation / ChangeAcceptedTaxonToSynonymOperation.java
index 9d0ca887261d2c9fc807960fdea9a3f315fe3d96..adc2d45ac6f440d95b511b3b105d4e3819058b72 100644 (file)
@@ -1,4 +1,3 @@
-// $Id$
 /**
 * Copyright (C) 2007 EDIT
 * European Distributed Institute of Taxonomy
@@ -16,10 +15,8 @@ import org.eclipse.core.runtime.IAdaptable;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
-import org.eclipse.jface.dialogs.MessageDialog;
 
 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
-import eu.etaxonomy.cdm.api.service.DeleteResult;
 import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
 import eu.etaxonomy.cdm.api.service.UpdateResult;
 import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
@@ -29,6 +26,7 @@ import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.navigation.internal.TaxeditorNavigationPlugin;
+import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
 import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
 import eu.etaxonomy.taxeditor.store.CdmStore;
@@ -83,27 +81,35 @@ public class ChangeAcceptedTaxonToSynonymOperation extends
                monitor.worked(20);
                bind();
 
-       Taxon oldTaxon = (Taxon) HibernateProxyHelper.deproxy(((TaxonNode) taxonNode).getTaxon());
-               try {
+       Taxon oldTaxon = HibernateProxyHelper.deproxy(((TaxonNode) taxonNode).getTaxon(), Taxon.class);
+       Taxon newAcceptedTaxon = HibernateProxyHelper.deproxy(newAcceptedTaxonNode.getTaxon(), Taxon.class);
 
+               try {
                    UpdateResult result = CdmStore.getService(ITaxonNodeService.class).makeTaxonNodeASynonymOfAnotherTaxonNode(taxonNode.getUuid(), newAcceptedTaxonNode.getUuid(), null, null, null);
-      
+
+
                    if (!result.getExceptions().isEmpty() && result.isOk()){
-                       String separator = ", ";
-                           String exceptionString = "";
+                       String separator = ", "; //$NON-NLS-1$
+                           String exceptionString = ""; //$NON-NLS-1$
+                           int count = result.getExceptions().size();
+                           int n = 0;
                            for (Exception exception : result.getExceptions()) {
-                           exceptionString += exception.getLocalizedMessage()+separator;
+                               n++;
+                           exceptionString += exception.getLocalizedMessage();
+                           if (n<count){
+                               exceptionString += separator;
+                           }
                        }
-                               
-                       MessagingUtils.informationDialog("Synonym created but taxon is not deleted.", exceptionString);                 
+
+                       MessagingUtils.informationDialog(Messages.ChangeAcceptedTaxonToSynonymOperation_CREATE_SUCCESS, exceptionString);
                    } else if (result.isAbort() || result.isError()){
-                       MessagingUtils.errorDialog("Synonym could not created", null, result.toString(), TaxeditorNavigationPlugin.PLUGIN_ID, null, true);
+                       MessagingUtils.errorDialog(Messages.ChangeAcceptedTaxonToSynonymOperation_CREATE_FAIL, null, result.toString(), TaxeditorNavigationPlugin.PLUGIN_ID, null, true);
                    }
                } catch (IllegalArgumentException e) {
-            MessagingUtils.errorDialog("Operation failed", this, e.getMessage(), TaxeditorNavigationPlugin.PLUGIN_ID, e, false);
+            MessagingUtils.errorDialog(Messages.ChangeAcceptedTaxonToSynonymOperation_OP_FAIL, this, e.getMessage(), TaxeditorNavigationPlugin.PLUGIN_ID, e, false);
             return Status.CANCEL_STATUS;
         }
-               
+
                monitor.worked(40);
 
                return postExecute(oldTaxon);