- fixed exception when changing accepted taxon to synonym of itself
authorPatric Plitzner <p.plitzner@bgbm.org>
Thu, 9 Apr 2015 21:17:58 +0000 (21:17 +0000)
committerPatric Plitzner <p.plitzner@bgbm.org>
Thu, 9 Apr 2015 21:17:58 +0000 (21:17 +0000)
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/ChangeAcceptedTaxonToSynonymOperation.java

index 697b46af520e0697663f098e3813bbfac6d06a42..4dd1c61dbf3a5e01904d92a7aefe610d489afe79 100644 (file)
@@ -1,9 +1,9 @@
 // $Id$
 /**
 * Copyright (C) 2007 EDIT
 // $Id$
 /**
 * Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy 
+* European Distributed Institute of Taxonomy
 * http://www.e-taxonomy.eu
 * http://www.e-taxonomy.eu
-* 
+*
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * See LICENSE.TXT at the top of this package for the full license terms.
 */
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * See LICENSE.TXT at the top of this package for the full license terms.
 */
@@ -15,18 +15,17 @@ import org.eclipse.core.commands.operations.IUndoContext;
 import org.eclipse.core.runtime.IAdaptable;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
 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 eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
 import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
 import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
 
 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
 import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
 import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
-import eu.etaxonomy.cdm.api.service.exception.DataChangeNoRollbackException;
 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
-import eu.etaxonomy.cdm.model.common.ITreeNode;
 import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
 import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
-import eu.etaxonomy.cdm.model.taxon.Synonym;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
-import eu.etaxonomy.taxeditor.operation.AbstractPersistentPostOperation;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.navigation.internal.TaxeditorNavigationPlugin;
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 
@@ -39,11 +38,11 @@ import eu.etaxonomy.taxeditor.store.CdmStore;
  */
 public class ChangeAcceptedTaxonToSynonymOperation extends
        DeleteOperation {
  */
 public class ChangeAcceptedTaxonToSynonymOperation extends
        DeleteOperation {
-       
-       private TaxonNode newAcceptedTaxonNode;
+
+       private final TaxonNode newAcceptedTaxonNode;
 
        //private TaxonNode oldTaxonNode;
 
        //private TaxonNode oldTaxonNode;
-       
+
        /**
         * <p>Constructor for ChangeAcceptedTaxonToSynonymOperation.</p>
         *
        /**
         * <p>Constructor for ChangeAcceptedTaxonToSynonymOperation.</p>
         *
@@ -72,13 +71,16 @@ public class ChangeAcceptedTaxonToSynonymOperation extends
 
                monitor.worked(20);
                bind();
 
                monitor.worked(20);
                bind();
-       Synonym synonym = null;
        Taxon oldTaxon = (Taxon) HibernateProxyHelper.deproxy(((TaxonNode) taxonNode).getTaxon());
        Taxon oldTaxon = (Taxon) HibernateProxyHelper.deproxy(((TaxonNode) taxonNode).getTaxon());
-               
-               synonym = CdmStore.getService(ITaxonNodeService.class).makeTaxonNodeASynonymOfAnotherTaxonNode((TaxonNode) taxonNode, newAcceptedTaxonNode, null, null, null);
-               
+               try {
+                   CdmStore.getService(ITaxonNodeService.class).makeTaxonNodeASynonymOfAnotherTaxonNode((TaxonNode) taxonNode, newAcceptedTaxonNode, null, null, null);
+        } catch (IllegalArgumentException e) {
+            MessagingUtils.errorDialog("Operation failed", this, e.getMessage(), TaxeditorNavigationPlugin.PLUGIN_ID, e, false);
+            return Status.CANCEL_STATUS;
+        }
+
                monitor.worked(40);
                monitor.worked(40);
-        
+
                return postExecute(oldTaxon);
        }
 
                return postExecute(oldTaxon);
        }