Merge branch 'release/5.19.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / view / descriptive / operation / DeleteSpecimenDescriptionOperation.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9 package eu.etaxonomy.taxeditor.editor.view.descriptive.operation;
10
11 import org.eclipse.core.commands.ExecutionException;
12 import org.eclipse.core.commands.operations.IUndoContext;
13 import org.eclipse.core.runtime.IAdaptable;
14 import org.eclipse.core.runtime.IProgressMonitor;
15 import org.eclipse.core.runtime.IStatus;
16
17 import eu.etaxonomy.cdm.api.service.IDescriptionService;
18 import eu.etaxonomy.cdm.model.description.SpecimenDescription;
19 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
20 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
21 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
22 import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
23 import eu.etaxonomy.taxeditor.store.CdmStore;
24
25 /**
26 * @author pplitzner
27 * @date Jan 15, 2015
28 */
29 public class DeleteSpecimenDescriptionOperation
30 extends AbstractPostOperation<SpecimenOrObservationBase<?>> {
31
32 private final SpecimenDescription description;
33
34 public DeleteSpecimenDescriptionOperation(String label,
35 IUndoContext undoContext,
36 SpecimenDescription description,
37 IPostOperationEnabled postOperationEnabled,
38 ICdmEntitySessionEnabled<SpecimenOrObservationBase<?>> cdmEntitySessionEnabled) {
39 super(label, undoContext, description.getDescribedSpecimenOrObservation(), postOperationEnabled, cdmEntitySessionEnabled);
40 this.description = description;
41 }
42
43 @Override
44 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
45 throws ExecutionException {
46
47 monitor.worked(40);
48 CdmStore.getService(IDescriptionService.class).deleteDescription(description.getUuid());
49
50 return postExecute(description);
51 }
52
53 @Override
54 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
55 throws ExecutionException {
56 return execute(monitor, info);
57 }
58
59 @Override
60 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
61 throws ExecutionException {
62
63 element.addDescription(description);
64
65 return postExecute(null);
66 }
67 }