3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.taxeditor
.navigation
.navigator
.operation
;
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
;
22 import eu
.etaxonomy
.cdm
.api
.application
.ICdmApplicationConfiguration
;
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
.MessagingUtils
;
33 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPersistentPostOperation
;
34 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
35 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
38 * <p>DeleteTreeNodeOperation class.</p>
41 * @created Jan 20, 2010
44 public class DeleteOperation
extends AbstractPersistentPostOperation
{
46 private Set
<ITaxonTreeNode
> treeNodes
;
47 protected final TaxonDeletionConfigurator config
;
51 * <p>Constructor for DeleteTreeNodeOperation.</p>
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.
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);
69 * <p>Constructor for DeleteTreeNodeOperation.</p>
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.
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
;
88 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
92 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
93 throws ExecutionException
{
97 ICdmApplicationConfiguration controller
= CdmStore
.getCurrentApplicationConfiguration();
98 ITaxonNodeService service
= controller
.getTaxonNodeService();
99 if(taxonNode
!= null && taxonNode
instanceof TaxonNode
){
100 //((TaxonNode) treeNode).delete();
102 element
= ((TaxonNode
)taxonNode
).getTaxon();
104 DeleteResult result
= service
.deleteTaxonNode((TaxonNode
)taxonNode
, config
);
105 if (result
.isError() && !result
.getExceptions().isEmpty()){
106 //TODO:Error message!
107 MessageDialog
.openError(null, "Delete failed", result
.getExceptions().iterator().next().getMessage());
108 } else if (!result
.getExceptions().isEmpty()){
109 String separator
= ", ";
110 String exceptionString
= "";
112 for (Exception exception
: result
.getExceptions()) {
113 exceptionString
+= exception
.getLocalizedMessage();
114 if (count
< result
.getExceptions().size()){
115 exceptionString
+= separator
;
118 MessagingUtils
.informationDialog("Delete of the node was successful but the taxon could not be deleted.", exceptionString
);
122 }else if(taxonNode
!= null && taxonNode
instanceof Classification
){
123 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?")){
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
;
137 MessagingUtils
.error(null, exceptionString
, result
.getExceptions().iterator().next());
142 CdmStore.getService(IClassificationService.class).delete(taxonomicTree);
143 }catch(ReferencedObjectUndeletableException e){
144 throw new ExecutionException(e.getMessage());
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
;
156 MessagingUtils
.error(null, exceptionString
, result
.getExceptions().iterator().next());
161 return postExecute(null);
165 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
169 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
170 throws ExecutionException
{
175 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
179 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
180 throws ExecutionException
{