Project

General

Profile

Download (4 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.ui.IWorkbenchPage;
18

    
19
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
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.SynonymDeletionConfigurator;
24
import eu.etaxonomy.cdm.api.service.config.TaxonBaseDeletionConfigurator;
25
import eu.etaxonomy.cdm.model.taxon.Synonym;
26
import eu.etaxonomy.cdm.model.taxon.SynonymType;
27
import eu.etaxonomy.cdm.model.taxon.Taxon;
28
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
29
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
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 DeleteTaxonBaseOperation {
39

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

    
43

    
44
	/**
45
	 * <p>Constructor for DeleteSynonymOperation.</p>
46
	 *
47
	 * @param label a {@link java.lang.String} object.
48
	 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
49
	 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
50
	 * @param synonym a {@link eu.etaxonomy.cdm.model.taxon.Synonym} object.
51
	 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
52
	 */
53
	public DeleteSynonymOperation(String label, IUndoContext undoContext, TaxonBaseDeletionConfigurator configurator,IWorkbenchPage activePage,
54
			Taxon taxon, Synonym synonym, IPostOperationEnabled postOperationEnabled, IConversationEnabled conversationEnabled,ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
55
		super(label, undoContext, configurator, activePage, postOperationEnabled, conversationEnabled, cdmEntitySessionEnabled);
56
		this.synonym = synonym;
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
		ICdmApplicationConfiguration controller;
70

    
71
		controller = CdmStore.getCurrentApplicationConfiguration();
72

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

    
77
		} else {
78
			//TODO: this should be moved to the handler, the operations should not contain ui code
79
			result = service.deleteSynonym(synonym.getUuid(), (SynonymDeletionConfigurator)configurator);
80

    
81
		}
82
	//	taxon.removeSynonym(synonym);
83
//				CdmStore.getTaxonService().deleteSynonymRelationships(synonym);
84
//				CdmStore.getTaxonService().delete(synonym);
85

    
86
		monitor.worked(40);
87

    
88
		// Redraw editor if exists
89

    
90
		return postExecute(element);
91
	}
92

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

    
100
	/** {@inheritDoc} */
101
	@Override
102
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
103
			throws ExecutionException {
104

    
105
		// Add synonym to taxon
106
		element.addSynonym(synonym, synonymType);
107

    
108
		// Redraw editor if exists
109
		return postExecute(synonym);
110
	}
111

    
112
    /**
113
     * @return the result
114
     */
115
    @Override
116
    public DeleteResult getResult() {
117
        return result;
118
    }
119

    
120
    /**
121
     * @param result the result to set
122
     */
123
    public void setResult(DeleteResult result) {
124
        this.result = result;
125
    }
126
}
(14-14/19)