Project

General

Profile

Download (2.94 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.ui.IWorkbenchPage;
12

    
13
import eu.etaxonomy.cdm.api.application.CdmApplicationController;
14
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
15
import eu.etaxonomy.cdm.api.service.ITaxonService;
16
import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
17
import eu.etaxonomy.cdm.api.service.exception.DataChangeNoRollbackException;
18
import eu.etaxonomy.cdm.model.taxon.Classification;
19
import eu.etaxonomy.cdm.model.taxon.Taxon;
20
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
21
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
22
import eu.etaxonomy.taxeditor.store.CdmStore;
23

    
24
public class DeleteTaxonOperation extends DeleteTaxonBaseOperation{
25
	//private Taxon taxon;
26
	private final Classification classification;
27

    
28

    
29

    
30

    
31
	public DeleteTaxonOperation(String label, IUndoContext undoContext,
32
			Taxon taxon, Classification classification, IWorkbenchPage activePage, IPostOperationEnabled postOperationEnabled, IConversationEnabled conversationEnabled) {
33
		super(label, undoContext, taxon, activePage, postOperationEnabled, conversationEnabled);
34
		this.element = taxon;
35

    
36
		Set<TaxonNode> nodes = taxon.getTaxonNodes();
37
		if (nodes.size() == 1 && classification == null){
38
			this.taxonNode = nodes.iterator().next();
39
		} else if (classification != null){
40
			Iterator<TaxonNode> iterator = nodes.iterator();
41
			while (iterator.hasNext()){
42
				TaxonNode node = iterator.next();
43
				if (node.getClassification().equals(classification)){
44
					this.taxonNode = node;
45
				}
46
			}
47
		} else{
48
			//TODO
49
		}
50
		this.classification = classification;
51

    
52
	}
53

    
54

    
55

    
56
	@Override
57
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
58
			throws ExecutionException {
59

    
60
				monitor.worked(20);
61
				bind();
62

    
63

    
64
				CdmApplicationController controller;
65

    
66
				controller = (CdmApplicationController) CdmStore.getCurrentApplicationConfiguration();
67

    
68
				ITaxonService service = controller.getTaxonService();
69
				try {
70

    
71
					service.deleteTaxon(element, new TaxonDeletionConfigurator(), classification);
72

    
73
				} catch (DataChangeNoRollbackException e) {
74
					// TODO Auto-generated catch block
75
					e.printStackTrace();
76

    
77
				}
78

    
79
				//closeObsoleteEditor(taxon);
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

    
101
}
(17-17/19)