Project

General

Profile

Download (3.46 KB) Statistics
| Branch: | Tag: | Revision:
1 d43de9c0 Katja Luther
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 e2b6e8ec Cherian Mathew
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
14 d43de9c0 Katja Luther
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
15 bcdc7df3 Katja Luther
import eu.etaxonomy.cdm.api.service.DeleteResult;
16 d43de9c0 Katja Luther
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 8336cf65 Katja Luther
import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin;
22
import eu.etaxonomy.taxeditor.model.DeleteResultMessagingUtils;
23 d43de9c0 Katja Luther
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
24 1842d7af Cherian Mathew
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
25 d43de9c0 Katja Luther
import eu.etaxonomy.taxeditor.store.CdmStore;
26
27
public class DeleteTaxonOperation extends DeleteTaxonBaseOperation{
28 0a534d09 Patric Plitzner
29 662c457c Cherian Mathew
    private final Classification classification;
30 0a534d09 Patric Plitzner
31 1842d7af Cherian Mathew
	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 0a534d09 Patric Plitzner
		this.element = taxon;
42
43 d43de9c0 Katja Luther
		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 0a534d09 Patric Plitzner
59 d43de9c0 Katja Luther
	}
60
61
	@Override
62
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
63
			throws ExecutionException {
64 0a534d09 Patric Plitzner
65 d43de9c0 Katja Luther
				monitor.worked(20);
66
				bind();
67 0a534d09 Patric Plitzner
68
69 0abb401a Cherian Mathew
				ICdmApplicationConfiguration controller;
70 0a534d09 Patric Plitzner
71 662c457c Cherian Mathew
				controller = CdmStore.getCurrentApplicationConfiguration();
72 0a534d09 Patric Plitzner
73 d43de9c0 Katja Luther
				ITaxonService service = controller.getTaxonService();
74 0a534d09 Patric Plitzner
75 d175d20f Cherian Mathew
				DeleteResult result =	service.deleteTaxon(element.getUuid(), configurator, classification.getUuid());
76 c36e67ab Cherian Mathew
77 a2e83464 Katja Luther
				if (result.isError()){
78 8336cf65 Katja Luther
				    DeleteResultMessagingUtils.messageDialogWithDetails(result, "Delete failed", TaxeditorEditorPlugin.PLUGIN_ID);
79 3513a90b Katja Luther
				} else if (!result.getUpdatedObjects().isEmpty()){
80 8336cf65 Katja Luther
                    DeleteResultMessagingUtils.messageDialogWithDetails(result, "The Taxon was deleted, but related object(s) could not be deleted", TaxeditorEditorPlugin.PLUGIN_ID);
81 a2e83464 Katja Luther
				}
82 0a534d09 Patric Plitzner
83 d43de9c0 Katja Luther
				monitor.worked(40);
84 0a534d09 Patric Plitzner
85
86 d43de9c0 Katja Luther
				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 0a534d09 Patric Plitzner
103 662c457c Cherian Mathew
}