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