// $Id$
/**
* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
+* 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.UUID;
-
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.ui.handlers.HandlerUtil;
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.IReferenceService;
import eu.etaxonomy.cdm.api.service.ITaxonService;
import eu.etaxonomy.cdm.api.service.IUserService;
+import eu.etaxonomy.cdm.api.service.config.NameDeletionConfigurator;
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
import eu.etaxonomy.cdm.model.common.Group;
import eu.etaxonomy.cdm.model.common.User;
-import eu.etaxonomy.cdm.model.name.NameRelationship;
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
import eu.etaxonomy.cdm.model.reference.Reference;
import eu.etaxonomy.cdm.model.taxon.Synonym;
import eu.etaxonomy.cdm.model.taxon.Taxon;
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
-import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
-import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
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.internal.TaxeditorBulkeditorPlugin;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
-import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
-import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
import eu.etaxonomy.taxeditor.store.CdmStore;
+
/**
* @author n.hoffmann
* @created Mar 11, 2011
*/
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
-
- if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_EXPERIMENTAL_FEATURES)){
- ISelection selection = HandlerUtil.getCurrentSelection(event);
-
- IEditorPart editor = HandlerUtil.getActiveEditor(event);
-
- IEditorInput input = editor.getEditorInput();
-
- if((input instanceof IEntityPersistenceService) && (selection instanceof IStructuredSelection)){
-
-
- IDocumentProvider provider = ((BulkEditor) editor).getDocumentProvider();
- LineAnnotationModel model =
- (LineAnnotationModel) provider.getAnnotationModel(input);
-
-
- IStructuredSelection structuredSelection = (IStructuredSelection) selection;
-
- IEntityPersistenceService persistenceService = (IEntityPersistenceService) input;
-
- for(Object object : structuredSelection.toList()){
-
- LineAnnotation annotation = (LineAnnotation) model.getAnnotation(object);
- DeleteResult result = new DeleteResult();
- try {
- ICdmApplicationConfiguration controller;
- controller = (ICdmApplicationConfiguration) CdmStore.getCurrentApplicationConfiguration();
- //persistenceService.delete(object);
- if (object instanceof SpecimenOrObservationBase){
-
- IOccurrenceService service = controller.getOccurrenceService();
- result = service.delete((SpecimenOrObservationBase)object);
- } else if (object instanceof Reference){
- IReferenceService service = controller.getReferenceService();
- result = service.delete((Reference)object);
- } else if (object instanceof Group){
- IGroupService service = controller.getGroupService();
- result = service.delete((Group) object);
- }else if (object instanceof User){
- IUserService service = controller.getUserService();
- result = service.delete((User) object);
- } else if (object instanceof TaxonNameBase){
- INameService service = controller.getNameService();
- result = service.delete((TaxonNameBase)object);
- } else if (object instanceof TaxonBase){
- ITaxonService service = controller.getTaxonService();
+
+ ISelection selection = HandlerUtil.getCurrentSelection(event);
+
+ IEditorPart editor = HandlerUtil.getActiveEditor(event);
+
+ IEditorInput input = editor.getEditorInput();
+
+ if((input instanceof IEntityPersistenceService) && (selection instanceof IStructuredSelection)){
+
+
+ IDocumentProvider provider = ((BulkEditor) editor).getDocumentProvider();
+ LineAnnotationModel model =
+ (LineAnnotationModel) provider.getAnnotationModel(input);
+
+
+ IStructuredSelection structuredSelection = (IStructuredSelection) selection;
+
+ IEntityPersistenceService persistenceService = (IEntityPersistenceService) input;
+
+
+ for(Object object : structuredSelection.toList()){
+
+ LineAnnotation annotation = (LineAnnotation) model.getAnnotation(object);
+ DeleteResult result = new DeleteResult();
+ //result.setError();
+ try {
+ ICdmApplicationConfiguration controller;
+ controller = CdmStore.getCurrentApplicationConfiguration();
+
+ if (object instanceof SpecimenOrObservationBase){
+ IOccurrenceService service = controller.getOccurrenceService();
+ if (object != null){
+ result = service.delete(((SpecimenOrObservationBase) object).getUuid());
+ }
+ } else if (object instanceof Reference){
+ IReferenceService service = controller.getReferenceService();
+ if (object != null){
+ result = service.delete(((Reference) object).getUuid());
+ }
+
+ } else if (object instanceof Group){
+ IGroupService service = controller.getGroupService();
+ if (object != null){
+ result = service.delete(((Group) object).getUuid());
+ }
+ }else if (object instanceof User){
+ IUserService service = controller.getUserService();
+ if (object != null){
+ result = service.delete(((User) object).getUuid());
+ }
+ } else if (object instanceof TaxonNameBase){
+ INameService service = controller.getNameService();
+ if (object != null){
+ NameDeletionConfigurator config = new NameDeletionConfigurator();
+ result = service.delete(((TaxonNameBase) object).getUuid(), config);
+ }
+ } else if (object instanceof TaxonBase){
+ ITaxonService service = controller.getTaxonService();
+ if (object != null){
if (object instanceof Taxon){
- result = service.deleteTaxon((Taxon)object, null, null);
+ result = service.deleteTaxon(((TaxonBase) object).getUuid(), null, null);
}else{
- result = service.deleteSynonym((Synonym)object, null);
+ result = service.deleteSynonym(((Synonym)object).getUuid(), null);
}
- } else if (object instanceof TeamOrPersonBase){
- IAgentService service = controller.getAgentService();
- result = service.delete((TeamOrPersonBase)object);
}
- } catch (Exception e){
- MessagingUtils.messageDialog("Could not delete", getClass(), e.getMessage(), null);
+ } else if (object instanceof TeamOrPersonBase){
+ IAgentService service = controller.getAgentService();
+ //TeamOrPersonBase teamOrPerson = (TeamOrPersonBase)service.load(((TeamOrPersonBase) object).getUuid());
+ result = service.delete(((TeamOrPersonBase)object).getUuid());
}
- if (result.isError()){
- MessagingUtils.messageDialog("Could not delete", getClass(), result.getExceptions().get(0).getMessage(), 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()) {
+ String message = null;
+ int i = result.getExceptions().size();
+ for (Exception e:result.getExceptions()){
+ i--;
+ message+= e.getMessage();
+ if (i>0){
+ message+= ", ";
+ }
+ }
+
+
+ MessagingUtils.messageDialog("Delete not possible", getClass(), result.getExceptions().toString(), null);
+ }else{
+ 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()){
+ MessagingUtils.informationDialog("Delete successfull", "The object is deleted but there are updated objects: " + result.toString());
+ }
+
+ }
+
}
- }else{
- MessagingUtils.warningDialog("Feature not enabled", getClass(), "Deletion is currently an experimental feature." +
- "Enable it via Preferences at your own risk.");
}
-
-
+
+
return null;
}