21629870e32e3e63ba7d6878e6034e8f805e8b3f
[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.List;
14 import java.util.Set;
15 import java.util.UUID;
16
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;
22
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;
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 protected final 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 = (ITaxonTreeNode)CdmBase.deproxy(taxonNode, CdmBase.class);
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 element = ((TaxonNode)taxonNode).getTaxon();
104
105 String result = service.deleteTaxonNode((TaxonNode)taxonNode, config);
106 //TODO:if result is not a UUIDstring then pop up a message box
107
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?")){
112 return null;
113 }
114 }*/
115
116 String result = CdmStore.getService(IClassificationService.class).delete(taxonomicTree);
117
118
119 /*}else{
120 try{
121 CdmStore.getService(IClassificationService.class).delete(taxonomicTree);
122 }catch(ReferencedObjectUndeletableException e){
123 throw new ExecutionException(e.getMessage());
124 }
125 }*/
126 } else {
127
128 List<UUID> result =service.deleteTaxonNodes(treeNodes, config);
129
130 }
131
132 monitor.worked(40);
133 return postExecute(null);
134 }
135
136 /* (non-Javadoc)
137 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
138 */
139 /** {@inheritDoc} */
140 @Override
141 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
142 throws ExecutionException {
143 return null;
144 }
145
146 /* (non-Javadoc)
147 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
148 */
149 /** {@inheritDoc} */
150 @Override
151 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
152 throws ExecutionException {
153 return null;
154 }
155 }