commit 240080affb98467d0a10c2b890bb05af5a2256e3
Author: Patrick Plitzner <p.plitzner@bgbm.org>
Date:   Fri Jun 30 13:36:22 2017 +0200

    code cleanup

diff --git a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/handler/DeleteHandler.java b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/handler/DeleteHandler.java
index 36671bcdf..e1eba6bb7 100644
--- a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/handler/DeleteHandler.java
+++ b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/handler/DeleteHandler.java
@@ -1,23 +1,22 @@
 /**
-* 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.bulkeditor.handler;
 
 
 import java.util.ArrayList;
-import java.util.Iterator;
 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.runtime.Status;
+import org.eclipse.core.runtime.IStatus;
 import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.text.TextSelection;
 import org.eclipse.jface.viewers.IStructuredSelection;
@@ -73,198 +72,161 @@ public class DeleteHandler extends AbstractHandler {
     private static final String DELETE = "Delete";
     private static final String CONFIRM_DELETION = "Confirm Deletion";
 
-    /* (non-Javadoc)
-	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
-	 */
-	@Override
-	public Object execute(ExecutionEvent event) throws ExecutionException {
+    @Override
+    public Object execute(ExecutionEvent event) throws ExecutionException {
 
 
-		TextSelection selection = (TextSelection) HandlerUtil.getCurrentSelection(event);
-		IEditorPart editor = HandlerUtil.getActiveEditor(event);
+        TextSelection selection = (TextSelection) HandlerUtil.getCurrentSelection(event);
+        IEditorPart editor = HandlerUtil.getActiveEditor(event);
 
-		IEditorInput input = editor.getEditorInput();
+        IEditorInput input = editor.getEditorInput();
 
-		if((input instanceof IEntityPersistenceService) && (selection instanceof IStructuredSelection)){
+        if((input instanceof IEntityPersistenceService) && (selection instanceof IStructuredSelection)){
 
 
-			IDocumentProvider provider = ((BulkEditor) editor).getDocumentProvider();
-			LineAnnotationModel model =
-					(LineAnnotationModel) provider.getAnnotationModel(input);
+            IDocumentProvider provider = ((BulkEditor) editor).getDocumentProvider();
+            LineAnnotationModel model =
+                    (LineAnnotationModel) provider.getAnnotationModel(input);
 
 
-			IStructuredSelection structuredSelection = (IStructuredSelection) selection;
-			DeleteConfiguratorBase config = null;
-			IEntityPersistenceService<?> persistenceService = (IEntityPersistenceService<?>) input;
-			DeleteResult result = new DeleteResult();
-			String errorMessage= "The object ";
-			for(Object object : structuredSelection.toList()){
-			    if (object instanceof CdmBase){
-			        CdmBase base = (CdmBase)object;
-			        LineAnnotation<?> annotation = (LineAnnotation<?>) model.getAnnotation(object);
-			        if (base.getId() != 0){
+            IStructuredSelection structuredSelection = (IStructuredSelection) selection;
+            DeleteConfiguratorBase config = null;
+            DeleteResult result = new DeleteResult();
+            String errorMessage= "The object ";
+            for(Object object : structuredSelection.toList()){
+                if (object instanceof CdmBase){
+                    CdmBase base = (CdmBase)object;
+                    LineAnnotation<?> annotation = (LineAnnotation<?>) model.getAnnotation(object);
+                    if (base.getId() != 0){
 
 
-        				try {
-        				    ICdmRepository controller;
-        				    controller = CdmStore.getCurrentApplicationConfiguration();
-        				    if (object instanceof SpecimenOrObservationBase){
-        				        IOccurrenceService service = controller.getOccurrenceService();
-        				        config = new SpecimenDeleteConfigurator();
+                        try {
+                            ICdmRepository controller;
+                            controller = CdmStore.getCurrentApplicationConfiguration();
+                            if (object instanceof SpecimenOrObservationBase){
+                                IOccurrenceService service = controller.getOccurrenceService();
+                                config = new SpecimenDeleteConfigurator();
 
                                 DeleteConfiguratorDialog dialog = new DeleteConfiguratorDialog(config, HandlerUtil.getActiveShell(event), CONFIRM_DELETION,  null,  Messages.BulkEditor_DeleteHandler_reallyDeleteSpecimen, MessageDialog.WARNING, new String[] { DELETE, SKIP }, 0, true);
                                 int result_dialog= dialog.open();
-                                if (result_dialog != Status.OK){
+                                if (result_dialog != IStatus.OK){
+                                    return null;
+                                }
+                                result = service.isDeletable(((SpecimenOrObservationBase<?>) object).getUuid(), config);
+                                errorMessage = "The specimen or observation ";
+
+                            } else if (object instanceof Reference){
+                                IReferenceService service = controller.getReferenceService();
+                                result = service.isDeletable(((Reference)object).getUuid(), null);
+                                errorMessage = "The reference ";
+
+                            } else if (object instanceof Group){
+                                errorMessage = "The group ";
+                            }else if (object instanceof User){
+                                errorMessage = "The user ";
+                            } else if (object instanceof TaxonName){
+                                TaxonName name = HibernateProxyHelper.deproxy(object, TaxonName.class);
+                                config = new NameDeletionConfigurator();
+
+                                DeleteConfiguratorDialog dialog = new DeleteConfiguratorDialog(config, HandlerUtil.getActiveShell(event), CONFIRM_DELETION,  null,  "Do you really want to delete the name?\nThis operation is irreversible!", MessageDialog.WARNING, new String[] { DELETE, SKIP }, 0, true);
+                                int result_dialog= dialog.open();
+                                if (result_dialog != IStatus.OK){
                                     return null;
                                 }
-        						if (object != null){
-        							result = service.isDeletable(((SpecimenOrObservationBase<?>) object).getUuid(), config);
-        							errorMessage = "The specimen or observation ";
-
-        						}
-        				    } else if (object instanceof Reference){
-        						IReferenceService service = controller.getReferenceService();
-        						if (object != null){
-        							result = service.isDeletable(((Reference)object).getUuid(), null);
-        							errorMessage = "The reference ";
-        						}
-
-        				    } else if (object instanceof Group){
-        				        errorMessage = "The group ";
-        				    }else if (object instanceof User){
-        				        errorMessage = "The user ";
-         				    } else if (object instanceof TaxonName){
-         				        TaxonName name = HibernateProxyHelper.deproxy(object, TaxonName.class);
-         				        if (object != null){
-         				            config = new NameDeletionConfigurator();
-
-         				            DeleteConfiguratorDialog dialog = new DeleteConfiguratorDialog(config, HandlerUtil.getActiveShell(event), CONFIRM_DELETION,  null,  "Do you really want to delete the name?\nThis operation is irreversible!", MessageDialog.WARNING, new String[] { DELETE, SKIP }, 0, true);
-         				            int result_dialog= dialog.open();
-         				            if (result_dialog != Status.OK){
-         				                return null;
-         				            }
-         				            result = controller.getNameService().isDeletable(name.getUuid(), config);
-         				            errorMessage = "The name ";
-
-         				        }
-         				    } else if (object instanceof TaxonBase){
-
-        						// synonym
-        						if(object instanceof Synonym){
-        							Synonym synonym = HibernateProxyHelper.deproxy(object, Synonym.class);
-        							config = new SynonymDeletionConfigurator();
-        							errorMessage = "The synonym ";
-        							DeleteConfiguratorDialog dialog = new DeleteConfiguratorDialog(config, HandlerUtil.getActiveShell(event), CONFIRM_DELETION,  null,  "Do you really want to delete the synonym?", MessageDialog.WARNING, new String[] { DELETE, SKIP }, 0, true);
+                                result = controller.getNameService().isDeletable(name.getUuid(), config);
+                                errorMessage = "The name ";
+
+                            } else if (object instanceof TaxonBase){
+
+                                // synonym
+                                if(object instanceof Synonym){
+                                    Synonym synonym = HibernateProxyHelper.deproxy(object, Synonym.class);
+                                    config = new SynonymDeletionConfigurator();
+                                    errorMessage = "The synonym ";
+                                    DeleteConfiguratorDialog dialog = new DeleteConfiguratorDialog(config, HandlerUtil.getActiveShell(event), CONFIRM_DELETION,  null,  "Do you really want to delete the synonym?", MessageDialog.WARNING, new String[] { DELETE, SKIP }, 0, true);
                                     int result_dialog= dialog.open();
-                                    if (result_dialog != Status.OK){
-                                         return null;
+                                    if (result_dialog != IStatus.OK){
+                                        return null;
                                     }
                                     result = controller.getTaxonService().isDeletable(synonym.getUuid(), 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);
-        							    return null;
-        							}
-        							config = new TaxonDeletionConfigurator();
-        							((TaxonDeletionConfigurator) config).setDeleteInAllClassifications(true);
-        							DeleteConfiguratorDialog dialog;
-        						    dialog = new DeleteConfiguratorDialog(config, HandlerUtil.getActiveShell(event), CONFIRM_DELETION,  null,  "Do you really want to delete the taxon?", MessageDialog.WARNING, new String[] { DELETE, SKIP }, 0, true);
-        							int result_dialog= dialog.open();
-                                    if (result_dialog != Status.OK){
-                                         return null;
+                                }
+                                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);
+                                        return null;
+                                    }
+                                    config = new TaxonDeletionConfigurator();
+                                    ((TaxonDeletionConfigurator) config).setDeleteInAllClassifications(true);
+                                    DeleteConfiguratorDialog dialog;
+                                    dialog = new DeleteConfiguratorDialog(config, HandlerUtil.getActiveShell(event), CONFIRM_DELETION,  null,  "Do you really want to delete the taxon?", MessageDialog.WARNING, new String[] { DELETE, SKIP }, 0, true);
+                                    int result_dialog= dialog.open();
+                                    if (result_dialog != IStatus.OK){
+                                        return null;
                                     }
                                     result = controller.getTaxonService().isDeletable(taxon.getUuid(), config);
 
-        						}
-         				    } else if (object instanceof TeamOrPersonBase){
-         				        result = controller.getAgentService().isDeletable(((CdmBase) object).getUuid(), null);
-    						  errorMessage = "The team or person ";
-         				   } else if (object instanceof Media){
-         				       config = new MediaDeletionConfigurator();
-         				      
-         				       Media media = HibernateProxyHelper.deproxy(object, Media.class);
-         				      ((MediaDeletionConfigurator)config).setDeleteFrom(media);
-         				       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, true);
-        					   int result_dialog= dialog.open();
-                               if (result_dialog != Status.OK){
-                                   return null;
-                               }
-
-                               result = controller.getMediaService().isDeletable(media.getUuid(), config);
-                               errorMessage = "The media ";
-
-                           }
-
-
-    				} catch (Exception e){
-    					MessagingUtils.errorDialog("Exception occured. Delete not possible", getClass(), e.getMessage(), TaxeditorBulkeditorPlugin.PLUGIN_ID, null, true);
-    				}
-    				if (result.isError() || result.isAbort()){
-    					if (!result.getExceptions().isEmpty()) {
-    						List<String> messages = new ArrayList<String>();
-    						int i = result.getExceptions().size();
-    						for (Exception e:result.getExceptions()){
-    							messages.add(e.getMessage());
-    						}
-    						errorMessage += "could not be deleted.";
-    						//MessagingUtils.errorDialog("test", getClass(), "message", TaxeditorBulkeditorPlugin.PLUGIN_ID, result.getExceptions().iterator().next(),true);
-    						DeleteResultMessagingUtils.messageDialogWithDetails(result,errorMessage, TaxeditorBulkeditorPlugin.PLUGIN_ID);
-    					}else{
-    						MessagingUtils.messageDialog("Delete not possible", getClass(), "The object could not be deleted. An exception occured.", null);
-    					}
-    				}else if (model != null) {
-    					annotation.markAsDeleted(config);
-    				}
-//    					int offset = selection.getOffset();
-//    					if (offset == 0){
-//    						offset = 1;
-//    					}
-//                        Iterator iter = model.getAnnotationIterator(offset, selection.getLength(), true, true);
-//                   //     Iterator<Annotation> iter = model.getAnnotationIterator(selection.getOffset(), selection.getLength(), true, true);
-//                        while (iter.hasNext()) {
-//                            Object next = iter.next();
-//                            if (next instanceof LineAnnotation) {
-//                                if (result.isOk()){
-//                                    ((LineAnnotation)next).markAsDeleted(config);
-//
-//                                }
-//
-//                            }
-//                        }
-//                    }
-
-			    }
-		        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();
-                        for (Exception e:result.getExceptions()){
-                            messages.add(e.getMessage());
-                        }
-                        errorMessage += "can be deleted but related object(s) could not be deleted. ";
-                        //MessagingUtils.errorDialog("test", getClass(), "message", TaxeditorBulkeditorPlugin.PLUGIN_ID, result.getExceptions().iterator().next(),true);
-                        DeleteResultMessagingUtils.messageDialogWithDetails(result, errorMessage, TaxeditorBulkeditorPlugin.PLUGIN_ID);
-                    }
-
-                }
-
-			    }
+                                }
+                            } else if (object instanceof TeamOrPersonBase){
+                                result = controller.getAgentService().isDeletable(((CdmBase) object).getUuid(), null);
+                                errorMessage = "The team or person ";
+                            } else if (object instanceof Media){
+                                config = new MediaDeletionConfigurator();
+
+                                Media media = HibernateProxyHelper.deproxy(object, Media.class);
+                                ((MediaDeletionConfigurator)config).setDeleteFrom(media);
+                                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, true);
+                                int result_dialog= dialog.open();
+                                if (result_dialog != IStatus.OK){
+                                    return null;
+                                }
 
-			}
-		}
+                                result = controller.getMediaService().isDeletable(media.getUuid(), config);
+                                errorMessage = "The media ";
 
+                            }
 
-		return null;
-	}
 
+                        } catch (Exception e){
+                            MessagingUtils.errorDialog("Exception occured. Delete not possible", getClass(), e.getMessage(), TaxeditorBulkeditorPlugin.PLUGIN_ID, null, true);
+                        }
+                        if (result.isError() || result.isAbort()){
+                            if (!result.getExceptions().isEmpty()) {
+                                List<String> messages = new ArrayList<String>();
+                                for (Exception e:result.getExceptions()){
+                                    messages.add(e.getMessage());
+                                }
+                                errorMessage += "could not be deleted.";
+                                //MessagingUtils.errorDialog("test", getClass(), "message", TaxeditorBulkeditorPlugin.PLUGIN_ID, result.getExceptions().iterator().next(),true);
+                                DeleteResultMessagingUtils.messageDialogWithDetails(result,errorMessage, TaxeditorBulkeditorPlugin.PLUGIN_ID);
+                            }else{
+                                MessagingUtils.messageDialog("Delete not possible", getClass(), "The object could not be deleted. An exception occured.", null);
+                            }
+                        }
+                        annotation.markAsDeleted(config);
+                    }
+                    if (result.isOk() ){
+
+                        ((BulkEditor) editor).removeAnnotatedLine(annotation);
+
+                        if(result.getUpdatedObjects().size() != 0 || !result.getExceptions().isEmpty()){
+                            List<String> messages = new ArrayList<String>();
+                            for (Exception e:result.getExceptions()){
+                                messages.add(e.getMessage());
+                            }
+                            errorMessage += "can be deleted but related object(s) could not be deleted. ";
+                            //MessagingUtils.errorDialog("test", getClass(), "message", TaxeditorBulkeditorPlugin.PLUGIN_ID, result.getExceptions().iterator().next(),true);
+                            DeleteResultMessagingUtils.messageDialogWithDetails(result, errorMessage, TaxeditorBulkeditorPlugin.PLUGIN_ID);
+                        }
+                    }
+                }
+            }
+        }
+        return null;
+    }
 
 }
