Project

General

Profile

Download (3.09 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.model.MessagingUtils;
23
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
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, IUndoContext undoContext,
31
			Taxon taxon, TaxonDeletionConfigurator configurator, Classification classification, IWorkbenchPage activePage, IPostOperationEnabled postOperationEnabled, IConversationEnabled conversationEnabled) {
32
		super(label, undoContext, configurator, activePage, postOperationEnabled, conversationEnabled);
33
		this.element = taxon;
34

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

    
51
	}
52

    
53
	@Override
54
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
55
			throws ExecutionException {
56

    
57
				monitor.worked(20);
58
				bind();
59

    
60

    
61
				ICdmApplicationConfiguration controller;
62

    
63
				controller = CdmStore.getCurrentApplicationConfiguration();
64

    
65
				ITaxonService service = controller.getTaxonService();
66

    
67

    
68
				DeleteResult result =	service.deleteTaxon(element.getUuid(), configurator, classification);
69
				if (result.isError()){
70
					MessageDialog.openError(null, "Delete failed", result.toString());
71
				} else if (!result.getUpdatedObjects().isEmpty()){
72
					MessagingUtils.informationDialog("Delete successfull", result.toString());
73
				}
74

    
75
				monitor.worked(40);
76

    
77

    
78
				return postExecute(null);
79
	}
80

    
81
	@Override
82
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
83
			throws ExecutionException {
84
		// TODO Auto-generated method stub
85
		return null;
86
	}
87

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

    
95
}
(16-16/19)