(no commit message)
[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 //private Taxon taxon;
27 private final Classification classification;
28
29
30
31
32 public DeleteTaxonOperation(String label, IUndoContext undoContext,
33 Taxon taxon, Classification classification, IWorkbenchPage activePage, IPostOperationEnabled postOperationEnabled, IConversationEnabled conversationEnabled) {
34 super(label, undoContext, taxon, activePage, postOperationEnabled, conversationEnabled);
35 this.element = taxon;
36
37 Set<TaxonNode> nodes = taxon.getTaxonNodes();
38 if (nodes.size() == 1 && classification == null){
39 this.taxonNode = nodes.iterator().next();
40 } else if (classification != null){
41 Iterator<TaxonNode> iterator = nodes.iterator();
42 while (iterator.hasNext()){
43 TaxonNode node = iterator.next();
44 if (node.getClassification().equals(classification)){
45 this.taxonNode = node;
46 }
47 }
48 } else{
49 //TODO
50 }
51 this.classification = classification;
52
53 }
54
55
56
57 @Override
58 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
59 throws ExecutionException {
60
61 monitor.worked(20);
62 bind();
63
64
65 ICdmApplicationConfiguration controller;
66
67 controller = (ICdmApplicationConfiguration) CdmStore.getCurrentApplicationConfiguration();
68
69 ITaxonService service = controller.getTaxonService();
70
71
72 DeleteResult result = service.deleteTaxon(element, new TaxonDeletionConfigurator(), classification);
73 if (result.isError()){
74 MessageDialog.openError(null, "Delete failed", result.getExceptions().get(0).getMessage());
75 }
76
77 //closeObsoleteEditor(taxon);
78 monitor.worked(40);
79
80
81 return postExecute(null);
82 }
83
84 @Override
85 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
86 throws ExecutionException {
87 // TODO Auto-generated method stub
88 return null;
89 }
90
91 @Override
92 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
93 throws ExecutionException {
94 // TODO Auto-generated method stub
95 return null;
96 }
97
98
99 }