1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.taxeditor.navigation.navigator.operation;
|
12
|
|
13
|
import java.util.Set;
|
14
|
|
15
|
import org.eclipse.core.commands.ExecutionException;
|
16
|
import org.eclipse.core.commands.operations.IUndoContext;
|
17
|
import org.eclipse.core.runtime.IAdaptable;
|
18
|
import org.eclipse.core.runtime.IProgressMonitor;
|
19
|
import org.eclipse.core.runtime.IStatus;
|
20
|
|
21
|
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
22
|
import eu.etaxonomy.cdm.api.service.IClassificationService;
|
23
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
24
|
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
|
25
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
26
|
import eu.etaxonomy.taxeditor.operation.AbstractPersistentPostOperation;
|
27
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
28
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
29
|
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
30
|
|
31
|
/**
|
32
|
* <p>DeleteTreeNodeOperation class.</p>
|
33
|
*
|
34
|
* @author n.hoffmann
|
35
|
* @created Jan 20, 2010
|
36
|
* @version 1.0
|
37
|
*/
|
38
|
public class DeleteOperation extends AbstractPersistentPostOperation{
|
39
|
|
40
|
private Set<ITaxonTreeNode> treeNodes;
|
41
|
|
42
|
|
43
|
/**
|
44
|
* <p>Constructor for DeleteTreeNodeOperation.</p>
|
45
|
*
|
46
|
* @param label a {@link java.lang.String} object.
|
47
|
* @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
|
48
|
* @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
|
49
|
* @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
|
50
|
* @param treeNodes a {@link java.util.Set} object.
|
51
|
*/
|
52
|
public DeleteOperation(String label, IUndoContext undoContext,
|
53
|
Set<ITaxonTreeNode> treeNodes,
|
54
|
IPostOperationEnabled postOperationEnabled,
|
55
|
IConversationEnabled conversationEnabled) {
|
56
|
super(label, undoContext, postOperationEnabled, conversationEnabled);
|
57
|
this.treeNodes = treeNodes;
|
58
|
}
|
59
|
|
60
|
|
61
|
/* (non-Javadoc)
|
62
|
* @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
63
|
*/
|
64
|
/** {@inheritDoc} */
|
65
|
@Override
|
66
|
public IStatus execute(IProgressMonitor monitor, IAdaptable info)
|
67
|
throws ExecutionException {
|
68
|
|
69
|
bind();
|
70
|
monitor.worked(20);
|
71
|
for (ITaxonTreeNode treeNode : treeNodes){
|
72
|
if(treeNode instanceof TaxonNode){
|
73
|
((TaxonNode) treeNode).delete();
|
74
|
}else if(treeNode instanceof Classification){
|
75
|
Classification taxonomicTree = (Classification) treeNode;
|
76
|
if(taxonomicTree.hasChildNodes()){
|
77
|
StoreUtil.warningDialog("Tree is not empty", this, "It is not possible to delete a Taxonomic Tree that " +
|
78
|
"is not empty. Please delete included taxa first");
|
79
|
}else{
|
80
|
CdmStore.getService(IClassificationService.class).delete(taxonomicTree);
|
81
|
}
|
82
|
}
|
83
|
}
|
84
|
monitor.worked(40);
|
85
|
return postExecute(null);
|
86
|
}
|
87
|
|
88
|
/* (non-Javadoc)
|
89
|
* @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
90
|
*/
|
91
|
/** {@inheritDoc} */
|
92
|
@Override
|
93
|
public IStatus redo(IProgressMonitor monitor, IAdaptable info)
|
94
|
throws ExecutionException {
|
95
|
return null;
|
96
|
}
|
97
|
|
98
|
/* (non-Javadoc)
|
99
|
* @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
100
|
*/
|
101
|
/** {@inheritDoc} */
|
102
|
@Override
|
103
|
public IStatus undo(IProgressMonitor monitor, IAdaptable info)
|
104
|
throws ExecutionException {
|
105
|
return null;
|
106
|
}
|
107
|
}
|