Project

General

Profile

Download (3.12 KB) Statistics
| Branch: | Tag: | Revision:
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.session.ICdmEntitySessionEnabled;
24
import eu.etaxonomy.taxeditor.store.CdmStore;
25

    
26
public class DeleteTaxonOperation extends DeleteTaxonBaseOperation{
27

    
28
    private final Classification classification;
29

    
30
	public DeleteTaxonOperation(String label,
31
	        IUndoContext undoContext,
32
			Taxon taxon,
33
			TaxonDeletionConfigurator configurator,
34
			Classification classification,
35
			IWorkbenchPage activePage,
36
			IPostOperationEnabled postOperationEnabled,
37
			IConversationEnabled conversationEnabled,
38
            ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
39
		super(label, undoContext, configurator, activePage, postOperationEnabled, conversationEnabled, cdmEntitySessionEnabled);
40
		this.element = taxon;
41

    
42
		Set<TaxonNode> nodes = taxon.getTaxonNodes();
43
		if (nodes.size() == 1 && classification == null){
44
			this.taxonNode = nodes.iterator().next();
45
		} else if (classification != null){
46
			Iterator<TaxonNode> iterator = nodes.iterator();
47
			while (iterator.hasNext()){
48
				TaxonNode node = iterator.next();
49
				if (node.getClassification().equals(classification)){
50
					this.taxonNode = node;
51
				}
52
			}
53
		} else{
54
			//TODO
55
		}
56
		this.classification = classification;
57

    
58
	}
59

    
60
	@Override
61
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
62
			throws ExecutionException {
63

    
64
				monitor.worked(20);
65
				bind();
66

    
67

    
68
				ICdmApplicationConfiguration controller;
69

    
70
				controller = CdmStore.getCurrentApplicationConfiguration();
71

    
72
				ITaxonService service = controller.getTaxonService();
73

    
74

    
75
				DeleteResult result =	service.deleteTaxon(element.getUuid(), configurator, classification.getUuid());
76
				if (result.isError()){
77
					MessageDialog.openError(null, "Delete failed", result.getExceptions().get(0).getMessage());
78
				}
79

    
80
				monitor.worked(40);
81

    
82

    
83
				return postExecute(null);
84
	}
85

    
86
	@Override
87
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
88
			throws ExecutionException {
89
		// TODO Auto-generated method stub
90
		return null;
91
	}
92

    
93
	@Override
94
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
95
			throws ExecutionException {
96
		// TODO Auto-generated method stub
97
		return null;
98
	}
99

    
100
}
(16-16/19)