5e57bd87396dcc7ed940113175f94aef355599e7
[taxeditor.git] / eu.etaxonomy.taxeditor.navigation / src / main / java / eu / etaxonomy / taxeditor / navigation / navigator / operation / DeleteOperation.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
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.
9 */
10
11 package eu.etaxonomy.taxeditor.navigation.navigator.operation;
12
13 import java.util.Set;
14
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
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.model.common.ITreeNode;
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.operation.AbstractPersistentPostOperation;
34 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
35 import eu.etaxonomy.taxeditor.store.CdmStore;
36 import eu.etaxonomy.taxeditor.store.StoreUtil;
37
38 /**
39 * <p>DeleteTreeNodeOperation class.</p>
40 *
41 * @author n.hoffmann
42 * @created Jan 20, 2010
43 * @version 1.0
44 */
45 public class DeleteOperation extends AbstractPersistentPostOperation{
46
47 private Set<ITaxonTreeNode> treeNodes;
48 private TaxonDeletionConfigurator config;
49
50
51 /**
52 * <p>Constructor for DeleteTreeNodeOperation.</p>
53 *
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.
59 */
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 = taxonNode;
66 this.config = config;
67 }
68
69 /**
70 * <p>Constructor for DeleteTreeNodeOperation.</p>
71 *
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.
77 */
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;
84 this.config = config;
85 }
86
87
88 /* (non-Javadoc)
89 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
90 */
91 /** {@inheritDoc} */
92 @Override
93 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
94 throws ExecutionException {
95
96 bind();
97 monitor.worked(20);
98 ICdmApplicationConfiguration controller = CdmStore.getCurrentApplicationConfiguration();
99 ITaxonNodeService service = controller.getTaxonNodeService();
100 if(taxonNode != null && taxonNode instanceof TaxonNode){
101 //((TaxonNode) treeNode).delete();
102
103 taxon = ((TaxonNode)taxonNode).getTaxon();
104 try {
105 service.deleteTaxonNode((TaxonNode)taxonNode, config);
106 } catch (DataChangeNoRollbackException e) {
107
108 throw new ExecutionException(e.getMessage());
109
110 }
111
112 }else if(taxonNode != null && taxonNode instanceof Classification){
113 Classification taxonomicTree = (Classification) taxonNode;
114 if(taxonomicTree.hasChildNodes()){
115 StoreUtil.warningDialog("Tree is not empty", this, "It is not possible to delete a Taxonomic Tree that " +
116 "is not empty. Please delete included taxa first");
117 }else{
118 CdmStore.getService(IClassificationService.class).delete(taxonomicTree);
119 }
120 } else {
121 try {
122 service.deleteTaxonNodes(treeNodes, config);
123 } catch (DataChangeNoRollbackException e) {
124 throw new ExecutionException(e.getMessage());
125 }
126 }
127
128 monitor.worked(40);
129 return postExecute(null);
130 }
131
132 /* (non-Javadoc)
133 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
134 */
135 /** {@inheritDoc} */
136 @Override
137 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
138 throws ExecutionException {
139 return null;
140 }
141
142 /* (non-Javadoc)
143 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
144 */
145 /** {@inheritDoc} */
146 @Override
147 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
148 throws ExecutionException {
149 return null;
150 }
151 }