Project

General

Profile

Download (3.57 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.conversation.IConversationEnabled;
21
import eu.etaxonomy.cdm.api.service.DeleteResult;
22
import eu.etaxonomy.cdm.api.service.ITaxonService;
23
import eu.etaxonomy.cdm.api.service.config.TaxonBaseDeletionConfigurator;
24
import eu.etaxonomy.cdm.model.taxon.Synonym;
25
import eu.etaxonomy.cdm.model.taxon.SynonymType;
26
import eu.etaxonomy.cdm.model.taxon.Taxon;
27
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
28
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
29
import eu.etaxonomy.taxeditor.store.CdmStore;
30

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

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

    
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, TaxonBaseDeletionConfigurator configurator,
53
			Taxon taxon, Synonym synonym, IPostOperationEnabled postOperationEnabled, IConversationEnabled conversationEnabled,ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
54
		super(label, undoContext, configurator, postOperationEnabled, conversationEnabled, cdmEntitySessionEnabled);
55
		this.synonym = synonym;
56
		this.element = taxon;
57
	}
58

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

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

    
68
		// Remove synonym from taxon
69
		ICdmRepository controller;
70

    
71
		controller = CdmStore.getCurrentApplicationConfiguration();
72

    
73
		ITaxonService service = controller.getTaxonService();
74

    
75

    
76
		result = service.isDeletable(synonym.getUuid(), configurator);
77

    
78

    
79

    
80
		monitor.worked(40);
81

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

    
87
	/** {@inheritDoc} */
88
	@Override
89
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
90
			throws ExecutionException {
91
		return execute(monitor, info);
92
	}
93

    
94
	/** {@inheritDoc} */
95
	@Override
96
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
97
			throws ExecutionException {
98

    
99
		// Add synonym to taxon
100
		element.addSynonym(synonym, synonymType);
101

    
102
		// Redraw editor if exists
103
		return postExecute(synonym);
104
	}
105

    
106
    /**
107
     * @return the result
108
     */
109
    @Override
110
    public DeleteResult getResult() {
111
        return result;
112
    }
113

    
114
    /**
115
     * @param result the result to set
116
     */
117
    public void setResult(DeleteResult result) {
118
        this.result = result;
119
    }
120
}
(13-13/15)