Project

General

Profile

Download (3.81 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9

    
10
package eu.etaxonomy.taxeditor.editor.name.operation;
11

    
12
import java.util.Set;
13

    
14
import org.eclipse.core.commands.ExecutionException;
15
import org.eclipse.core.commands.operations.IUndoContext;
16
import org.eclipse.core.runtime.IAdaptable;
17
import org.eclipse.core.runtime.IProgressMonitor;
18
import org.eclipse.core.runtime.IStatus;
19

    
20
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
21
import eu.etaxonomy.cdm.api.service.DeleteResult;
22
import eu.etaxonomy.cdm.api.service.ITaxonService;
23
import eu.etaxonomy.cdm.model.taxon.Synonym;
24
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
25
import eu.etaxonomy.cdm.model.taxon.Taxon;
26
import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin;
27
import eu.etaxonomy.taxeditor.model.DeleteResultMessagingUtils;
28
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
29
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
30
import eu.etaxonomy.taxeditor.store.CdmStore;
31

    
32
/**
33
 * <p>DeleteSynonymOperation class.</p>
34
 *
35
 * @author p.ciardelli
36
 * @created 14.01.2009
37
 */
38
public class DeleteSynonymOperation extends AbstractPostTaxonOperation {
39

    
40
	private final Synonym synonym;
41
	private SynonymRelationshipType synonymType;
42

    
43
	/**
44
	 * <p>Constructor for DeleteSynonymOperation.</p>
45
	 *
46
	 * @param label a {@link java.lang.String} object.
47
	 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
48
	 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
49
	 * @param synonym a {@link eu.etaxonomy.cdm.model.taxon.Synonym} object.
50
	 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
51
	 */
52
	public DeleteSynonymOperation(String label, IUndoContext undoContext,
53
			Taxon taxon, Synonym synonym, IPostOperationEnabled postOperationEnabled) {
54
		super(label, undoContext, taxon, postOperationEnabled);
55
		this.synonym = synonym;
56
	}
57

    
58
	/** {@inheritDoc} */
59
	@Override
60
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
61
			throws ExecutionException {
62

    
63
		// Store synonymRelationshipType for later undo operations
64
		synonymType = synonym.getType();
65
		monitor.worked(20);
66

    
67
		// Remove synonym from taxon
68
		ICdmApplicationConfiguration controller;
69

    
70
		controller = CdmStore.getCurrentApplicationConfiguration();
71

    
72
		ITaxonService service = controller.getTaxonService();
73
		if (synonym.getId() == 0){
74
			element.removeSynonym(synonym);
75

    
76
		} else {
77
			//TODO: this should be moved to the handler, the operations should not contain ui code
78
			DeleteResult result = service.deleteSynonym(synonym.getUuid(), null);
79
			if (result.isError()){
80
				DeleteResultMessagingUtils.messageDialogWithDetails(result, "Delete failed", TaxeditorEditorPlugin.PLUGIN_ID);
81
			} else if (!result.getUpdatedObjects().isEmpty()){
82
			    DeleteResultMessagingUtils.messageDialogWithDetails(result, "The Synonym could be deleted, but related object(s) could not be deleted", TaxeditorEditorPlugin.PLUGIN_ID);
83
			}
84
		}
85
	//	taxon.removeSynonym(synonym);
86
//				CdmStore.getTaxonService().deleteSynonymRelationships(synonym);
87
//				CdmStore.getTaxonService().delete(synonym);
88

    
89
		monitor.worked(40);
90

    
91
		// Redraw editor if exists
92

    
93
		return postExecute(element);
94
	}
95

    
96
	/** {@inheritDoc} */
97
	@Override
98
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
99
			throws ExecutionException {
100
		return execute(monitor, info);
101
	}
102

    
103
	/** {@inheritDoc} */
104
	@Override
105
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
106
			throws ExecutionException {
107

    
108
		// Add synonym to taxon
109
		element.addSynonym(synonym, synonymType);
110

    
111
		// Redraw editor if exists
112
		return postExecute(synonym);
113
	}
114
}
(14-14/19)