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
;
13 import java
.util
.HashSet
;
15 import java
.util
.UUID
;
17 import org
.eclipse
.core
.commands
.ExecutionException
;
18 import org
.eclipse
.core
.commands
.operations
.IUndoContext
;
19 import org
.eclipse
.core
.runtime
.IAdaptable
;
20 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
21 import org
.eclipse
.core
.runtime
.IStatus
;
23 import eu
.etaxonomy
.cdm
.api
.application
.ICdmApplicationConfiguration
;
24 import eu
.etaxonomy
.cdm
.api
.conversation
.IConversationEnabled
;
25 import eu
.etaxonomy
.cdm
.api
.service
.DeleteResult
;
26 import eu
.etaxonomy
.cdm
.api
.service
.IClassificationService
;
27 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonNodeService
;
28 import eu
.etaxonomy
.cdm
.api
.service
.config
.TaxonDeletionConfigurator
;
29 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
30 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
31 import eu
.etaxonomy
.cdm
.model
.taxon
.ITaxonTreeNode
;
32 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
33 import eu
.etaxonomy
.taxeditor
.model
.DeleteResultMessagingUtils
;
34 import eu
.etaxonomy
.taxeditor
.navigation
.internal
.TaxeditorNavigationPlugin
;
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
;
41 * <p>DeleteTreeNodeOperation class.</p>
44 * @created Jan 20, 2010
47 public class DeleteOperation
extends AbstractPersistentPostOperation
{
49 private Set
<ITaxonTreeNode
> treeNodes
;
50 protected final TaxonDeletionConfigurator config
;
51 private final ICdmEntitySessionEnabled cdmEntitySessionEnabled
;
54 * <p>Constructor for DeleteTreeNodeOperation.</p>
56 * @param label a {@link java.lang.String} object.
57 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
58 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
59 * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
60 * @param treeNodes a {@link java.util.Set} object.
62 public DeleteOperation(String label
, IUndoContext undoContext
,
63 ITaxonTreeNode taxonNode
, TaxonDeletionConfigurator config
,
64 IPostOperationEnabled postOperationEnabled
,
65 IConversationEnabled conversationEnabled
,
66 ICdmEntitySessionEnabled cdmEntitySessionEnabled
) {
67 super(label
, undoContext
, postOperationEnabled
, conversationEnabled
, cdmEntitySessionEnabled
);
68 this.taxonNode
= (ITaxonTreeNode
)CdmBase
.deproxy(taxonNode
, CdmBase
.class);
70 this.cdmEntitySessionEnabled
= cdmEntitySessionEnabled
;
74 * <p>Constructor for DeleteTreeNodeOperation.</p>
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.
82 public DeleteOperation(String label
, IUndoContext undoContext
,
83 Set
<ITaxonTreeNode
> treeNodes
, TaxonDeletionConfigurator config
,
84 IPostOperationEnabled postOperationEnabled
,
85 IConversationEnabled conversationEnabled
,
86 ICdmEntitySessionEnabled cdmEntitySessionEnabled
) {
87 super(label
, undoContext
, postOperationEnabled
, conversationEnabled
, cdmEntitySessionEnabled
);
88 this.treeNodes
= treeNodes
;
90 this.cdmEntitySessionEnabled
= cdmEntitySessionEnabled
;
97 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
101 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
102 throws ExecutionException
{
106 ICdmApplicationConfiguration controller
= CdmStore
.getCurrentApplicationConfiguration();
107 ITaxonNodeService service
= controller
.getTaxonNodeService();
108 if(taxonNode
!= null && taxonNode
instanceof TaxonNode
){
109 //((TaxonNode) treeNode).delete();
111 element
= ((TaxonNode
)taxonNode
).getTaxon();
113 DeleteResult result
= service
.deleteTaxonNode((TaxonNode
)taxonNode
, config
);
114 if (result
.isError() && !result
.getExceptions().isEmpty()){
116 DeleteResultMessagingUtils
.messageDialogWithDetails(result
, "TaxonNode could not be deleted.", TaxeditorNavigationPlugin
.PLUGIN_ID
);
117 } else if (!result
.getExceptions().isEmpty()){
118 String separator
= ", ";
119 String exceptionString
= "";
120 for (Exception exception
: result
.getExceptions()) {
121 exceptionString
+= exception
.getLocalizedMessage()+separator
;
123 DeleteResultMessagingUtils
.messageDialogWithDetails(result
, "TaxonNode was successfully deleted, but related object(s) could not be deleted", TaxeditorNavigationPlugin
.PLUGIN_ID
);
127 }else if(taxonNode
!= null && taxonNode
instanceof Classification
){
128 Classification taxonomicTree
= (Classification
) taxonNode
;
130 DeleteResult result
= CdmStore
.getService(IClassificationService
.class).delete(taxonomicTree
.getUuid());
131 if (result
.isError() && !result
.getExceptions().isEmpty()){
132 //TODO:Error message!
133 DeleteResultMessagingUtils
.messageDialogWithDetails(result
, "TaxonNode could not be deleted.", TaxeditorNavigationPlugin
.PLUGIN_ID
);
136 Set
<UUID
> treeNodeUuids
= new HashSet
<UUID
>();
137 ITaxonTreeNode entity
= null;
138 for(ITaxonTreeNode treeNode
: treeNodes
) {
142 treeNodeUuids
.add(treeNode
.getUuid());
145 DeleteResult result
= service
.deleteTaxonNodes(treeNodeUuids
, config
);
146 if (result
.isError() && !result
.getExceptions().isEmpty()){
147 //TODO:Error message!
148 DeleteResultMessagingUtils
.messageDialogWithDetails(result
, "TaxonNode could not be deleted.", TaxeditorNavigationPlugin
.PLUGIN_ID
);
155 return postExecute(null);
159 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
163 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
164 throws ExecutionException
{
169 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
173 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
174 throws ExecutionException
{