Project

General

Profile

Download (3.29 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 org.eclipse.core.commands.ExecutionException;
13
import org.eclipse.core.commands.operations.IUndoContext;
14
import org.eclipse.core.runtime.IAdaptable;
15
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.core.runtime.IStatus;
17
import org.eclipse.core.runtime.Status;
18

    
19
import eu.etaxonomy.cdm.api.application.ICdmRepository;
20
import eu.etaxonomy.cdm.api.service.DeleteResult;
21
import eu.etaxonomy.cdm.api.service.ITaxonService;
22
import eu.etaxonomy.cdm.api.service.config.TaxonBaseDeletionConfigurator;
23
import eu.etaxonomy.cdm.model.taxon.Synonym;
24
import eu.etaxonomy.cdm.model.taxon.SynonymType;
25
import eu.etaxonomy.cdm.model.taxon.Taxon;
26
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
27
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
28
import eu.etaxonomy.taxeditor.store.CdmStore;
29

    
30
/**
31
 * <p>DeleteSynonymOperation class.</p>
32
 *
33
 * @author p.ciardelli
34
 * @created 14.01.2009
35
 */
36
public class DeleteSynonymOperation extends DeleteTaxonBaseOperation {
37

    
38
	private final Synonym synonym;
39
	private SynonymType synonymType;
40

    
41

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

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

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

    
66
		// Remove synonym from taxon
67
		ICdmRepository controller;
68

    
69
		controller = CdmStore.getCurrentApplicationConfiguration();
70

    
71
		ITaxonService service = controller.getTaxonService();
72

    
73

    
74
		result = service.isDeletable(synonym.getUuid(), configurator);
75

    
76

    
77

    
78
		monitor.worked(40);
79

    
80
		// Redraw editor if exists
81
		return Status.OK_STATUS;
82
//		return postExecute(element);
83
	}
84

    
85
	@Override
86
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
87
			throws ExecutionException {
88
		return execute(monitor, info);
89
	}
90

    
91
	@Override
92
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
93
			throws ExecutionException {
94

    
95
		// Add synonym to taxon
96
		element.addSynonym(synonym, synonymType);
97

    
98
		// Redraw editor if exists
99
		return postExecute(synonym);
100
	}
101

    
102
    @Override
103
    public DeleteResult getResult() {
104
        return result;
105
    }
106

    
107
    public void setResult(DeleteResult result) {
108
        this.result = result;
109
    }
110
}
(13-13/15)