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
.operation
.AbstractPersistentPostOperation
;
33 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
34 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
37 * <p>DeleteTreeNodeOperation class.</p>
40 * @created Jan 20, 2010
43 public class DeleteOperation
extends AbstractPersistentPostOperation
{
45 private Set
<ITaxonTreeNode
> treeNodes
;
46 protected final TaxonDeletionConfigurator config
;
50 * <p>Constructor for DeleteTreeNodeOperation.</p>
52 * @param label a {@link java.lang.String} object.
53 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
54 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
55 * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
56 * @param treeNodes a {@link java.util.Set} object.
58 public DeleteOperation(String label
, IUndoContext undoContext
,
59 ITaxonTreeNode taxonNode
, TaxonDeletionConfigurator config
,
60 IPostOperationEnabled postOperationEnabled
,
61 IConversationEnabled conversationEnabled
) {
62 super(label
, undoContext
, postOperationEnabled
, conversationEnabled
);
63 this.taxonNode
= (ITaxonTreeNode
)CdmBase
.deproxy(taxonNode
, CdmBase
.class);
68 * <p>Constructor for DeleteTreeNodeOperation.</p>
70 * @param label a {@link java.lang.String} object.
71 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
72 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
73 * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
74 * @param treeNodes a {@link java.util.Set} object.
76 public DeleteOperation(String label
, IUndoContext undoContext
,
77 Set
<ITaxonTreeNode
> treeNodes
, TaxonDeletionConfigurator config
,
78 IPostOperationEnabled postOperationEnabled
,
79 IConversationEnabled conversationEnabled
) {
80 super(label
, undoContext
, postOperationEnabled
, conversationEnabled
);
81 this.treeNodes
= treeNodes
;
87 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
91 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
92 throws ExecutionException
{
96 ICdmApplicationConfiguration controller
= CdmStore
.getCurrentApplicationConfiguration();
97 ITaxonNodeService service
= controller
.getTaxonNodeService();
98 if(taxonNode
!= null && taxonNode
instanceof TaxonNode
){
99 //((TaxonNode) treeNode).delete();
101 element
= ((TaxonNode
)taxonNode
).getTaxon();
103 DeleteResult result
= service
.deleteTaxonNode((TaxonNode
)taxonNode
, config
);
104 if (result
.isError() && !result
.getExceptions().isEmpty()){
105 //TODO:Error message!
106 MessageDialog
.openError(null, "Delete failed", result
.getExceptions().iterator().next().getMessage());
107 } else if (!result
.getExceptions().isEmpty()){
108 String separator
= ", ";
109 String exceptionString
= "";
110 for (Exception exception
: result
.getExceptions()) {
111 exceptionString
+= exception
.getLocalizedMessage()+separator
;
113 MessageDialog
.openInformation(null, "Delete of the node was successful but the taxon could not be deleted.", exceptionString
);
117 }else if(taxonNode
!= null && taxonNode
instanceof Classification
){
118 Classification taxonomicTree
= (Classification
) taxonNode
;
119 /*if(taxonomicTree.hasChildNodes()){
120 if(! MessageDialog.openConfirm(null, "Confirm Deletion", "The selected tree has children, do yu realy want to delete the whole tree with its children?")){
125 DeleteResult result
= CdmStore
.getService(IClassificationService
.class).delete(taxonomicTree
);
126 if (result
.isError() && !result
.getExceptions().isEmpty()){
127 //TODO:Error message!
128 MessageDialog
.openError(null, "Delete failed", result
.getExceptions().iterator().next().getMessage());
133 CdmStore.getService(IClassificationService.class).delete(taxonomicTree);
134 }catch(ReferencedObjectUndeletableException e){
135 throw new ExecutionException(e.getMessage());
140 DeleteResult result
=service
.deleteTaxonNodes(treeNodes
, config
);
141 if (result
.isError() && !result
.getExceptions().isEmpty()){
142 //TODO:Error message!
143 MessageDialog
.openError(null, "Delete failed", result
.getExceptions().iterator().next().getMessage());
148 return postExecute(null);
152 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
156 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
157 throws ExecutionException
{
162 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
166 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
167 throws ExecutionException
{