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.CdmApplicationController;
|
21
|
import eu.etaxonomy.cdm.api.service.ITaxonService;
|
22
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
23
|
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
|
24
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
25
|
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
|
26
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
27
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
28
|
|
29
|
/**
|
30
|
* <p>DeleteSynonymOperation class.</p>
|
31
|
*
|
32
|
* @author p.ciardelli
|
33
|
* @created 14.01.2009
|
34
|
* @version 1.0
|
35
|
*/
|
36
|
public class DeleteSynonymOperation extends AbstractPostOperation {
|
37
|
|
38
|
private Synonym synonym;
|
39
|
private Set<SynonymRelationshipType> synonymTypes;
|
40
|
|
41
|
/**
|
42
|
* <p>Constructor for DeleteSynonymOperation.</p>
|
43
|
*
|
44
|
* @param label a {@link java.lang.String} object.
|
45
|
* @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
|
46
|
* @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
|
47
|
* @param synonym a {@link eu.etaxonomy.cdm.model.taxon.Synonym} object.
|
48
|
* @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
|
49
|
*/
|
50
|
public DeleteSynonymOperation(String label, IUndoContext undoContext,
|
51
|
Taxon taxon, Synonym synonym, IPostOperationEnabled postOperationEnabled) {
|
52
|
super(label, undoContext, taxon, postOperationEnabled);
|
53
|
this.synonym = synonym;
|
54
|
}
|
55
|
|
56
|
/* (non-Javadoc)
|
57
|
* @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
58
|
*/
|
59
|
/** {@inheritDoc} */
|
60
|
@Override
|
61
|
public IStatus execute(IProgressMonitor monitor, IAdaptable info)
|
62
|
throws ExecutionException {
|
63
|
|
64
|
// Store synonymRelationshipType for later undo operations
|
65
|
synonymTypes = synonym.getRelationType(taxon);
|
66
|
monitor.worked(20);
|
67
|
|
68
|
// Remove synonym from taxon
|
69
|
|
70
|
CdmApplicationController controller;
|
71
|
|
72
|
controller = (CdmApplicationController) CdmStore.getCurrentApplicationConfiguration();
|
73
|
|
74
|
ITaxonService service = controller.getTaxonService();
|
75
|
if (synonym.getId() == 0){
|
76
|
taxon.removeSynonym(synonym);
|
77
|
|
78
|
} else {
|
79
|
service.deleteSynonym(synonym, null);
|
80
|
}
|
81
|
// taxon.removeSynonym(synonym);
|
82
|
// CdmStore.getTaxonService().deleteSynonymRelationships(synonym);
|
83
|
// CdmStore.getTaxonService().delete(synonym);
|
84
|
|
85
|
monitor.worked(40);
|
86
|
|
87
|
// Redraw editor if exists
|
88
|
|
89
|
return postExecute(taxon);
|
90
|
}
|
91
|
|
92
|
/* (non-Javadoc)
|
93
|
* @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
94
|
*/
|
95
|
/** {@inheritDoc} */
|
96
|
@Override
|
97
|
public IStatus redo(IProgressMonitor monitor, IAdaptable info)
|
98
|
throws ExecutionException {
|
99
|
return execute(monitor, info);
|
100
|
}
|
101
|
|
102
|
/* (non-Javadoc)
|
103
|
* @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
104
|
*/
|
105
|
/** {@inheritDoc} */
|
106
|
@Override
|
107
|
public IStatus undo(IProgressMonitor monitor, IAdaptable info)
|
108
|
throws ExecutionException {
|
109
|
|
110
|
// Add synonym to taxon
|
111
|
for (SynonymRelationshipType synonymType : synonymTypes){
|
112
|
taxon.addSynonym(synonym, synonymType);
|
113
|
}
|
114
|
|
115
|
// Redraw editor if exists
|
116
|
return postExecute(synonym);
|
117
|
}
|
118
|
}
|