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
.CdmApplicationController
;
22 import eu
.etaxonomy
.cdm
.api
.application
.ICdmApplicationConfiguration
;
23 import eu
.etaxonomy
.cdm
.api
.conversation
.IConversationEnabled
;
24 import eu
.etaxonomy
.cdm
.api
.service
.IClassificationService
;
25 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonNodeService
;
26 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
27 import eu
.etaxonomy
.cdm
.api
.service
.config
.TaxonDeletionConfigurator
;
28 import eu
.etaxonomy
.cdm
.api
.service
.exception
.DataChangeNoRollbackException
;
29 import eu
.etaxonomy
.cdm
.api
.service
.exception
.ReferencedObjectUndeletableException
;
30 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
31 import eu
.etaxonomy
.cdm
.model
.common
.ITreeNode
;
32 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
33 import eu
.etaxonomy
.cdm
.model
.taxon
.ITaxonTreeNode
;
34 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
35 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPersistentPostOperation
;
36 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
37 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
38 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
41 * <p>DeleteTreeNodeOperation class.</p>
44 * @created Jan 20, 2010
47 public class DeleteOperation
extends AbstractPersistentPostOperation
{
49 private Set
<ITaxonTreeNode
> treeNodes
;
50 private TaxonDeletionConfigurator config
;
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 super(label
, undoContext
, postOperationEnabled
, conversationEnabled
);
67 this.taxonNode
= (ITaxonTreeNode
)CdmBase
.deproxy(taxonNode
, CdmBase
.class);
72 * <p>Constructor for DeleteTreeNodeOperation.</p>
74 * @param label a {@link java.lang.String} object.
75 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
76 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
77 * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
78 * @param treeNodes a {@link java.util.Set} object.
80 public DeleteOperation(String label
, IUndoContext undoContext
,
81 Set
<ITaxonTreeNode
> treeNodes
, TaxonDeletionConfigurator config
,
82 IPostOperationEnabled postOperationEnabled
,
83 IConversationEnabled conversationEnabled
) {
84 super(label
, undoContext
, postOperationEnabled
, conversationEnabled
);
85 this.treeNodes
= treeNodes
;
91 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
95 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
96 throws ExecutionException
{
100 ICdmApplicationConfiguration controller
= CdmStore
.getCurrentApplicationConfiguration();
101 ITaxonNodeService service
= controller
.getTaxonNodeService();
102 if(taxonNode
!= null && taxonNode
instanceof TaxonNode
){
103 //((TaxonNode) treeNode).delete();
105 taxon
= ((TaxonNode
)taxonNode
).getTaxon();
107 service
.deleteTaxonNode((TaxonNode
)taxonNode
, config
);
108 } catch (DataChangeNoRollbackException e
) {
110 throw new ExecutionException(e
.getMessage());
114 }else if(taxonNode
!= null && taxonNode
instanceof Classification
){
115 Classification taxonomicTree
= (Classification
) taxonNode
;
116 if(taxonomicTree
.hasChildNodes()){
117 StoreUtil
.warningDialog("Tree is not empty", this, "It is not possible to delete a Taxonomic Tree that " +
118 "is not empty. Please delete included taxa first");
121 CdmStore
.getService(IClassificationService
.class).delete(taxonomicTree
);
122 }catch(ReferencedObjectUndeletableException e
){
123 throw new ExecutionException(e
.getMessage());
128 service
.deleteTaxonNodes(treeNodes
, config
);
129 } catch (DataChangeNoRollbackException e
) {
130 throw new ExecutionException(e
.getMessage());
135 return postExecute(null);
139 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
143 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
144 throws ExecutionException
{
149 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
153 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
154 throws ExecutionException
{