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.navigation.navigator.operation;
|
11
|
|
12
|
import java.util.HashSet;
|
13
|
import java.util.Set;
|
14
|
import java.util.UUID;
|
15
|
|
16
|
import org.eclipse.core.commands.ExecutionException;
|
17
|
import org.eclipse.core.commands.operations.IUndoContext;
|
18
|
import org.eclipse.core.runtime.IAdaptable;
|
19
|
import org.eclipse.core.runtime.IProgressMonitor;
|
20
|
import org.eclipse.core.runtime.IStatus;
|
21
|
|
22
|
import eu.etaxonomy.cdm.api.application.ICdmRepository;
|
23
|
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
24
|
import eu.etaxonomy.cdm.api.service.DeleteResult;
|
25
|
import eu.etaxonomy.cdm.api.service.IClassificationService;
|
26
|
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
|
27
|
import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
|
28
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
29
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
30
|
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
|
31
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
32
|
import eu.etaxonomy.taxeditor.model.DeleteResultMessagingUtils;
|
33
|
import eu.etaxonomy.taxeditor.navigation.internal.TaxeditorNavigationPlugin;
|
34
|
import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
|
35
|
import eu.etaxonomy.taxeditor.operation.AbstractPersistentPostOperation;
|
36
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
37
|
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
|
38
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
39
|
|
40
|
/**
|
41
|
* <p>DeleteTreeNodeOperation class.</p>
|
42
|
*
|
43
|
* @author n.hoffmann
|
44
|
* @created Jan 20, 2010
|
45
|
* @version 1.0
|
46
|
*/
|
47
|
public class DeleteOperation extends AbstractPersistentPostOperation{
|
48
|
|
49
|
private static final String TAXON_NODE_COULD_NOT_BE_DELETED = Messages.DeleteOperation_DELETE_FAIL;
|
50
|
private Set<ITaxonTreeNode> treeNodes;
|
51
|
protected final TaxonDeletionConfigurator config;
|
52
|
private final ICdmEntitySessionEnabled cdmEntitySessionEnabled;
|
53
|
|
54
|
/**
|
55
|
* <p>Constructor for DeleteTreeNodeOperation.</p>
|
56
|
*
|
57
|
* @param label a {@link java.lang.String} object.
|
58
|
* @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
|
59
|
* @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
|
60
|
* @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
|
61
|
* @param treeNodes a {@link java.util.Set} object.
|
62
|
*/
|
63
|
public DeleteOperation(String label, IUndoContext undoContext,
|
64
|
ITaxonTreeNode taxonNode, TaxonDeletionConfigurator config,
|
65
|
IPostOperationEnabled postOperationEnabled,
|
66
|
IConversationEnabled conversationEnabled,
|
67
|
ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
|
68
|
super(label, undoContext, postOperationEnabled, conversationEnabled, cdmEntitySessionEnabled);
|
69
|
this.taxonNode = (ITaxonTreeNode)CdmBase.deproxy(taxonNode, CdmBase.class);
|
70
|
this.config = config;
|
71
|
this.cdmEntitySessionEnabled = cdmEntitySessionEnabled;
|
72
|
}
|
73
|
|
74
|
/**
|
75
|
* <p>Constructor for DeleteTreeNodeOperation.</p>
|
76
|
*
|
77
|
* @param label a {@link java.lang.String} object.
|
78
|
* @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
|
79
|
* @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
|
80
|
* @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
|
81
|
* @param treeNodes a {@link java.util.Set} object.
|
82
|
*/
|
83
|
public DeleteOperation(String label, IUndoContext undoContext,
|
84
|
Set<ITaxonTreeNode> treeNodes, TaxonDeletionConfigurator config,
|
85
|
IPostOperationEnabled postOperationEnabled,
|
86
|
IConversationEnabled conversationEnabled,
|
87
|
ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
|
88
|
super(label, undoContext, postOperationEnabled, conversationEnabled, cdmEntitySessionEnabled);
|
89
|
this.treeNodes = treeNodes;
|
90
|
this.config = config;
|
91
|
this.cdmEntitySessionEnabled = cdmEntitySessionEnabled;
|
92
|
}
|
93
|
|
94
|
|
95
|
|
96
|
|
97
|
/* (non-Javadoc)
|
98
|
* @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
99
|
*/
|
100
|
/** {@inheritDoc} */
|
101
|
@Override
|
102
|
public IStatus execute(IProgressMonitor monitor, IAdaptable info)
|
103
|
throws ExecutionException {
|
104
|
|
105
|
bind();
|
106
|
monitor.worked(20);
|
107
|
ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
|
108
|
ITaxonNodeService service = controller.getTaxonNodeService();
|
109
|
if(taxonNode != null && taxonNode instanceof TaxonNode){
|
110
|
//((TaxonNode) treeNode).delete();
|
111
|
|
112
|
element = ((TaxonNode)taxonNode).getTaxon();
|
113
|
|
114
|
DeleteResult result = service.deleteTaxonNode((TaxonNode)taxonNode, config);
|
115
|
if (result.isError() && !result.getExceptions().isEmpty()){
|
116
|
|
117
|
DeleteResultMessagingUtils.messageDialogWithDetails(result, TAXON_NODE_COULD_NOT_BE_DELETED, TaxeditorNavigationPlugin.PLUGIN_ID);
|
118
|
} else if (!result.getExceptions().isEmpty()){
|
119
|
String separator = ", "; //$NON-NLS-1$
|
120
|
String exceptionString = ""; //$NON-NLS-1$
|
121
|
for (Exception exception : result.getExceptions()) {
|
122
|
exceptionString += exception.getLocalizedMessage()+separator;
|
123
|
}
|
124
|
DeleteResultMessagingUtils.messageDialogWithDetails(result, Messages.DeleteOperation_DELETE_SUCCESS, TaxeditorNavigationPlugin.PLUGIN_ID);
|
125
|
}
|
126
|
|
127
|
|
128
|
}else if(taxonNode != null && taxonNode instanceof Classification){
|
129
|
Classification taxonomicTree = (Classification) taxonNode;
|
130
|
|
131
|
DeleteResult result = CdmStore.getService(IClassificationService.class).delete(taxonomicTree.getUuid());
|
132
|
if (result.isError() && !result.getExceptions().isEmpty()){
|
133
|
//TODO:Error message!
|
134
|
DeleteResultMessagingUtils.messageDialogWithDetails(result, TAXON_NODE_COULD_NOT_BE_DELETED, TaxeditorNavigationPlugin.PLUGIN_ID);
|
135
|
}
|
136
|
} else {
|
137
|
Set<UUID> treeNodeUuids = new HashSet<UUID>();
|
138
|
ITaxonTreeNode entity = null;
|
139
|
for(ITaxonTreeNode treeNode : treeNodes) {
|
140
|
if(entity == null) {
|
141
|
entity = treeNode;
|
142
|
}
|
143
|
treeNodeUuids.add(treeNode.getUuid());
|
144
|
}
|
145
|
|
146
|
DeleteResult result = service.deleteTaxonNodes(treeNodeUuids, config);
|
147
|
if (result.isError() && !result.getExceptions().isEmpty()){
|
148
|
//TODO:Error message!
|
149
|
DeleteResultMessagingUtils.messageDialogWithDetails(result, TAXON_NODE_COULD_NOT_BE_DELETED, TaxeditorNavigationPlugin.PLUGIN_ID);
|
150
|
}
|
151
|
|
152
|
}
|
153
|
|
154
|
monitor.worked(40);
|
155
|
|
156
|
return postExecute(null);
|
157
|
}
|
158
|
|
159
|
/* (non-Javadoc)
|
160
|
* @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
161
|
*/
|
162
|
/** {@inheritDoc} */
|
163
|
@Override
|
164
|
public IStatus redo(IProgressMonitor monitor, IAdaptable info)
|
165
|
throws ExecutionException {
|
166
|
return null;
|
167
|
}
|
168
|
|
169
|
/* (non-Javadoc)
|
170
|
* @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
171
|
*/
|
172
|
/** {@inheritDoc} */
|
173
|
@Override
|
174
|
public IStatus undo(IProgressMonitor monitor, IAdaptable info)
|
175
|
throws ExecutionException {
|
176
|
return null;
|
177
|
}
|
178
|
}
|