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
.List
;
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
.IClassificationService
;
26 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonNodeService
;
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
.taxon
.Classification
;
32 import eu
.etaxonomy
.cdm
.model
.taxon
.ITaxonTreeNode
;
33 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
34 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPersistentPostOperation
;
35 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
36 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
39 * <p>DeleteTreeNodeOperation class.</p>
42 * @created Jan 20, 2010
45 public class DeleteOperation
extends AbstractPersistentPostOperation
{
47 private Set
<ITaxonTreeNode
> treeNodes
;
48 protected final TaxonDeletionConfigurator config
;
52 * <p>Constructor for DeleteTreeNodeOperation.</p>
54 * @param label a {@link java.lang.String} object.
55 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
56 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
57 * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
58 * @param treeNodes a {@link java.util.Set} object.
60 public DeleteOperation(String label
, IUndoContext undoContext
,
61 ITaxonTreeNode taxonNode
, TaxonDeletionConfigurator config
,
62 IPostOperationEnabled postOperationEnabled
,
63 IConversationEnabled conversationEnabled
) {
64 super(label
, undoContext
, postOperationEnabled
, conversationEnabled
);
65 this.taxonNode
= (ITaxonTreeNode
)CdmBase
.deproxy(taxonNode
, CdmBase
.class);
70 * <p>Constructor for DeleteTreeNodeOperation.</p>
72 * @param label a {@link java.lang.String} object.
73 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
74 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
75 * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
76 * @param treeNodes a {@link java.util.Set} object.
78 public DeleteOperation(String label
, IUndoContext undoContext
,
79 Set
<ITaxonTreeNode
> treeNodes
, TaxonDeletionConfigurator config
,
80 IPostOperationEnabled postOperationEnabled
,
81 IConversationEnabled conversationEnabled
) {
82 super(label
, undoContext
, postOperationEnabled
, conversationEnabled
);
83 this.treeNodes
= treeNodes
;
89 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
93 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
94 throws ExecutionException
{
98 ICdmApplicationConfiguration controller
= CdmStore
.getCurrentApplicationConfiguration();
99 ITaxonNodeService service
= controller
.getTaxonNodeService();
100 if(taxonNode
!= null && taxonNode
instanceof TaxonNode
){
101 //((TaxonNode) treeNode).delete();
103 element
= ((TaxonNode
)taxonNode
).getTaxon();
105 String result
= service
.deleteTaxonNode((TaxonNode
)taxonNode
, config
);
106 //TODO:if result is not a UUIDstring then pop up a message box
108 }else if(taxonNode
!= null && taxonNode
instanceof Classification
){
109 Classification taxonomicTree
= (Classification
) taxonNode
;
110 /*if(taxonomicTree.hasChildNodes()){
111 if(! MessageDialog.openConfirm(null, "Confirm Deletion", "The selected tree has children, do yu realy want to delete the whole tree with its children?")){
116 String result
= CdmStore
.getService(IClassificationService
.class).delete(taxonomicTree
);
121 CdmStore.getService(IClassificationService.class).delete(taxonomicTree);
122 }catch(ReferencedObjectUndeletableException e){
123 throw new ExecutionException(e.getMessage());
128 List
<UUID
> result
=service
.deleteTaxonNodes(treeNodes
, config
);
133 return postExecute(null);
137 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
141 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
142 throws ExecutionException
{
147 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
151 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
152 throws ExecutionException
{