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.jface.viewers.TreeNode;
|
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.api.service.molecular.ISequenceService;
|
24
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
25
|
import eu.etaxonomy.cdm.model.molecular.Sequence;
|
26
|
import eu.etaxonomy.cdm.model.molecular.SingleRead;
|
27
|
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
|
28
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
29
|
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
|
30
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
31
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
32
|
|
33
|
/**
|
34
|
* @author pplitzner
|
35
|
* @date Oct 21, 2014
|
36
|
*/
|
37
|
public class DeleteDerivateOperation extends AbstractPostOperation<CdmBase> {
|
38
|
|
39
|
private final SpecimenDeleteConfigurator deleteConfigurator;
|
40
|
private final TreeNode treeNode;
|
41
|
|
42
|
public DeleteDerivateOperation(String label, IUndoContext undoContext, CdmBase element, TreeNode treeNode,
|
43
|
IPostOperationEnabled postOperationEnabled) {
|
44
|
this(label, undoContext, element, treeNode, postOperationEnabled, new SpecimenDeleteConfigurator());
|
45
|
}
|
46
|
|
47
|
public DeleteDerivateOperation(String label, IUndoContext undoContext, CdmBase element, TreeNode treeNode,
|
48
|
IPostOperationEnabled postOperationEnabled, SpecimenDeleteConfigurator config) {
|
49
|
super(label, undoContext, element, postOperationEnabled);
|
50
|
this.deleteConfigurator = config;
|
51
|
this.treeNode = treeNode;
|
52
|
}
|
53
|
|
54
|
@Override
|
55
|
public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
|
56
|
|
57
|
DeleteResult deleteResult;
|
58
|
if(element instanceof SingleRead && treeNode!=null
|
59
|
&& treeNode.getValue().equals(element)
|
60
|
&& treeNode.getParent()!=null
|
61
|
&& treeNode.getParent().getValue() instanceof Sequence){
|
62
|
deleteResult = CdmStore.getService(ISequenceService.class).deleteSingleRead(((SingleRead)element).getUuid(),
|
63
|
((Sequence) treeNode.getParent().getValue()).getUuid());
|
64
|
} else if(element instanceof Sequence){
|
65
|
deleteResult = CdmStore.getService(ISequenceService.class).delete(element.getUuid());
|
66
|
} else {
|
67
|
deleteResult = CdmStore.getService(IOccurrenceService.class).delete(element.getUuid(), deleteConfigurator);
|
68
|
}
|
69
|
|
70
|
if (!deleteResult.isOk()) {
|
71
|
MessagingUtils.warningDialog(Messages.DeleteDerivateOperation_DELETE_FAILED, this, deleteResult.toString());
|
72
|
|
73
|
return Status.CANCEL_STATUS;
|
74
|
}
|
75
|
return Status.OK_STATUS;
|
76
|
}
|
77
|
|
78
|
@Override
|
79
|
public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
|
80
|
//no redo possible
|
81
|
return Status.CANCEL_STATUS ;
|
82
|
}
|
83
|
|
84
|
@Override
|
85
|
public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
|
86
|
//no undo possible
|
87
|
return Status.CANCEL_STATUS;
|
88
|
}
|
89
|
}
|