commit 7dce04a4ef06e30769a711c8b6aceb11b2137c31
Author: Katja Luther <k.luther@bgbm.org>
Date:   Thu Oct 13 13:14:26 2016 +0200

    fix  #5692: adapt delete algorithm to annotatedLineEditor mechanisms

diff --git a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/annotatedlineeditor/AnnotatedLineDocumentProvider.java b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/annotatedlineeditor/AnnotatedLineDocumentProvider.java
index 1ad5dc7d6..e2a4d7470 100644
--- a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/annotatedlineeditor/AnnotatedLineDocumentProvider.java
+++ b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/annotatedlineeditor/AnnotatedLineDocumentProvider.java
@@ -26,6 +26,8 @@ import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.texteditor.AbstractDocumentProvider;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
+import eu.etaxonomy.cdm.api.service.config.DeleteConfiguratorBase;
+import eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException;
 import eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 
@@ -274,7 +276,16 @@ public class AnnotatedLineDocumentProvider extends AbstractDocumentProvider {
 				}
 				if (annotation.isMarkedAsMerged()) {
 					persistenceService.merge(annotation.getEntity(), annotation.getMergeTarget()); //  merge
-				} else {
+				} if (annotation.isMarkedAsDeleted()) {
+					try {
+						persistenceService.delete(annotation.getEntity(), annotation.getDeleteConfigurator());
+					} catch (ReferencedObjectUndeletableException e) {
+						// TODO Auto-generated catch block
+						e.printStackTrace();
+					} //  merge
+				}
+				
+				else {
 					// TODO clarify w AM whether this needs to be executed on merged objects
 					//persistenceService.delete(annotation.getEntity()); // delete
 				}
@@ -378,9 +389,9 @@ public class AnnotatedLineDocumentProvider extends AbstractDocumentProvider {
 			int length = position.getLength();
 
 			Object entity = annotation.getEntity();
-			annotation.markAsDeleted();
+			//annotation.markAsDeleted(configurator);
 			model.removeAnnotation(annotation);
-
+			
 			// Immediately followed by a delimiter?
 			int annotationEnd = offset + length;
 			try {
@@ -392,7 +403,9 @@ public class AnnotatedLineDocumentProvider extends AbstractDocumentProvider {
 			}
 
 			try {
+				
 				document.replace(offset, length, "");
+				
 			} catch (BadLocationException e) {
 				MessagingUtils.error(getClass(), "Problems removing annotated line", e);
 			}
@@ -411,4 +424,6 @@ public class AnnotatedLineDocumentProvider extends AbstractDocumentProvider {
 			updateLineFromAnnotation(annotation);
 		}
 	}
+	
+	
 }
diff --git a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/annotatedlineeditor/AnnotatedLineEditor.java b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/annotatedlineeditor/AnnotatedLineEditor.java
index 03ee6e9fe..178c9c64d 100644
--- a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/annotatedlineeditor/AnnotatedLineEditor.java
+++ b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/annotatedlineeditor/AnnotatedLineEditor.java
@@ -235,6 +235,7 @@ public class AnnotatedLineEditor extends TextEditor implements IConversationEnab
      */
     public void removeAnnotatedLine(LineAnnotation annotation) {
         ((AnnotatedLineDocumentProvider) getDocumentProvider()).removeAnnotatedLine(annotation);
+        
     }
 
     /* (non-Javadoc)
diff --git a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/annotatedlineeditor/IEntityPersistenceService.java b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/annotatedlineeditor/IEntityPersistenceService.java
index b57e8b7bc..d9224d928 100644
--- a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/annotatedlineeditor/IEntityPersistenceService.java
+++ b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/annotatedlineeditor/IEntityPersistenceService.java
@@ -10,6 +10,7 @@
 
 package eu.etaxonomy.taxeditor.annotatedlineeditor;
 
+import eu.etaxonomy.cdm.api.service.config.DeleteConfiguratorBase;
 import eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException;
 
 
@@ -57,5 +58,5 @@ public interface IEntityPersistenceService<T> {
 	 * @return a boolean.
 	 * @throws ReferencedObjectUndeletableException
 	 */
-	boolean delete(T entity) throws ReferencedObjectUndeletableException;
+	boolean delete(T entity, DeleteConfiguratorBase config) throws ReferencedObjectUndeletableException;
 }
diff --git a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/annotatedlineeditor/LineAnnotation.java b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/annotatedlineeditor/LineAnnotation.java
index ef4f124b7..9f41f4b44 100644
--- a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/annotatedlineeditor/LineAnnotation.java
+++ b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/annotatedlineeditor/LineAnnotation.java
@@ -14,6 +14,9 @@ import java.util.Set;
 import org.apache.log4j.Logger;
 import org.eclipse.jface.text.source.Annotation;
 
+import eu.etaxonomy.cdm.api.service.config.DeleteConfiguratorBase;
+import eu.etaxonomy.cdm.api.service.config.NameDeletionConfigurator;
+
 /**
  * An <code>Annotation</code> which spans an entire line and holds an object associated
  * with the line in an <code>IEntityContainer</code>.
@@ -37,6 +40,7 @@ public class LineAnnotation<T> extends Annotation implements IEntityContainer<T>
 	private boolean markedAsMerged;
 	private boolean markedAsNew;
 	private T mergeTarget;
+	private DeleteConfiguratorBase configurator= null;
 
 
 	/**
@@ -184,7 +188,13 @@ public class LineAnnotation<T> extends Annotation implements IEntityContainer<T>
 			lineDisplayStrategy.setStatusMessage(entity + " deleted.", entity);
 		}
 	}
-
+	 public void markAsDeleted(DeleteConfiguratorBase config) {
+			super.markDeleted(true);
+			this.configurator = config;
+			if (!isMarkedAsMerged()) {
+				lineDisplayStrategy.setStatusMessage(entity + " deleted.", entity);
+			}
+		}
 	/* (non-Javadoc)
 	 * @see eu.etaxonomy.taxeditor.bulkeditor.IEntityContainer#markAsMerged(eu.etaxonomy.cdm.model.common.CdmBase)
 	 */
@@ -248,4 +258,13 @@ public class LineAnnotation<T> extends Annotation implements IEntityContainer<T>
     public void setEntity(Object entity) {
         this.entity = (T) entity;
     }
+
+	public DeleteConfiguratorBase getDeleteConfigurator() {
+		return this.configurator;
+	}
+
+	public void setDeleteConfigurator(DeleteConfiguratorBase config) {
+		this.configurator = config;
+		
+	}
 }
diff --git a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/BulkEditor.java b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/BulkEditor.java
index d3d9d482e..b0d5605b3 100644
--- a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/BulkEditor.java
+++ b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/BulkEditor.java
@@ -74,6 +74,15 @@ public class BulkEditor extends AnnotatedLineEditor implements IPartContentHasDe
 	private boolean isDirty;
 
     private IUndoContext undoContext;
+    
+    private BulkEditorQuery lastQuery;
+    
+	/**
+	 * @return the lastQuery
+	 */
+	public BulkEditorQuery getLastQuery() {
+		return lastQuery;
+	}
 
 	public BulkEditor() {
 		super(CdmStore.createConversation());
@@ -185,6 +194,13 @@ public class BulkEditor extends AnnotatedLineEditor implements IPartContentHasDe
 		searchBar.setFocus();
 	}
 
+	/**
+	 * @return the searchBar
+	 */
+	public BulkEditorSearch getSearchBar() {
+		return searchBar;
+	}
+
 	private void displayWarningDialog() {
 		IPreferenceStore prefs = PreferencesUtil.getPreferenceStore();
 		if (!prefs.getBoolean(IPreferenceKeys.HIDE_BULKEDITOR_INFO)) {
@@ -247,8 +263,9 @@ public class BulkEditor extends AnnotatedLineEditor implements IPartContentHasDe
 	    isDirty = true;
 	    firePropertyChange(PROP_DIRTY);
 	}
-
-	@Override
+	
+	
+   	@Override
 	public void doSave(IProgressMonitor progressMonitor) {
 	    isDirty = false;
 
@@ -286,13 +303,14 @@ public class BulkEditor extends AnnotatedLineEditor implements IPartContentHasDe
 					return;
 				}
 			}
-			conversation.clear();
-			conversation.commit(true);
+			//conversation.clear();
+			//conversation.commit(true);
 
 			getEditorInput().dispose();
 			getEditorInput().bind();
 			getEditorInput().performSearch(query);
-
+			this.lastQuery = query;	
+			this.lastQuery.getSearchConfigurator().setCheckResult(false);
 			refresh();
 
 			selectFirstItem();
@@ -336,4 +354,8 @@ public class BulkEditor extends AnnotatedLineEditor implements IPartContentHasDe
     public IUndoContext getUndoContext() {
         return undoContext;
     }
+
+	public void setDirty(boolean isDirty) {
+		this.isDirty = isDirty;
+	}
 }
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 f42174ba7..b9f334677 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
@@ -11,13 +11,17 @@
 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.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;
@@ -30,14 +34,15 @@ 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.INameService;
 import eu.etaxonomy.cdm.api.service.IOccurrenceService;
 import eu.etaxonomy.cdm.api.service.IReferenceService;
-import eu.etaxonomy.cdm.api.service.ITaxonService;
 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;
 import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
+import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
 import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
 import eu.etaxonomy.cdm.model.common.Group;
 import eu.etaxonomy.cdm.model.common.User;
@@ -52,9 +57,17 @@ 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.bulkeditor.operation.DeleteTaxonBaseOperation;
+import eu.etaxonomy.taxeditor.bulkeditor.operation.DeleteTaxonNameOperation;
+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.CdmDeleteOperation;
+import eu.etaxonomy.taxeditor.operation.RemotingCdmHandler;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.ui.dialog.deleteConfigurator.DeleteConfiguratorDialog;
 
@@ -66,14 +79,16 @@ 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 {
 
-		ISelection selection = HandlerUtil.getCurrentSelection(event);
-
+		
+		TextSelection selection = (TextSelection) HandlerUtil.getCurrentSelection(event);
 		IEditorPart editor = HandlerUtil.getActiveEditor(event);
 
 		IEditorInput input = editor.getEditorInput();
@@ -89,8 +104,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);
@@ -104,82 +118,247 @@ public class DeleteHandler extends AbstractHandler {
 					if (object instanceof SpecimenOrObservationBase){
 						IOccurrenceService service = controller.getOccurrenceService();
 						if (object != null){
-							result = service.delete(((SpecimenOrObservationBase) object).getUuid());
+							result = service.isDeletable(((SpecimenOrObservationBase) object), null);
 							errorMessage = "The specimen or observation ";
+							if (model != null) {
+								Iterator 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(null);
+										}
+										
+									}
+								}
+							}
 						}
 					} else if (object instanceof Reference){
 						IReferenceService service = controller.getReferenceService();
 						if (object != null){
-							result = service.delete(((Reference) object).getUuid());
+							result = service.isDeletable((Reference)object, null);
 							errorMessage = "The reference ";
 						}
+						if (model != null) {
+							Iterator 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(null);
+									}
+									
+								}
+							}
+						}
 
 					} else if (object instanceof Group){
-						IGroupService service = controller.getGroupService();
-						if (object != null){
-							result = service.delete(((Group) object).getUuid());
-							errorMessage = "The group ";
+						if (model != null) {
+							Iterator 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(null);
+									}
+									
+								}
+							}
 						}
+						
+//						IGroupService service = controller.getGroupService();
+//						if (object != null){
+//							result = service.delete(((Group) object).getUuid());
+//							errorMessage = "The group ";
+//						}
 					}else if (object instanceof User){
-						IUserService service = controller.getUserService();
-						if (object != null){
-							result = service.delete(((User) object).getUuid());
-							errorMessage = "The user ";
+						if (model != null) {
+							Iterator 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(null);
+									}
+									
+								}
+							}
 						}
+						
+//						IUserService service = controller.getUserService();
+//						if (object != null){
+//							result = service.delete(((User) object).getUuid());
+//							errorMessage = "The user ";
+//						}
 					} else if (object instanceof TaxonNameBase){
-						INameService service = controller.getNameService();
+						TaxonNameBase name = HibernateProxyHelper.deproxy(object, TaxonNameBase.class);
+						
+						
 						if (object != null){
 							NameDeletionConfigurator config = new NameDeletionConfigurator();
 
-							DeleteConfiguratorDialog dialog = new DeleteConfiguratorDialog(config, HandlerUtil.getActiveShell(event), "Confirm Deletion",  null,  "Do you really want to delete the name?", MessageDialog.WARNING, new String[] { "Delete", "Skip" }, 0);
+							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);
 							int result_dialog= dialog.open();
 							if (result_dialog != Status.OK){
 								return null;
 							}
-							result = service.delete(((TaxonNameBase) object).getUuid(), config);
+							
+							//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()) {
+									Object next = iter.next();
+									if (next instanceof LineAnnotation) {
+										result = controller.getNameService().isDeletable(name, config);
+										if (result.isOk()){
+											((LineAnnotation)next).markAsDeleted(config);
+										}
+										
+									}
+								}
+							}
 						}
 					} else if (object instanceof TaxonBase){
-						ITaxonService service = controller.getTaxonService();
-						if (object != null){
-							if (object instanceof Taxon){
-							    TaxonDeletionConfigurator config = new TaxonDeletionConfigurator();
-								config.setDeleteInAllClassifications(true);
-								DeleteConfiguratorDialog dialog;
-								if (((Taxon)object).getTaxonNodes().isEmpty()){
-								    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);
-								    int result_dialog= dialog.open();
-	                                if (result_dialog != Status.OK){
-	                                    return null;
-	                                }
-	                                result = service.deleteTaxon(((TaxonBase) object).getUuid(), config, null);
-	                                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;
+						
+						// synonym
+						if(object instanceof Synonym){
+							Synonym synonym = HibernateProxyHelper.deproxy(object, Synonym.class);
+							SynonymDeletionConfigurator 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);
+                            int result_dialog= dialog.open();
+                            if (result_dialog != Status.OK){
+                                 return null;
+                            }
+							//operation = new DeleteTaxonBaseOperation(commandName,((BulkEditor) editor).getUndoContext() , synonym, config, (BulkEditor)editor);
+							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.getTaxonService().isDeletable(synonym, config);
+										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);
+							    return null;
+							}
+							TaxonDeletionConfigurator config = new 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);
+							int result_dialog= dialog.open();
+                            if (result_dialog != Status.OK){
+                                 return null;
+                            }
+                            //operation = new DeleteTaxonBaseOperation(commandName, ((BulkEditor) editor).getUndoContext(), taxon, config, (BulkEditor)editor);
+                            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.getTaxonService().isDeletable(taxon, config);
+										if (result.isOk()){
+											((LineAnnotation)next).markAsDeleted(config);
+										}
+										
+									}
 								}
-
-							}else{
-								SynonymDeletionConfigurator config = new SynonymDeletionConfigurator();
-								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);
-                                int result_dialog= dialog.open();
-                                if (result_dialog != Status.OK){
-                                     return null;
-                                }
-								result = service.deleteSynonym(((Synonym)object).getUuid(), config);
-								errorMessage = "The synonym ";
 							}
 						}
+							
+						
+//						ITaxonService service = controller.getTaxonService();
+//						if (object != null){
+//							if (object instanceof Taxon){
+//							    TaxonDeletionConfigurator config = new TaxonDeletionConfigurator();
+//								config.setDeleteInAllClassifications(true);
+//								DeleteConfiguratorDialog dialog;
+//								if (((Taxon)object).getTaxonNodes().isEmpty()){
+//								    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);
+//								    int result_dialog= dialog.open();
+//	                                if (result_dialog != Status.OK){
+//	                                    return null;
+//	                                }
+//	                                result = service.deleteTaxon(((TaxonBase) object).getUuid(), config, null);
+//	                                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;
+//								}
+//
+//							}else{
+//								SynonymDeletionConfigurator config = new SynonymDeletionConfigurator();
+//								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);
+//                                int result_dialog= dialog.open();
+//                                if (result_dialog != Status.OK){
+//                                     return null;
+//                                }
+//								result = service.deleteSynonym(((Synonym)object).getUuid(), config);
+//								errorMessage = "The synonym ";
+//							}
+//						}
 					} else if (object instanceof TeamOrPersonBase){
-						IAgentService service = controller.getAgentService();
+						
+						  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);
+										}
+										
+									}
+								}
+							}
+						//IAgentService service = controller.getAgentService();
 						//TeamOrPersonBase teamOrPerson = (TeamOrPersonBase)service.load(((TeamOrPersonBase) object).getUuid());
-						result = service.delete(((TeamOrPersonBase)object).getUuid());
+					//result = service.delete(((TeamOrPersonBase)object).getUuid());
 						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();
+                        if (result_dialog != Status.OK){
+                             return null;
+                        }
                         IMediaService service = controller.getMediaService();
                         //TeamOrPersonBase teamOrPerson = (TeamOrPersonBase)service.load(((TeamOrPersonBase) object).getUuid());
-                        result = service.delete(((Media)object).getUuid(), null);
+                       
                         errorMessage = "The media ";
+                        
+                        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 = service.isDeletable(((Media)object), config);
+									if (result.isOk()){
+										((LineAnnotation)next).markAsDeleted(null);
+									}
+									
+								}
+							}
+						}
                     }
 
 				} catch (Exception e){
@@ -199,15 +378,19 @@ 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();
                         for (Exception e:result.getExceptions()){
                             messages.add(e.getMessage());
                         }
-					    errorMessage += "was deleted but related object(s) could not be deleted. ";
+					    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);
 					}
@@ -221,4 +404,5 @@ public class DeleteHandler extends AbstractHandler {
 		return null;
 	}
 
+	
 }
diff --git a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/AgentEditorInput.java b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/AgentEditorInput.java
index 31b7498ca..4140a1be4 100644
--- a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/AgentEditorInput.java
+++ b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/AgentEditorInput.java
@@ -14,6 +14,7 @@ import java.util.List;
 import java.util.UUID;
 
 import eu.etaxonomy.cdm.api.service.IAgentService;
+import eu.etaxonomy.cdm.api.service.config.DeleteConfiguratorBase;
 import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator;
 import eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException;
 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
@@ -155,10 +156,9 @@ public class AgentEditorInput extends AbstractBulkEditorInput<TeamOrPersonBase>
 	}
 
 	@Override
-	public boolean delete(TeamOrPersonBase entity)
+	public boolean delete(TeamOrPersonBase entity, DeleteConfiguratorBase config)
 			throws ReferencedObjectUndeletableException {
-		// TODO Auto-generated method stub
-		return false;
+		return CdmStore.getService(IAgentService.class).delete(entity.getUuid()) != null;
 	}
 
     /* (non-Javadoc)
diff --git a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/GroupEditorInput.java b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/GroupEditorInput.java
index 440af4567..9b46b570d 100644
--- a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/GroupEditorInput.java
+++ b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/GroupEditorInput.java
@@ -16,6 +16,7 @@ import java.util.UUID;
 
 import eu.etaxonomy.cdm.api.service.IAgentService;
 import eu.etaxonomy.cdm.api.service.IGroupService;
+import eu.etaxonomy.cdm.api.service.config.DeleteConfiguratorBase;
 import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator;
 import eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException;
 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
@@ -74,8 +75,8 @@ public class GroupEditorInput extends AbstractBulkEditorInput<Group> {
 	 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityPersistenceService#delete(java.lang.Object)
 	 */
 	@Override
-	public boolean delete(Group entity) throws ReferencedObjectUndeletableException {
-		return CdmStore.getService(IGroupService.class).delete(entity) != null;
+	public boolean delete(Group entity, DeleteConfiguratorBase config) throws ReferencedObjectUndeletableException {
+		return CdmStore.getService(IGroupService.class).delete(entity.getUuid()) != null;
 	}
 
 	/* (non-Javadoc)
diff --git a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/MediaEditorInput.java b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/MediaEditorInput.java
index 697118e46..052e11623 100644
--- a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/MediaEditorInput.java
+++ b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/MediaEditorInput.java
@@ -14,9 +14,12 @@ import java.util.List;
 import java.util.UUID;
 
 import eu.etaxonomy.cdm.api.service.IMediaService;
+import eu.etaxonomy.cdm.api.service.config.DeleteConfiguratorBase;
 import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator;
+import eu.etaxonomy.cdm.api.service.config.MediaDeletionConfigurator;
 import eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException;
 import eu.etaxonomy.cdm.model.media.Media;
+import eu.etaxonomy.cdm.persistence.dao.hibernate.media.MediaDaoHibernateImpl;
 import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator;
 import eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorSortProvider;
 import eu.etaxonomy.taxeditor.bulkeditor.input.entitycreator.MediaCreator;
@@ -61,8 +64,14 @@ public class MediaEditorInput extends AbstractBulkEditorInput<Media> {
     }
 
     @Override
-    public boolean delete(Media entity) throws ReferencedObjectUndeletableException {
-        return CdmStore.getService(IMediaService.class).delete(entity) != null;
+    public boolean delete(Media entity, DeleteConfiguratorBase config) throws ReferencedObjectUndeletableException {
+    	MediaDeletionConfigurator mediaConfig = null;
+    	if (config instanceof MediaDeletionConfigurator){
+    		mediaConfig = (MediaDeletionConfigurator) config;
+    	} else{
+    		
+    	}
+        return CdmStore.getService(IMediaService.class).delete(entity.getUuid(), mediaConfig) != null;
     }
 
     @Override
diff --git a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/NameEditorInput.java b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/NameEditorInput.java
index 9017638d0..f257149ac 100644
--- a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/NameEditorInput.java
+++ b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/NameEditorInput.java
@@ -15,7 +15,9 @@ import java.util.List;
 import java.util.UUID;
 
 import eu.etaxonomy.cdm.api.service.INameService;
+import eu.etaxonomy.cdm.api.service.config.DeleteConfiguratorBase;
 import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator;
+import eu.etaxonomy.cdm.api.service.config.NameDeletionConfigurator;
 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
 import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator;
 import eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorSortProvider;
@@ -112,13 +114,17 @@ public class NameEditorInput extends AbstractBulkEditorInput<TaxonNameBase> {
 		return CdmStore.getService(INameService.class).load(uuid, propertyPaths);
 	}
 */
-	/** {@inheritDoc}
-	 **/
 	@Override
-    public boolean delete(TaxonNameBase entity)  {
-		return CdmStore.getService(INameService.class).delete(entity) != null;
+    public boolean delete(TaxonNameBase entity, DeleteConfiguratorBase config)  {
+		NameDeletionConfigurator nameConfig = null;
+		if (config instanceof NameDeletionConfigurator){
+			nameConfig = (NameDeletionConfigurator) config;
+		} else{
+			
+		}
+		return CdmStore.getService(INameService.class).delete(entity.getUuid(), nameConfig) != null;
 	}
-
+	
 	/** {@inheritDoc} */
 	@Override
     public TaxonNameBase save(TaxonNameBase entity) {
diff --git a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/NameRelationshipEditorInput.java b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/NameRelationshipEditorInput.java
index 893232a91..af2c3c883 100644
--- a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/NameRelationshipEditorInput.java
+++ b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/NameRelationshipEditorInput.java
@@ -14,6 +14,7 @@ import java.util.Arrays;
 import java.util.List;
 import java.util.UUID;
 
+import eu.etaxonomy.cdm.api.service.config.DeleteConfiguratorBase;
 import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator;
 import eu.etaxonomy.cdm.model.name.NameRelationship;
 import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator;
@@ -84,7 +85,7 @@ public class NameRelationshipEditorInput extends AbstractBulkEditorInput<NameRel
 	 */
 	/** {@inheritDoc} */
 	@Override
-	public boolean delete(NameRelationship entity) {
+	public boolean delete(NameRelationship entity, DeleteConfiguratorBase config) {
 		// TODO Auto-generated method stub
 		return false;
 	}
diff --git a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/OccurrenceEditorInput.java b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/OccurrenceEditorInput.java
index b247659c2..578105cf4 100644
--- a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/OccurrenceEditorInput.java
+++ b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/OccurrenceEditorInput.java
@@ -15,6 +15,7 @@ import java.util.List;
 import java.util.UUID;
 
 import eu.etaxonomy.cdm.api.service.IOccurrenceService;
+import eu.etaxonomy.cdm.api.service.config.DeleteConfiguratorBase;
 import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator;
 import eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException;
 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
@@ -129,7 +130,7 @@ public class OccurrenceEditorInput extends AbstractBulkEditorInput<SpecimenOrObs
 	/** {@inheritDoc}
 	 * @throws ReferencedObjectUndeletableException */
 	@Override
-    public boolean delete(SpecimenOrObservationBase entity) throws ReferencedObjectUndeletableException {
+    public boolean delete(SpecimenOrObservationBase entity, DeleteConfiguratorBase config ) throws ReferencedObjectUndeletableException {
 		return CdmStore.getService(IOccurrenceService.class).delete(entity) != null;
 	}
 
diff --git a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/ReferenceEditorInput.java b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/ReferenceEditorInput.java
index a269df46a..48cf55fbc 100644
--- a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/ReferenceEditorInput.java
+++ b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/ReferenceEditorInput.java
@@ -14,6 +14,7 @@ import java.util.List;
 import java.util.UUID;
 
 import eu.etaxonomy.cdm.api.service.IReferenceService;
+import eu.etaxonomy.cdm.api.service.config.DeleteConfiguratorBase;
 import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator;
 import eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException;
 import eu.etaxonomy.cdm.model.common.MarkerType;
@@ -132,8 +133,8 @@ public class ReferenceEditorInput extends AbstractBulkEditorInput<Reference> {
 	/** {@inheritDoc}
 	 * @throws ReferencedObjectUndeletableException */
 	@Override
-    public boolean delete(Reference entity) throws ReferencedObjectUndeletableException {
-		return CdmStore.getService(IReferenceService.class).delete(entity) != null;
+    public boolean delete(Reference entity, DeleteConfiguratorBase config) throws ReferencedObjectUndeletableException {
+		return CdmStore.getService(IReferenceService.class).delete(entity.getUuid()) != null;
 	}
 
 	/** {@inheritDoc} */
diff --git a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/UserEditorInput.java b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/UserEditorInput.java
index f78e19d0d..06bd812f7 100644
--- a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/UserEditorInput.java
+++ b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/UserEditorInput.java
@@ -15,6 +15,7 @@ import java.util.List;
 import java.util.UUID;
 
 import eu.etaxonomy.cdm.api.service.IUserService;
+import eu.etaxonomy.cdm.api.service.config.DeleteConfiguratorBase;
 import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator;
 import eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException;
 import eu.etaxonomy.cdm.model.common.User;
@@ -71,7 +72,7 @@ public class UserEditorInput extends AbstractBulkEditorInput<User> {
 	 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityPersistenceService#delete(java.lang.Object)
 	 */
 	@Override
-	public boolean delete(User entity) throws ReferencedObjectUndeletableException {
+	public boolean delete(User entity, DeleteConfiguratorBase config) throws ReferencedObjectUndeletableException {
 		return CdmStore.getService(IUserService.class).delete(entity) != null;
 	}
 
