Project

General

Profile

Download (3.46 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.ICdmApplicationConfiguration;
14
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
15
import eu.etaxonomy.cdm.api.service.DeleteResult;
16
import eu.etaxonomy.cdm.api.service.ITaxonService;
17
import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
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.editor.internal.TaxeditorEditorPlugin;
22
import eu.etaxonomy.taxeditor.model.DeleteResultMessagingUtils;
23
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
24
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
25
import eu.etaxonomy.taxeditor.store.CdmStore;
26

    
27
public class DeleteTaxonOperation extends DeleteTaxonBaseOperation{
28

    
29
    private final Classification classification;
30

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

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

    
59
	}
60

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

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

    
68

    
69
				ICdmApplicationConfiguration controller;
70

    
71
				controller = CdmStore.getCurrentApplicationConfiguration();
72

    
73
				ITaxonService service = controller.getTaxonService();
74

    
75
				DeleteResult result =	service.deleteTaxon(element.getUuid(), configurator, classification.getUuid());
76

    
77
				if (result.isError()){
78
				    DeleteResultMessagingUtils.messageDialogWithDetails(result, "Delete failed", TaxeditorEditorPlugin.PLUGIN_ID);
79
				} else if (!result.getUpdatedObjects().isEmpty()){
80
                    DeleteResultMessagingUtils.messageDialogWithDetails(result, "The Taxon was deleted, but related object(s) could not be deleted", TaxeditorEditorPlugin.PLUGIN_ID);
81
				}
82

    
83
				monitor.worked(40);
84

    
85

    
86
				return postExecute(null);
87
	}
88

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

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

    
103
}
(16-16/19)