5032dde4168c692c542897a6675c5be41ed89a75
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / view / derivate / operation / DeleteDerivateOperation.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
10 package eu.etaxonomy.taxeditor.editor.view.derivate.operation;
11
12 import org.eclipse.core.commands.ExecutionException;
13 import org.eclipse.core.commands.operations.IUndoContext;
14 import org.eclipse.core.runtime.IAdaptable;
15 import org.eclipse.core.runtime.IProgressMonitor;
16 import org.eclipse.core.runtime.IStatus;
17
18 import eu.etaxonomy.cdm.api.service.DeleteResult;
19 import eu.etaxonomy.cdm.api.service.IOccurrenceService;
20 import eu.etaxonomy.cdm.api.service.config.SpecimenDeleteConfigurator;
21 import eu.etaxonomy.cdm.model.common.CdmBase;
22 import eu.etaxonomy.taxeditor.model.MessagingUtils;
23 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
24 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
25 import eu.etaxonomy.taxeditor.store.CdmStore;
26
27 /**
28 *
29 * @author pplitzner
30 * @date Oct 21, 2014
31 *
32 */
33 public class DeleteDerivateOperation extends AbstractPostOperation<CdmBase> {
34
35 private final SpecimenDeleteConfigurator deleteConfigurator;
36
37 public DeleteDerivateOperation(String label, IUndoContext undoContext, CdmBase element,
38 IPostOperationEnabled postOperationEnabled) {
39 this(label, undoContext, element, postOperationEnabled, new SpecimenDeleteConfigurator());
40 }
41
42 public DeleteDerivateOperation(String label, IUndoContext undoContext, CdmBase element,
43 IPostOperationEnabled postOperationEnabled, SpecimenDeleteConfigurator config) {
44 super(label, undoContext, element, postOperationEnabled);
45 this.deleteConfigurator = config;
46 }
47
48
49 /*
50 * (non-Javadoc)
51 *
52 * @see
53 * org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse
54 * .core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
55 */
56 /** {@inheritDoc} */
57 @Override
58 public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
59 DeleteResult deleteResult = CdmStore.getService(IOccurrenceService.class).deleteDerivateHierarchy(element, deleteConfigurator);
60 if(!deleteResult.isOk()){
61 String exceptionMessage = "";
62 for(Exception exception:deleteResult.getExceptions()){
63 exceptionMessage += exception.getLocalizedMessage();
64 }
65 //TODO: add method to DeleteResult to sum up exceptions
66 MessagingUtils.warningDialog("Deletion failed", this, exceptionMessage);
67 return postExecute(null);
68 }
69 return postExecute(element);
70 }
71
72 /*
73 * (non-Javadoc)
74 *
75 * @see
76 * org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse
77 * .core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
78 */
79 /** {@inheritDoc} */
80 @Override
81 public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
82 return execute(monitor, info);
83 }
84
85 /*
86 * (non-Javadoc)
87 *
88 * @see
89 * org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse
90 * .core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
91 */
92 /** {@inheritDoc} */
93 @Override
94 public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
95 return postExecute(element);
96 }
97 }