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.store.operations;
|
11
|
|
12
|
import java.util.Set;
|
13
|
|
14
|
import org.apache.log4j.Logger;
|
15
|
import org.eclipse.core.commands.ExecutionException;
|
16
|
import org.eclipse.core.commands.operations.IUndoContext;
|
17
|
import org.eclipse.core.runtime.IAdaptable;
|
18
|
import org.eclipse.core.runtime.IProgressMonitor;
|
19
|
import org.eclipse.core.runtime.IStatus;
|
20
|
|
21
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
22
|
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
|
23
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
24
|
|
25
|
/**
|
26
|
* @author p.ciardelli
|
27
|
* @created 14.01.2009
|
28
|
* @version 1.0
|
29
|
*/
|
30
|
public class DeleteSynonymOperation extends AbstractPostOperation {
|
31
|
private static final Logger logger = Logger
|
32
|
.getLogger(DeleteSynonymOperation.class);
|
33
|
|
34
|
private Synonym synonym;
|
35
|
private Set<SynonymRelationshipType> synonymTypes;
|
36
|
|
37
|
public DeleteSynonymOperation(String label, IUndoContext undoContext,
|
38
|
Taxon taxon, Synonym synonym, IPostOperationEnabled postOperationEnabled) {
|
39
|
super(label, undoContext, taxon, postOperationEnabled);
|
40
|
this.synonym = synonym;
|
41
|
}
|
42
|
|
43
|
/* (non-Javadoc)
|
44
|
* @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
45
|
*/
|
46
|
@Override
|
47
|
public IStatus execute(IProgressMonitor monitor, IAdaptable info)
|
48
|
throws ExecutionException {
|
49
|
|
50
|
// Store synonymRelationshipType for later undo operations
|
51
|
synonymTypes = synonym.getRelationType(taxon);
|
52
|
|
53
|
// Remove synonym from taxon
|
54
|
taxon.removeSynonym(synonym);
|
55
|
|
56
|
// Redraw editor if exists
|
57
|
return postExecute(null);
|
58
|
}
|
59
|
|
60
|
/* (non-Javadoc)
|
61
|
* @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
62
|
*/
|
63
|
@Override
|
64
|
public IStatus redo(IProgressMonitor monitor, IAdaptable info)
|
65
|
throws ExecutionException {
|
66
|
return execute(monitor, info);
|
67
|
}
|
68
|
|
69
|
/* (non-Javadoc)
|
70
|
* @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
71
|
*/
|
72
|
@Override
|
73
|
public IStatus undo(IProgressMonitor monitor, IAdaptable info)
|
74
|
throws ExecutionException {
|
75
|
|
76
|
// Add synonym to taxon
|
77
|
for (SynonymRelationshipType synonymType : synonymTypes){
|
78
|
taxon.addSynonym(synonym, synonymType);
|
79
|
}
|
80
|
|
81
|
// Redraw editor if exists
|
82
|
return postExecute(synonym);
|
83
|
}
|
84
|
}
|