678b43e4089603b4e7453f52ef5abb1e6562b858
[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 import org.eclipse.core.runtime.Status;
18 import org.eclipse.ui.ISaveablePart;
19
20 import eu.etaxonomy.cdm.api.service.DeleteResult;
21 import eu.etaxonomy.cdm.api.service.IOccurrenceService;
22 import eu.etaxonomy.cdm.api.service.config.SpecimenDeleteConfigurator;
23 import eu.etaxonomy.cdm.model.common.CdmBase;
24 import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView;
25 import eu.etaxonomy.taxeditor.model.MessagingUtils;
26 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
27 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
28 import eu.etaxonomy.taxeditor.store.CdmStore;
29
30 /**
31 *
32 * @author pplitzner
33 * @date Oct 21, 2014
34 *
35 */
36 public class DeleteDerivateOperation extends AbstractPostOperation<CdmBase> {
37
38 private final SpecimenDeleteConfigurator deleteConfigurator;
39
40 public DeleteDerivateOperation(String label, IUndoContext undoContext, CdmBase element,
41 IPostOperationEnabled postOperationEnabled) {
42 this(label, undoContext, element, postOperationEnabled, new SpecimenDeleteConfigurator());
43 }
44
45 public DeleteDerivateOperation(String label, IUndoContext undoContext, CdmBase element,
46 IPostOperationEnabled postOperationEnabled, SpecimenDeleteConfigurator config) {
47 super(label, undoContext, element, postOperationEnabled);
48 this.deleteConfigurator = config;
49 }
50
51
52 /*
53 * (non-Javadoc)
54 *
55 * @see
56 * org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse
57 * .core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
58 */
59 /** {@inheritDoc} */
60 @Override
61 public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
62 if(getPostOperationEnabled() instanceof ISaveablePart){
63 if(!MessagingUtils.confirmDialog("Confirm deletion", "Do you really want to delete the selected element?")){
64 return Status.CANCEL_STATUS;
65 }
66 if(((ISaveablePart) getPostOperationEnabled()).isDirty()){
67 MessagingUtils.warningDialog("View has unsaved changes", this, "You need to save before performing this action");
68 return Status.CANCEL_STATUS;
69 }
70 }
71 DeleteResult deleteResult = CdmStore.getService(IOccurrenceService.class).deleteDerivateHierarchy(element, deleteConfigurator);
72 if(deleteResult.isOk()){
73 if(getPostOperationEnabled() instanceof DerivateView){
74 DerivateView derivateView = (DerivateView) getPostOperationEnabled();
75 //update DerivateView
76 derivateView.getConversationHolder().commit();
77 return postExecute(null);
78 }
79 }
80 else{
81 MessagingUtils.warningDialog("Deletion failed", this, deleteResult.toString());
82 return Status.CANCEL_STATUS;
83 }
84 return Status.OK_STATUS;
85 }
86
87 /*
88 * (non-Javadoc)
89 *
90 * @see
91 * org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse
92 * .core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
93 */
94 /** {@inheritDoc} */
95 @Override
96 public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
97 //no redo possible
98 return Status.CANCEL_STATUS ;
99 }
100
101 /*
102 * (non-Javadoc)
103 *
104 * @see
105 * org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse
106 * .core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
107 */
108 /** {@inheritDoc} */
109 @Override
110 public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
111 //no undo possible
112 return Status.CANCEL_STATUS;
113 }
114 }