fix the deletion of media in bulk editor
[taxeditor.git] / eu.etaxonomy.taxeditor.bulkeditor / src / main / java / eu / etaxonomy / taxeditor / bulkeditor / handler / DeleteHandler.java
index 554f0a4c326416af6abab49389d4db2101b4a00a..a1b8e461cd1bb7a5bc94de7d27d59c5e50cf4dab 100644 (file)
@@ -17,12 +17,9 @@ import java.util.List;
 import org.eclipse.core.commands.AbstractHandler;
 import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.commands.common.NotDefinedException;
-import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.text.TextSelection;
-import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.IEditorPart;
@@ -31,13 +28,9 @@ import org.eclipse.ui.texteditor.IDocumentProvider;
 
 import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
 import eu.etaxonomy.cdm.api.service.DeleteResult;
-import eu.etaxonomy.cdm.api.service.IAgentService;
-import eu.etaxonomy.cdm.api.service.IGroupService;
 import eu.etaxonomy.cdm.api.service.IMediaService;
 import eu.etaxonomy.cdm.api.service.IOccurrenceService;
 import eu.etaxonomy.cdm.api.service.IReferenceService;
-import eu.etaxonomy.cdm.api.service.IUserService;
-import eu.etaxonomy.cdm.api.service.config.DeleteConfiguratorBase;
 import eu.etaxonomy.cdm.api.service.config.MediaDeletionConfigurator;
 import eu.etaxonomy.cdm.api.service.config.NameDeletionConfigurator;
 import eu.etaxonomy.cdm.api.service.config.SynonymDeletionConfigurator;
@@ -57,16 +50,9 @@ import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityPersistenceService;
 import eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotation;
 import eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotationModel;
 import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor;
-import eu.etaxonomy.taxeditor.bulkeditor.BulkEditorQuery;
-import eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorConstants;
 import eu.etaxonomy.taxeditor.bulkeditor.internal.TaxeditorBulkeditorPlugin;
-
-import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.model.DeleteResultMessagingUtils;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
-import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
-
-import eu.etaxonomy.taxeditor.operation.RemotingCdmHandler;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.ui.dialog.deleteConfigurator.DeleteConfiguratorDialog;
 
@@ -78,15 +64,15 @@ import eu.etaxonomy.taxeditor.ui.dialog.deleteConfigurator.DeleteConfiguratorDia
  */
 public class DeleteHandler extends AbstractHandler {
 
-       
-       
+
+
        /* (non-Javadoc)
         * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
         */
        @Override
        public Object execute(ExecutionEvent event) throws ExecutionException {
 
-               
+
                TextSelection selection = (TextSelection) HandlerUtil.getCurrentSelection(event);
                IEditorPart editor = HandlerUtil.getActiveEditor(event);
 
@@ -103,7 +89,7 @@ public class DeleteHandler extends AbstractHandler {
                        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
 
                        IEntityPersistenceService persistenceService = (IEntityPersistenceService) input;
-                       
+
                        for(Object object : structuredSelection.toList()){
 
                                LineAnnotation annotation = (LineAnnotation) model.getAnnotation(object);
@@ -127,7 +113,7 @@ public class DeleteHandler extends AbstractHandler {
                                                                                if (result.isOk()){
                                                                                        ((LineAnnotation)next).markAsDeleted(null);
                                                                                }
-                                                                               
+
                                                                        }
                                                                }
                                                        }
@@ -146,7 +132,7 @@ public class DeleteHandler extends AbstractHandler {
                                                                        if (result.isOk()){
                                                                                ((LineAnnotation)next).markAsDeleted(null);
                                                                        }
-                                                                       
+
                                                                }
                                                        }
                                                }
@@ -160,11 +146,11 @@ public class DeleteHandler extends AbstractHandler {
                                                                        if (result.isOk()){
                                                                                ((LineAnnotation)next).markAsDeleted(null);
                                                                        }
-                                                                       
+
                                                                }
                                                        }
                                                }
-                                               
+
 //                                             IGroupService service = controller.getGroupService();
 //                                             if (object != null){
 //                                                     result = service.delete(((Group) object).getUuid());
@@ -179,11 +165,11 @@ public class DeleteHandler extends AbstractHandler {
                                                                        if (result.isOk()){
                                                                                ((LineAnnotation)next).markAsDeleted(null);
                                                                        }
-                                                                       
+
                                                                }
                                                        }
                                                }
-                                               
+
 //                                             IUserService service = controller.getUserService();
 //                                             if (object != null){
 //                                                     result = service.delete(((User) object).getUuid());
@@ -191,8 +177,8 @@ public class DeleteHandler extends AbstractHandler {
 //                                             }
                                        } else if (object instanceof TaxonNameBase){
                                                TaxonNameBase name = HibernateProxyHelper.deproxy(object, TaxonNameBase.class);
-                                               
-                                               
+
+
                                                if (object != null){
                                                        NameDeletionConfigurator config = new NameDeletionConfigurator();
 
@@ -201,10 +187,10 @@ public class DeleteHandler extends AbstractHandler {
                                                        if (result_dialog != Status.OK){
                                                                return null;
                                                        }
-                                                       
+
                                                        //operation = new DeleteTaxonNameOperation(commandName,((BulkEditor) editor).getUndoContext() , name, config, (BulkEditor)editor);
                                                        errorMessage = "The name ";
-                                                       
+
                                                        if (model != null) {
                                                                Iterator iter = model.getAnnotationIterator(selection.getOffset(), selection.getLength(), true, true);
                                                                while (iter.hasNext()) {
@@ -214,13 +200,13 @@ public class DeleteHandler extends AbstractHandler {
                                                                                if (result.isOk()){
                                                                                        ((LineAnnotation)next).markAsDeleted(config);
                                                                                }
-                                                                               
+
                                                                        }
                                                                }
                                                        }
                                                }
                                        } else if (object instanceof TaxonBase){
-                                               
+
                                                // synonym
                                                if(object instanceof Synonym){
                                                        Synonym synonym = HibernateProxyHelper.deproxy(object, Synonym.class);
@@ -241,16 +227,16 @@ public class DeleteHandler extends AbstractHandler {
                                                                                if (result.isOk()){
                                                                                        ((LineAnnotation)next).markAsDeleted(config);
                                                                                }
-                                                                               
+
                                                                        }
                                                                }
                                                        }
                                                }
-                                               
+
                                                else if(object instanceof Taxon ){
                                                        Taxon  taxon = HibernateProxyHelper.deproxy(object, Taxon.class);
                                                        if (((Taxon)object).getTaxonNodes().isEmpty()){
-                                                          
+
                                 errorMessage = "The taxon ";
                                                        } else{
                                                            MessagingUtils.messageDialog("Delete not possible", getClass(), "The taxon can not be deleted in bulk editor. It is used in a classification.", null);
@@ -274,13 +260,13 @@ public class DeleteHandler extends AbstractHandler {
                                                                                if (result.isOk()){
                                                                                        ((LineAnnotation)next).markAsDeleted(config);
                                                                                }
-                                                                               
+
                                                                        }
                                                                }
                                                        }
                                                }
-                                                       
-                                               
+
+
 //                                             ITaxonService service = controller.getTaxonService();
 //                                             if (object != null){
 //                                                     if (object instanceof Taxon){
@@ -312,18 +298,18 @@ public class DeleteHandler extends AbstractHandler {
 //                                                     }
 //                                             }
                                        } else if (object instanceof TeamOrPersonBase){
-                                               
+
                                                  if (model != null) {
                                                                Iterator iter = model.getAnnotationIterator(selection.getOffset(), selection.getLength(), true, true);
                                                                while (iter.hasNext()) {
                                                                        Object next = iter.next();
                                                                        if (next instanceof LineAnnotation) {
-                                                                               
+
                                                                                result = controller.getAgentService().isDeletable((TeamOrPersonBase) object, null);
                                                                                if (result.isOk()){
                                                                                        ((LineAnnotation)next).markAsDeleted(null);
                                                                                }
-                                                                               
+
                                                                        }
                                                                }
                                                        }
@@ -333,7 +319,7 @@ public class DeleteHandler extends AbstractHandler {
                                                errorMessage = "The team or person ";
                                        } else if (object instanceof Media){
                                                MediaDeletionConfigurator config = new MediaDeletionConfigurator();
-                                               
+
                                                DeleteConfiguratorDialog dialog;
                                            dialog = new DeleteConfiguratorDialog(config, HandlerUtil.getActiveShell(event), "Confirm Deletion",  null,  "Do you really want to delete the media?", MessageDialog.WARNING, new String[] { "Delete", "Skip" }, 0);
                                                int result_dialog= dialog.open();
@@ -342,9 +328,9 @@ public class DeleteHandler extends AbstractHandler {
                         }
                         IMediaService service = controller.getMediaService();
                         //TeamOrPersonBase teamOrPerson = (TeamOrPersonBase)service.load(((TeamOrPersonBase) object).getUuid());
-                       
+
                         errorMessage = "The media ";
-                        
+
                         if (model != null) {
                                                        Iterator iter = model.getAnnotationIterator(selection.getOffset(), selection.getLength(), true, true);
                                                        while (iter.hasNext()) {
@@ -352,9 +338,9 @@ public class DeleteHandler extends AbstractHandler {
                                                                if (next instanceof LineAnnotation) {
                                                                         result = service.isDeletable(((Media)object), config);
                                                                        if (result.isOk()){
-                                                                               ((LineAnnotation)next).markAsDeleted(null);
+                                                                               ((LineAnnotation)next).markAsDeleted(config);
                                                                        }
-                                                                       
+
                                                                }
                                                        }
                                                }
@@ -377,12 +363,12 @@ public class DeleteHandler extends AbstractHandler {
                                                MessagingUtils.messageDialog("Delete not possible", getClass(), "The object could not be deleted. An exception occured.", null);
                                        }
                                }
-                               
-                               
+
+
                                if (result.isOk() ){
-                                       
+
                                        ((BulkEditor) editor).removeAnnotatedLine(annotation);
-                                                                       
+
                                        if(result.getUpdatedObjects().size() != 0 || !result.getExceptions().isEmpty()){
                                            List<String> messages = new ArrayList<String>();
                         int i = result.getExceptions().size();
@@ -403,5 +389,5 @@ public class DeleteHandler extends AbstractHandler {
                return null;
        }
 
-       
+
 }