e7cd64a7ec18092c53e40af40a99353d30a04200
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / name / operation / DeleteTaxonOperation.java
1 package eu.etaxonomy.taxeditor.editor.name.operation;
2
3 import java.util.Iterator;
4 import java.util.Set;
5
6 import org.eclipse.core.commands.ExecutionException;
7 import org.eclipse.core.commands.operations.IUndoContext;
8 import org.eclipse.core.runtime.IAdaptable;
9 import org.eclipse.core.runtime.IProgressMonitor;
10 import org.eclipse.core.runtime.IStatus;
11 import org.eclipse.jface.dialogs.MessageDialog;
12 import org.eclipse.ui.IWorkbenchPage;
13
14 import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
15 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
16 import eu.etaxonomy.cdm.api.service.DeleteResult;
17 import eu.etaxonomy.cdm.api.service.ITaxonService;
18 import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
19 import eu.etaxonomy.cdm.model.taxon.Classification;
20 import eu.etaxonomy.cdm.model.taxon.Taxon;
21 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
22 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
23 import eu.etaxonomy.taxeditor.store.CdmStore;
24
25 public class DeleteTaxonOperation extends DeleteTaxonBaseOperation{
26
27 private final Classification classification;
28
29 public DeleteTaxonOperation(String label, IUndoContext undoContext,
30 Taxon taxon, TaxonDeletionConfigurator configurator, Classification classification, IWorkbenchPage activePage, IPostOperationEnabled postOperationEnabled, IConversationEnabled conversationEnabled) {
31 super(label, undoContext, configurator, activePage, postOperationEnabled, conversationEnabled);
32 this.element = taxon;
33
34 Set<TaxonNode> nodes = taxon.getTaxonNodes();
35 if (nodes.size() == 1 && classification == null){
36 this.taxonNode = nodes.iterator().next();
37 } else if (classification != null){
38 Iterator<TaxonNode> iterator = nodes.iterator();
39 while (iterator.hasNext()){
40 TaxonNode node = iterator.next();
41 if (node.getClassification().equals(classification)){
42 this.taxonNode = node;
43 }
44 }
45 } else{
46 //TODO
47 }
48 this.classification = classification;
49
50 }
51
52 @Override
53 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
54 throws ExecutionException {
55
56 monitor.worked(20);
57 bind();
58
59
60 ICdmApplicationConfiguration controller;
61
62 controller = CdmStore.getCurrentApplicationConfiguration();
63
64 ITaxonService service = controller.getTaxonService();
65
66
67 DeleteResult result = service.deleteTaxon(element, configurator, classification);
68 if (result.isError()){
69 MessageDialog.openError(null, "Delete failed", result.getExceptions().get(0).getMessage());
70 }
71
72 monitor.worked(40);
73
74
75 return postExecute(null);
76 }
77
78 @Override
79 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
80 throws ExecutionException {
81 // TODO Auto-generated method stub
82 return null;
83 }
84
85 @Override
86 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
87 throws ExecutionException {
88 // TODO Auto-generated method stub
89 return null;
90 }
91
92 }