2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.editor
.view
.derivate
.operation
;
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
;
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
;
36 public class DeleteDerivateOperation
extends AbstractPostOperation
<CdmBase
> {
38 private final SpecimenDeleteConfigurator deleteConfigurator
;
40 public DeleteDerivateOperation(String label
, IUndoContext undoContext
, CdmBase element
,
41 IPostOperationEnabled postOperationEnabled
) {
42 this(label
, undoContext
, element
, postOperationEnabled
, new SpecimenDeleteConfigurator());
45 public DeleteDerivateOperation(String label
, IUndoContext undoContext
, CdmBase element
,
46 IPostOperationEnabled postOperationEnabled
, SpecimenDeleteConfigurator config
) {
47 super(label
, undoContext
, element
, postOperationEnabled
);
48 this.deleteConfigurator
= config
;
56 * org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse
57 * .core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
61 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
) throws ExecutionException
{
62 if(getPostOperationEnabled() instanceof ISaveablePart
){
63 String confirmationQuestion
= "Do you really want to delete the selected element";
64 if(deleteConfigurator
.isDeleteChildren()){
65 confirmationQuestion
+= " and its children";
67 confirmationQuestion
+= "?";
68 if(!MessagingUtils
.confirmDialog("Confirm deletion", confirmationQuestion
)){
69 return Status
.CANCEL_STATUS
;
71 if(((ISaveablePart
) getPostOperationEnabled()).isDirty()){
72 MessagingUtils
.warningDialog("View has unsaved changes", this, "You need to save before performing this action");
73 return Status
.CANCEL_STATUS
;
76 DeleteResult deleteResult
= CdmStore
.getService(IOccurrenceService
.class).deleteDerivateHierarchy(element
, deleteConfigurator
);
77 if(deleteResult
.isOk()){
78 if(getPostOperationEnabled() instanceof DerivateView
){
79 DerivateView derivateView
= (DerivateView
) getPostOperationEnabled();
81 derivateView
.getConversationHolder().commit();
82 return postExecute(null);
86 MessagingUtils
.warningDialog("Deletion failed", this, deleteResult
.toString());
87 return Status
.CANCEL_STATUS
;
89 return Status
.OK_STATUS
;
96 * org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse
97 * .core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
101 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
) throws ExecutionException
{
103 return Status
.CANCEL_STATUS
;
110 * org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse
111 * .core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
115 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
) throws ExecutionException
{
117 return Status
.CANCEL_STATUS
;