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
|
import org.eclipse.jface.dialogs.MessageDialog;
|
21
|
import org.eclipse.ui.handlers.HandlerUtil;
|
22
|
|
23
|
import eu.etaxonomy.cdm.api.application.CdmApplicationController;
|
24
|
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
|
25
|
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
26
|
import eu.etaxonomy.cdm.api.service.IClassificationService;
|
27
|
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
|
28
|
import eu.etaxonomy.cdm.api.service.ITaxonService;
|
29
|
import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
|
30
|
import eu.etaxonomy.cdm.api.service.exception.DataChangeNoRollbackException;
|
31
|
import eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException;
|
32
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
33
|
import eu.etaxonomy.cdm.model.common.ITreeNode;
|
34
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
35
|
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
|
36
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
37
|
import eu.etaxonomy.taxeditor.operation.AbstractPersistentPostOperation;
|
38
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
39
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
40
|
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
41
|
|
42
|
/**
|
43
|
* <p>DeleteTreeNodeOperation class.</p>
|
44
|
*
|
45
|
* @author n.hoffmann
|
46
|
* @created Jan 20, 2010
|
47
|
* @version 1.0
|
48
|
*/
|
49
|
public class DeleteOperation extends AbstractPersistentPostOperation{
|
50
|
|
51
|
private Set<ITaxonTreeNode> treeNodes;
|
52
|
private TaxonDeletionConfigurator config;
|
53
|
|
54
|
|
55
|
/**
|
56
|
* <p>Constructor for DeleteTreeNodeOperation.</p>
|
57
|
*
|
58
|
* @param label a {@link java.lang.String} object.
|
59
|
* @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
|
60
|
* @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
|
61
|
* @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
|
62
|
* @param treeNodes a {@link java.util.Set} object.
|
63
|
*/
|
64
|
public DeleteOperation(String label, IUndoContext undoContext,
|
65
|
ITaxonTreeNode taxonNode, TaxonDeletionConfigurator config,
|
66
|
IPostOperationEnabled postOperationEnabled,
|
67
|
IConversationEnabled conversationEnabled) {
|
68
|
super(label, undoContext, postOperationEnabled, conversationEnabled);
|
69
|
this.taxonNode = (ITaxonTreeNode)CdmBase.deproxy(taxonNode, CdmBase.class);
|
70
|
this.config = config;
|
71
|
}
|
72
|
|
73
|
/**
|
74
|
* <p>Constructor for DeleteTreeNodeOperation.</p>
|
75
|
*
|
76
|
* @param label a {@link java.lang.String} object.
|
77
|
* @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
|
78
|
* @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
|
79
|
* @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
|
80
|
* @param treeNodes a {@link java.util.Set} object.
|
81
|
*/
|
82
|
public DeleteOperation(String label, IUndoContext undoContext,
|
83
|
Set<ITaxonTreeNode> treeNodes, TaxonDeletionConfigurator config,
|
84
|
IPostOperationEnabled postOperationEnabled,
|
85
|
IConversationEnabled conversationEnabled) {
|
86
|
super(label, undoContext, postOperationEnabled, conversationEnabled);
|
87
|
this.treeNodes = treeNodes;
|
88
|
this.config = config;
|
89
|
}
|
90
|
|
91
|
|
92
|
/* (non-Javadoc)
|
93
|
* @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
94
|
*/
|
95
|
/** {@inheritDoc} */
|
96
|
@Override
|
97
|
public IStatus execute(IProgressMonitor monitor, IAdaptable info)
|
98
|
throws ExecutionException {
|
99
|
|
100
|
bind();
|
101
|
monitor.worked(20);
|
102
|
ICdmApplicationConfiguration controller = CdmStore.getCurrentApplicationConfiguration();
|
103
|
ITaxonNodeService service = controller.getTaxonNodeService();
|
104
|
if(taxonNode != null && taxonNode instanceof TaxonNode){
|
105
|
//((TaxonNode) treeNode).delete();
|
106
|
|
107
|
taxon = ((TaxonNode)taxonNode).getTaxon();
|
108
|
try {
|
109
|
service.deleteTaxonNode((TaxonNode)taxonNode, config);
|
110
|
} catch (DataChangeNoRollbackException e) {
|
111
|
|
112
|
throw new ExecutionException(e.getMessage());
|
113
|
|
114
|
}
|
115
|
|
116
|
}else if(taxonNode != null && taxonNode instanceof Classification){
|
117
|
Classification taxonomicTree = (Classification) taxonNode;
|
118
|
/*if(taxonomicTree.hasChildNodes()){
|
119
|
if(! MessageDialog.openConfirm(null, "Confirm Deletion", "The selected tree has children, do yu realy want to delete the whole tree with its children?")){
|
120
|
return null;
|
121
|
}
|
122
|
}*/
|
123
|
try{
|
124
|
CdmStore.getService(IClassificationService.class).delete(taxonomicTree);
|
125
|
}catch(ReferencedObjectUndeletableException e){
|
126
|
throw new ExecutionException(e.getMessage());
|
127
|
}
|
128
|
|
129
|
|
130
|
/*}else{
|
131
|
try{
|
132
|
CdmStore.getService(IClassificationService.class).delete(taxonomicTree);
|
133
|
}catch(ReferencedObjectUndeletableException e){
|
134
|
throw new ExecutionException(e.getMessage());
|
135
|
}
|
136
|
}*/
|
137
|
} else {
|
138
|
try {
|
139
|
service.deleteTaxonNodes(treeNodes, config);
|
140
|
} catch (DataChangeNoRollbackException e) {
|
141
|
throw new ExecutionException(e.getMessage());
|
142
|
}
|
143
|
}
|
144
|
|
145
|
monitor.worked(40);
|
146
|
return postExecute(null);
|
147
|
}
|
148
|
|
149
|
/* (non-Javadoc)
|
150
|
* @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
151
|
*/
|
152
|
/** {@inheritDoc} */
|
153
|
@Override
|
154
|
public IStatus redo(IProgressMonitor monitor, IAdaptable info)
|
155
|
throws ExecutionException {
|
156
|
return null;
|
157
|
}
|
158
|
|
159
|
/* (non-Javadoc)
|
160
|
* @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
161
|
*/
|
162
|
/** {@inheritDoc} */
|
163
|
@Override
|
164
|
public IStatus undo(IProgressMonitor monitor, IAdaptable info)
|
165
|
throws ExecutionException {
|
166
|
return null;
|
167
|
}
|
168
|
}
|