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
;
21 import eu
.etaxonomy
.cdm
.api
.application
.ICdmApplicationConfiguration
;
22 import eu
.etaxonomy
.cdm
.api
.conversation
.IConversationEnabled
;
23 import eu
.etaxonomy
.cdm
.api
.service
.IClassificationService
;
24 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonNodeService
;
25 import eu
.etaxonomy
.cdm
.api
.service
.config
.TaxonDeletionConfigurator
;
26 import eu
.etaxonomy
.cdm
.api
.service
.exception
.DataChangeNoRollbackException
;
27 import eu
.etaxonomy
.cdm
.api
.service
.exception
.ReferencedObjectUndeletableException
;
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 private 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 service
.deleteTaxonNode((TaxonNode
)taxonNode
, config
);
104 } catch (DataChangeNoRollbackException e
) {
106 throw new ExecutionException(e
.getMessage());
110 }else if(taxonNode
!= null && taxonNode
instanceof Classification
){
111 Classification taxonomicTree
= (Classification
) taxonNode
;
112 /*if(taxonomicTree.hasChildNodes()){
113 if(! MessageDialog.openConfirm(null, "Confirm Deletion", "The selected tree has children, do yu realy want to delete the whole tree with its children?")){
118 CdmStore
.getService(IClassificationService
.class).delete(taxonomicTree
);
119 }catch(ReferencedObjectUndeletableException e
){
120 throw new ExecutionException(e
.getMessage());
126 CdmStore.getService(IClassificationService.class).delete(taxonomicTree);
127 }catch(ReferencedObjectUndeletableException e){
128 throw new ExecutionException(e.getMessage());
133 service
.deleteTaxonNodes(treeNodes
, config
);
134 } catch (DataChangeNoRollbackException e
) {
135 throw new ExecutionException(e
.getMessage());
140 return postExecute(null);
144 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
148 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
149 throws ExecutionException
{
154 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
158 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
159 throws ExecutionException
{