Revision 4b242b1d
Added by Cherian Mathew over 8 years ago
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/DeleteOperation.java | ||
---|---|---|
1 | 1 |
// $Id$ |
2 | 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 |
*/ |
|
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 | 10 |
|
11 | 11 |
package eu.etaxonomy.taxeditor.navigation.navigator.operation; |
12 | 12 |
|
13 |
import java.util.HashSet; |
|
13 | 14 |
import java.util.Set; |
15 |
import java.util.UUID; |
|
14 | 16 |
|
15 | 17 |
import org.eclipse.core.commands.ExecutionException; |
16 | 18 |
import org.eclipse.core.commands.operations.IUndoContext; |
... | ... | |
29 | 31 |
import eu.etaxonomy.cdm.model.taxon.Classification; |
30 | 32 |
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode; |
31 | 33 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode; |
32 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
|
33 | 34 |
import eu.etaxonomy.taxeditor.operation.AbstractPersistentPostOperation; |
34 | 35 |
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled; |
36 |
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled; |
|
35 | 37 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
36 | 38 |
|
37 | 39 |
/** |
... | ... | |
43 | 45 |
*/ |
44 | 46 |
public class DeleteOperation extends AbstractPersistentPostOperation{ |
45 | 47 |
|
46 |
private Set<ITaxonTreeNode> treeNodes; |
|
47 |
protected final TaxonDeletionConfigurator config; |
|
48 |
private Set<ITaxonTreeNode> treeNodes; |
|
49 |
protected final TaxonDeletionConfigurator config; |
|
50 |
private final ICdmEntitySessionEnabled cdmEntitySessionEnabled; |
|
51 |
|
|
52 |
/** |
|
53 |
* <p>Constructor for DeleteTreeNodeOperation.</p> |
|
54 |
* |
|
55 |
* @param label a {@link java.lang.String} object. |
|
56 |
* @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object. |
|
57 |
* @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object. |
|
58 |
* @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object. |
|
59 |
* @param treeNodes a {@link java.util.Set} object. |
|
60 |
*/ |
|
61 |
public DeleteOperation(String label, IUndoContext undoContext, |
|
62 |
ITaxonTreeNode taxonNode, TaxonDeletionConfigurator config, |
|
63 |
IPostOperationEnabled postOperationEnabled, |
|
64 |
IConversationEnabled conversationEnabled, |
|
65 |
ICdmEntitySessionEnabled cdmEntitySessionEnabled) { |
|
66 |
super(label, undoContext, postOperationEnabled, conversationEnabled, cdmEntitySessionEnabled); |
|
67 |
this.taxonNode = (ITaxonTreeNode)CdmBase.deproxy(taxonNode, CdmBase.class); |
|
68 |
this.config = config; |
|
69 |
this.cdmEntitySessionEnabled = cdmEntitySessionEnabled; |
|
70 |
} |
|
71 |
|
|
72 |
/** |
|
73 |
* <p>Constructor for DeleteTreeNodeOperation.</p> |
|
74 |
* |
|
75 |
* @param label a {@link java.lang.String} object. |
|
76 |
* @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object. |
|
77 |
* @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object. |
|
78 |
* @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object. |
|
79 |
* @param treeNodes a {@link java.util.Set} object. |
|
80 |
*/ |
|
81 |
public DeleteOperation(String label, IUndoContext undoContext, |
|
82 |
Set<ITaxonTreeNode> treeNodes, TaxonDeletionConfigurator config, |
|
83 |
IPostOperationEnabled postOperationEnabled, |
|
84 |
IConversationEnabled conversationEnabled, |
|
85 |
ICdmEntitySessionEnabled cdmEntitySessionEnabled) { |
|
86 |
super(label, undoContext, postOperationEnabled, conversationEnabled, cdmEntitySessionEnabled); |
|
87 |
this.treeNodes = treeNodes; |
|
88 |
this.config = config; |
|
89 |
this.cdmEntitySessionEnabled = cdmEntitySessionEnabled; |
|
90 |
} |
|
48 | 91 |
|
49 | 92 |
|
50 |
/** |
|
51 |
* <p>Constructor for DeleteTreeNodeOperation.</p> |
|
52 |
* |
|
53 |
* @param label a {@link java.lang.String} object. |
|
54 |
* @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object. |
|
55 |
* @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object. |
|
56 |
* @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object. |
|
57 |
* @param treeNodes a {@link java.util.Set} object. |
|
58 |
*/ |
|
59 |
public DeleteOperation(String label, IUndoContext undoContext, |
|
60 |
ITaxonTreeNode taxonNode, TaxonDeletionConfigurator config, |
|
61 |
IPostOperationEnabled postOperationEnabled, |
|
62 |
IConversationEnabled conversationEnabled) { |
|
63 |
super(label, undoContext, postOperationEnabled, conversationEnabled); |
|
64 |
this.taxonNode = (ITaxonTreeNode)CdmBase.deproxy(taxonNode, CdmBase.class); |
|
65 |
this.config = config; |
|
66 |
} |
|
67 |
|
|
68 |
/** |
|
69 |
* <p>Constructor for DeleteTreeNodeOperation.</p> |
|
70 |
* |
|
71 |
* @param label a {@link java.lang.String} object. |
|
72 |
* @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object. |
|
73 |
* @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object. |
|
74 |
* @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object. |
|
75 |
* @param treeNodes a {@link java.util.Set} object. |
|
76 |
*/ |
|
77 |
public DeleteOperation(String label, IUndoContext undoContext, |
|
78 |
Set<ITaxonTreeNode> treeNodes, TaxonDeletionConfigurator config, |
|
79 |
IPostOperationEnabled postOperationEnabled, |
|
80 |
IConversationEnabled conversationEnabled) { |
|
81 |
super(label, undoContext, postOperationEnabled, conversationEnabled); |
|
82 |
this.treeNodes = treeNodes; |
|
83 |
this.config = config; |
|
84 |
} |
|
85 | 93 |
|
86 | 94 |
|
87 | 95 |
/* (non-Javadoc) |
... | ... | |
108 | 116 |
} else if (!result.getExceptions().isEmpty()){ |
109 | 117 |
String separator = ", "; |
110 | 118 |
String exceptionString = ""; |
111 |
int count = 1; |
|
112 | 119 |
for (Exception exception : result.getExceptions()) { |
113 |
exceptionString += exception.getLocalizedMessage(); |
|
114 |
if (count < result.getExceptions().size()){ |
|
115 |
exceptionString += separator; |
|
116 |
} |
|
120 |
exceptionString += exception.getLocalizedMessage()+separator; |
|
117 | 121 |
} |
118 |
MessagingUtils.informationDialog("Delete of the node was successful but the taxon could not be deleted.", exceptionString);
|
|
122 |
MessageDialog.openInformation(null, "Delete of the node was successful but the taxon could not be deleted.", exceptionString);
|
|
119 | 123 |
} |
120 | 124 |
|
121 | 125 |
|
122 | 126 |
}else if(taxonNode != null && taxonNode instanceof Classification){ |
123 | 127 |
Classification taxonomicTree = (Classification) taxonNode; |
124 |
/*if(taxonomicTree.hasChildNodes()){ |
|
125 |
if(! MessageDialog.openConfirm(null, "Confirm Deletion", "The selected tree has children, do yu realy want to delete the whole tree with its children?")){ |
|
126 |
return null; |
|
127 |
} |
|
128 |
}*/ |
|
129 | 128 |
|
130 |
DeleteResult result = CdmStore.getService(IClassificationService.class).delete(taxonomicTree); |
|
131 |
if (result.isError() && !result.getExceptions().isEmpty()){ |
|
132 |
String separator = ", "; |
|
133 |
String exceptionString = ""; |
|
134 |
for (Exception exception : result.getExceptions()) { |
|
135 |
exceptionString += exception.getLocalizedMessage()+separator; |
|
136 |
} |
|
137 |
MessagingUtils.error(null, exceptionString, result.getExceptions().iterator().next()); |
|
138 |
} |
|
139 |
|
|
140 |
/*}else{ |
|
141 |
try{ |
|
142 |
CdmStore.getService(IClassificationService.class).delete(taxonomicTree); |
|
143 |
}catch(ReferencedObjectUndeletableException e){ |
|
144 |
throw new ExecutionException(e.getMessage()); |
|
145 |
} |
|
146 |
}*/ |
|
147 |
} else { |
|
148 |
|
|
149 |
DeleteResult result =service.deleteTaxonNodes(treeNodes, config); |
|
150 |
if (result.isError() && !result.getExceptions().isEmpty()){ |
|
151 |
String separator = ", "; |
|
152 |
String exceptionString = ""; |
|
153 |
for (Exception exception : result.getExceptions()) { |
|
154 |
exceptionString += exception.getLocalizedMessage()+separator; |
|
155 |
} |
|
156 |
MessagingUtils.error(null, exceptionString, result.getExceptions().iterator().next()); |
|
157 |
} |
|
129 |
DeleteResult result = CdmStore.getService(IClassificationService.class).delete(taxonomicTree.getUuid()); |
|
130 |
if (result.isError() && !result.getExceptions().isEmpty()){ |
|
131 |
//TODO:Error message! |
|
132 |
MessageDialog.openError(null, "Delete failed", result.getExceptions().iterator().next().getMessage()); |
|
133 |
} |
|
134 |
} else { |
|
135 |
Set<UUID> treeNodeUuids = new HashSet<UUID>(); |
|
136 |
ITaxonTreeNode entity = null; |
|
137 |
for(ITaxonTreeNode treeNode : treeNodes) { |
|
138 |
if(entity == null) { |
|
139 |
entity = treeNode; |
|
140 |
} |
|
141 |
treeNodeUuids.add(treeNode.getUuid()); |
|
142 |
} |
|
143 |
|
|
144 |
DeleteResult result = service.deleteTaxonNodes(treeNodeUuids, config); |
|
145 |
if (result.isError() && !result.getExceptions().isEmpty()){ |
|
146 |
//TODO:Error message! |
|
147 |
MessageDialog.openError(null, "Delete failed", result.getExceptions().iterator().next().getMessage()); |
|
158 | 148 |
} |
159 | 149 |
|
160 |
monitor.worked(40); |
|
161 |
return postExecute(null); |
|
162 |
} |
|
163 |
|
|
164 |
/* (non-Javadoc) |
|
165 |
* @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable) |
|
166 |
*/ |
|
167 |
/** {@inheritDoc} */ |
|
168 |
@Override |
|
169 |
public IStatus redo(IProgressMonitor monitor, IAdaptable info) |
|
170 |
throws ExecutionException { |
|
171 |
return null; |
|
172 |
} |
|
173 |
|
|
174 |
/* (non-Javadoc) |
|
175 |
* @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable) |
|
176 |
*/ |
|
177 |
/** {@inheritDoc} */ |
|
178 |
@Override |
|
179 |
public IStatus undo(IProgressMonitor monitor, IAdaptable info) |
|
180 |
throws ExecutionException { |
|
181 |
return null; |
|
182 |
} |
|
150 |
} |
|
151 |
|
|
152 |
monitor.worked(40); |
|
153 |
|
|
154 |
return postExecute(null); |
|
155 |
} |
|
156 |
|
|
157 |
/* (non-Javadoc) |
|
158 |
* @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable) |
|
159 |
*/ |
|
160 |
/** {@inheritDoc} */ |
|
161 |
@Override |
|
162 |
public IStatus redo(IProgressMonitor monitor, IAdaptable info) |
|
163 |
throws ExecutionException { |
|
164 |
return null; |
|
165 |
} |
|
166 |
|
|
167 |
/* (non-Javadoc) |
|
168 |
* @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable) |
|
169 |
*/ |
|
170 |
/** {@inheritDoc} */ |
|
171 |
@Override |
|
172 |
public IStatus undo(IProgressMonitor monitor, IAdaptable info) |
|
173 |
throws ExecutionException { |
|
174 |
return null; |
|
175 |
} |
|
183 | 176 |
} |
Also available in: Unified diff
Correct merge