Correct merge
authorCherian Mathew <c.mathew@bgbm.org>
Thu, 3 Sep 2015 15:42:47 +0000 (17:42 +0200)
committerCherian Mathew <c.mathew@bgbm.org>
Thu, 3 Sep 2015 15:42:47 +0000 (17:42 +0200)
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/DeleteOperation.java

index 5e78bd2ddb6ff8da75c17075ec28f1443afec236..a2fea97595d44cac993dbb5498591d26fc726f81 100644 (file)
@@ -1,16 +1,18 @@
 // $Id$
 /**
-* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
-* 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.
-*/
+ * Copyright (C) 2007 EDIT
+ * European Distributed Institute of Taxonomy
+ * 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.
+ */
 
 package eu.etaxonomy.taxeditor.navigation.navigator.operation;
 
+import java.util.HashSet;
 import java.util.Set;
+import java.util.UUID;
 
 import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.core.commands.operations.IUndoContext;
@@ -29,9 +31,9 @@ import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.taxon.Classification;
 import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
-import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.operation.AbstractPersistentPostOperation;
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
+import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 
 /**
@@ -43,45 +45,51 @@ import eu.etaxonomy.taxeditor.store.CdmStore;
  */
 public class DeleteOperation extends AbstractPersistentPostOperation{
 
-       private Set<ITaxonTreeNode> treeNodes;
-       protected final TaxonDeletionConfigurator config;
+    private Set<ITaxonTreeNode> treeNodes;
+    protected final TaxonDeletionConfigurator config;
+    private final ICdmEntitySessionEnabled cdmEntitySessionEnabled;
+
+    /**
+     * <p>Constructor for DeleteTreeNodeOperation.</p>
+     *
+     * @param label a {@link java.lang.String} object.
+     * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
+     * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
+     * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
+     * @param treeNodes a {@link java.util.Set} object.
+     */
+    public DeleteOperation(String label, IUndoContext undoContext,
+            ITaxonTreeNode taxonNode, TaxonDeletionConfigurator config,
+            IPostOperationEnabled postOperationEnabled,
+            IConversationEnabled conversationEnabled,
+            ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
+        super(label, undoContext, postOperationEnabled, conversationEnabled, cdmEntitySessionEnabled);
+        this.taxonNode = (ITaxonTreeNode)CdmBase.deproxy(taxonNode, CdmBase.class);
+        this.config = config;
+        this.cdmEntitySessionEnabled = cdmEntitySessionEnabled;
+    }
+
+    /**
+     * <p>Constructor for DeleteTreeNodeOperation.</p>
+     *
+     * @param label a {@link java.lang.String} object.
+     * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
+     * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
+     * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
+     * @param treeNodes a {@link java.util.Set} object.
+     */
+    public DeleteOperation(String label, IUndoContext undoContext,
+            Set<ITaxonTreeNode> treeNodes, TaxonDeletionConfigurator config,
+            IPostOperationEnabled postOperationEnabled,
+            IConversationEnabled conversationEnabled,
+            ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
+        super(label, undoContext, postOperationEnabled, conversationEnabled, cdmEntitySessionEnabled);
+        this.treeNodes = treeNodes;
+        this.config = config;
+        this.cdmEntitySessionEnabled = cdmEntitySessionEnabled;
+    }
 
 
-       /**
-        * <p>Constructor for DeleteTreeNodeOperation.</p>
-        *
-        * @param label a {@link java.lang.String} object.
-        * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
-        * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
-        * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
-        * @param treeNodes a {@link java.util.Set} object.
-        */
-       public DeleteOperation(String label, IUndoContext undoContext,
-                       ITaxonTreeNode taxonNode, TaxonDeletionConfigurator config,
-                       IPostOperationEnabled postOperationEnabled,
-                       IConversationEnabled conversationEnabled) {
-               super(label, undoContext, postOperationEnabled, conversationEnabled);
-               this.taxonNode = (ITaxonTreeNode)CdmBase.deproxy(taxonNode, CdmBase.class);
-               this.config = config;
-       }
-
-       /**
-        * <p>Constructor for DeleteTreeNodeOperation.</p>
-        *
-        * @param label a {@link java.lang.String} object.
-        * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
-        * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
-        * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
-        * @param treeNodes a {@link java.util.Set} object.
-        */
-       public DeleteOperation(String label, IUndoContext undoContext,
-                       Set<ITaxonTreeNode> treeNodes, TaxonDeletionConfigurator config,
-                       IPostOperationEnabled postOperationEnabled,
-                       IConversationEnabled conversationEnabled) {
-               super(label, undoContext, postOperationEnabled, conversationEnabled);
-               this.treeNodes = treeNodes;
-               this.config = config;
-       }
 
 
        /* (non-Javadoc)
@@ -108,76 +116,61 @@ public class DeleteOperation extends AbstractPersistentPostOperation{
                                } else if (!result.getExceptions().isEmpty()){
                                        String separator = ", ";
                                    String exceptionString = "";
-                                   int count = 1;
                                    for (Exception exception : result.getExceptions()) {
-                                       exceptionString += exception.getLocalizedMessage();
-                                       if (count < result.getExceptions().size()){
-                                           exceptionString += separator;
-                                       }
+                                   exceptionString += exception.getLocalizedMessage()+separator;
                                }
-                                       MessagingUtils.informationDialog("Delete of the node was successful but the taxon could not be deleted.", exceptionString);
+                                       MessageDialog.openInformation(null, "Delete of the node was successful but the taxon could not be deleted.", exceptionString);
                                }
 
 
                        }else if(taxonNode != null && taxonNode instanceof Classification){
                                Classification taxonomicTree = (Classification) taxonNode;
-                               /*if(taxonomicTree.hasChildNodes()){
-                                       if(! MessageDialog.openConfirm(null, "Confirm Deletion", "The selected tree has children, do yu realy want to delete the whole tree with its children?")){
-                                               return null;
-                                       }
-                               }*/
 
-                               DeleteResult result = CdmStore.getService(IClassificationService.class).delete(taxonomicTree);
-                               if (result.isError() && !result.getExceptions().isEmpty()){
-                                   String separator = ", ";
-                    String exceptionString = "";
-                    for (Exception exception : result.getExceptions()) {
-                        exceptionString += exception.getLocalizedMessage()+separator;
-                    }
-                                   MessagingUtils.error(null, exceptionString, result.getExceptions().iterator().next());
-                               }
-
-                               /*}else{
-                                       try{
-                                       CdmStore.getService(IClassificationService.class).delete(taxonomicTree);
-                                       }catch(ReferencedObjectUndeletableException e){
-                                               throw new ExecutionException(e.getMessage());
-                                       }
-                               }*/
-                       } else {
-
-                               DeleteResult result =service.deleteTaxonNodes(treeNodes, config);
-                               if (result.isError() && !result.getExceptions().isEmpty()){
-                                   String separator = ", ";
-                    String exceptionString = "";
-                    for (Exception exception : result.getExceptions()) {
-                        exceptionString += exception.getLocalizedMessage()+separator;
-                    }
-                    MessagingUtils.error(null, exceptionString, result.getExceptions().iterator().next());
-                               }
+                               DeleteResult result = CdmStore.getService(IClassificationService.class).delete(taxonomicTree.getUuid());
+                if (result.isError() && !result.getExceptions().isEmpty()){
+                    //TODO:Error message!
+                    MessageDialog.openError(null, "Delete failed", result.getExceptions().iterator().next().getMessage());
+                }
+        } else {
+            Set<UUID> treeNodeUuids = new HashSet<UUID>();
+            ITaxonTreeNode entity = null;
+            for(ITaxonTreeNode treeNode : treeNodes) {
+                if(entity == null) {
+                    entity = treeNode;
+                }
+                treeNodeUuids.add(treeNode.getUuid());
+            }
+
+            DeleteResult result = service.deleteTaxonNodes(treeNodeUuids, config);
+            if (result.isError() && !result.getExceptions().isEmpty()){
+                               //TODO:Error message!
+                               MessageDialog.openError(null, "Delete failed", result.getExceptions().iterator().next().getMessage());
                        }
 
-               monitor.worked(40);
-               return postExecute(null);
-       }
-
-       /* (non-Javadoc)
-        * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
-        */
-       /** {@inheritDoc} */
-       @Override
-       public IStatus redo(IProgressMonitor monitor, IAdaptable info)
-                       throws ExecutionException {
-               return null;
-       }
-
-       /* (non-Javadoc)
-        * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
-        */
-       /** {@inheritDoc} */
-       @Override
-       public IStatus undo(IProgressMonitor monitor, IAdaptable info)
-                       throws ExecutionException {
-               return null;
-       }
+        }
+
+        monitor.worked(40);
+
+        return postExecute(null);
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
+     */
+    /** {@inheritDoc} */
+    @Override
+    public IStatus redo(IProgressMonitor monitor, IAdaptable info)
+            throws ExecutionException {
+        return null;
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
+     */
+    /** {@inheritDoc} */
+    @Override
+    public IStatus undo(IProgressMonitor monitor, IAdaptable info)
+            throws ExecutionException {
+        return null;
+    }
 }