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
;
21 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
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
.cdm
.api
.application
.CdmApplicationController
;
36 import eu
.etaxonomy
.cdm
.api
.application
.ICdmApplicationConfiguration
;
37 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPersistentPostOperation
;
38 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
39 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
40 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
43 * <p>DeleteTreeNodeOperation class.</p>
46 * @created Jan 20, 2010
49 public class DeleteOperation
extends AbstractPersistentPostOperation
{
51 private Set
<ITaxonTreeNode
> treeNodes
;
52 private TaxonDeletionConfigurator config
;
56 * <p>Constructor for DeleteTreeNodeOperation.</p>
58 * @param label a {@link java.lang.String} object.
59 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
60 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
61 * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
62 * @param treeNodes a {@link java.util.Set} object.
64 public DeleteOperation(String label
, IUndoContext undoContext
,
65 ITaxonTreeNode taxonNode
, TaxonDeletionConfigurator config
,
66 IPostOperationEnabled postOperationEnabled
,
67 IConversationEnabled conversationEnabled
) {
68 super(label
, undoContext
, postOperationEnabled
, conversationEnabled
);
69 this.taxonNode
= (ITaxonTreeNode
)CdmBase
.deproxy(taxonNode
, CdmBase
.class);
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 super(label
, undoContext
, postOperationEnabled
, conversationEnabled
);
87 this.treeNodes
= treeNodes
;
93 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
97 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
98 throws ExecutionException
{
102 ICdmApplicationConfiguration controller
= CdmStore
.getCurrentApplicationConfiguration();
103 ITaxonNodeService service
= controller
.getTaxonNodeService();
104 if(taxonNode
!= null && taxonNode
instanceof TaxonNode
){
105 //((TaxonNode) treeNode).delete();
107 taxon
= ((TaxonNode
)taxonNode
).getTaxon();
109 service
.deleteTaxonNode((TaxonNode
)taxonNode
, config
);
110 } catch (DataChangeNoRollbackException e
) {
112 throw new ExecutionException(e
.getMessage());
116 }else if(taxonNode
!= null && taxonNode
instanceof Classification
){
117 Classification taxonomicTree
= (Classification
) taxonNode
;
118 /*if(taxonomicTree.hasChildNodes()){
119 if(! MessageDialog.openConfirm(null, "Confirm Deletion", "The selected tree has children, do yu realy want to delete the whole tree with its children?")){
124 CdmStore
.getService(IClassificationService
.class).delete(taxonomicTree
);
125 }catch(ReferencedObjectUndeletableException e
){
126 throw new ExecutionException(e
.getMessage());
132 CdmStore.getService(IClassificationService.class).delete(taxonomicTree);
133 }catch(ReferencedObjectUndeletableException e){
134 throw new ExecutionException(e.getMessage());
139 service
.deleteTaxonNodes(treeNodes
, config
);
140 } catch (DataChangeNoRollbackException e
) {
141 throw new ExecutionException(e
.getMessage());
146 return postExecute(null);
150 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
154 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
155 throws ExecutionException
{
160 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
164 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
165 throws ExecutionException
{