ref #8222 Delete type designations via operations
authorPatrick Plitzner <p.plitzner@bgbm.org>
Wed, 10 Apr 2019 10:33:23 +0000 (12:33 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Wed, 10 Apr 2019 10:33:23 +0000 (12:33 +0200)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/name/TypeDesignationSection.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/name/operation/DeleteTypeDesignationOperation.java [new file with mode: 0755]

index a930d28..1e5d53b 100644 (file)
@@ -12,7 +12,9 @@ package eu.etaxonomy.taxeditor.ui.section.name;
 import java.util.Collection;
 import java.util.Comparator;
 
+import org.eclipse.core.commands.operations.IOperationHistory;
 import org.eclipse.core.runtime.IStatus;
+import org.eclipse.e4.ui.workbench.modeling.EPartService;
 import org.eclipse.jface.action.Action;
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.action.ToolBarManager;
@@ -31,9 +33,12 @@ import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
 import eu.etaxonomy.cdm.model.name.TaxonName;
 import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
+import eu.etaxonomy.taxeditor.editor.ITaxonEditor;
 import eu.etaxonomy.taxeditor.l10n.Messages;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.model.ImageResources;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
 import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 import eu.etaxonomy.taxeditor.store.CdmStore;
@@ -42,7 +47,9 @@ import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
 import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection;
 import eu.etaxonomy.taxeditor.ui.section.ITaxonBaseDetailSection;
+import eu.etaxonomy.taxeditor.ui.section.name.operation.DeleteTypeDesignationOperation;
 import eu.etaxonomy.taxeditor.ui.section.name.type.CloneTypeWizard;
+import eu.etaxonomy.taxeditor.view.e4.details.DetailsPartE4;
 
 /**
  * @author n.hoffmann
@@ -140,7 +147,22 @@ public class TypeDesignationSection extends AbstractEntityCollectionSection<Taxo
        public void removeElement(TypeDesignationBase element) {
                boolean removeTypeDesignationFromAllTypifiedNames = PreferencesUtil.getBooleanValue(IPreferenceKeys.ADD_TYPES_TO_ALL_NAMES);
                TaxonName entity = removeTypeDesignationFromAllTypifiedNames ? null : getEntity();
-               CdmStore.getService(INameService.class).deleteTypeDesignation(entity.getUuid(), element.getUuid());
+               DetailsPartE4 detailsView = AbstractUtility.getDetailsView(getFormFactory().getContext().get((EPartService.class)));
+               if(detailsView!=null
+                       && detailsView.getSelectionProvidingPart().getObject() instanceof ITaxonEditor
+                       && detailsView.getSelectionProvidingPart().getObject() instanceof IPostOperationEnabled) {
+            DeleteTypeDesignationOperation operation = new DeleteTypeDesignationOperation(
+                    "Remove type designation",
+                    IOperationHistory.GLOBAL_UNDO_CONTEXT,
+                    entity,
+                    element,
+                    (IPostOperationEnabled) detailsView.getSelectionProvidingPart().getObject(),
+                    null);
+            ((ITaxonEditor) detailsView.getSelectionProvidingPart().getObject()).addOperation(operation);
+               }
+               if(entity!=null){
+                   entity.removeTypeDesignation(element);
+               }
                updateToolbar();
        }
 
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/name/operation/DeleteTypeDesignationOperation.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/name/operation/DeleteTypeDesignationOperation.java
new file mode 100755 (executable)
index 0000000..ae3e4eb
--- /dev/null
@@ -0,0 +1,69 @@
+/**
+* Copyright (C) 2019 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.ui.section.name.operation;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.operations.IUndoContext;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+
+import eu.etaxonomy.cdm.api.service.INameService;
+import eu.etaxonomy.cdm.model.name.TaxonName;
+import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
+import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
+import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
+import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+
+/**
+ *
+ * @author pplitzner
+ * @since Apr 10, 2019
+ *
+ */
+public class DeleteTypeDesignationOperation extends AbstractPostOperation<TaxonName> {
+
+    private final TypeDesignationBase<?> typeDesignation;
+
+    public DeleteTypeDesignationOperation(String label, IUndoContext undoContext, TaxonName taxonName,
+            TypeDesignationBase<?> typeDesignation, IPostOperationEnabled postOperationEnabled,
+            ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
+        super(label, undoContext, taxonName, postOperationEnabled, cdmEntitySessionEnabled);
+        this.typeDesignation = typeDesignation;
+
+    }
+
+    @Override
+    public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+        monitor.worked(20);
+        if (typeDesignation != null && typeDesignation.isPersited()){
+            if(element==null){
+                CdmStore.getService(INameService.class).deleteTypeDesignation(null, typeDesignation);
+            }
+            else{
+                CdmStore.getService(INameService.class).deleteTypeDesignation(element.getUuid(), typeDesignation.getUuid());
+            }
+            return postExecute(element);
+        }
+        return null;
+    }
+
+    @Override
+    public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+        return execute(monitor, info);
+    }
+
+    @Override
+    public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+        element.removeTypeDesignation(typeDesignation);
+        return postExecute(element);
+    }
+
+}