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
|
|
18
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
19
|
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
|
20
|
import eu.etaxonomy.cdm.model.name.HybridRelationship;
|
21
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
22
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
23
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
24
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
25
|
|
26
|
/**
|
27
|
* <ol>
|
28
|
* <li>Create synonym name using newSynonymText</li>
|
29
|
* <li>Add name to new homotypic group</li>
|
30
|
* <li>Create a new synonym for the taxon</li>
|
31
|
* </ol>
|
32
|
*
|
33
|
* @author p.ciardelli
|
34
|
* @author n.hoffmann
|
35
|
* @created 16.01.2009
|
36
|
*/
|
37
|
public class CreateSynonymInNewGroupOperation extends CreateNewTaxonBaseOperation {
|
38
|
|
39
|
private final TaxonName newSynonymName;
|
40
|
private Synonym newSynonym;
|
41
|
|
42
|
/**
|
43
|
* <p>Constructor for CreateSynonymInNewGroupOperation.</p>
|
44
|
*
|
45
|
* @param label a {@link java.lang.String} object.
|
46
|
* @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
|
47
|
* @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
|
48
|
* @param newSynonymName a {@link eu.etaxonomy.cdm.model.name.TaxonNameBase} object.
|
49
|
* @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
|
50
|
*/
|
51
|
public CreateSynonymInNewGroupOperation(String label,
|
52
|
IUndoContext undoContext, Taxon taxon, TaxonName newSynonymName, IPostOperationEnabled postOperationEnabled) {
|
53
|
super(label, undoContext, taxon, postOperationEnabled);
|
54
|
|
55
|
this.newSynonymName = newSynonymName;
|
56
|
}
|
57
|
|
58
|
@Override
|
59
|
public IStatus execute(IProgressMonitor monitor, IAdaptable info)
|
60
|
throws ExecutionException {
|
61
|
|
62
|
// Add name to new homotypic group
|
63
|
HomotypicalGroup.NewInstance().addTypifiedName(newSynonymName);
|
64
|
monitor.worked(20);
|
65
|
HibernateProxyHelper.deproxy(element);
|
66
|
newSynonym = element.addHeterotypicSynonymName(newSynonymName);
|
67
|
for (HybridRelationship rel : newSynonymName.getHybridChildRelations()){
|
68
|
if (!rel.getHybridName().isPersited()) {
|
69
|
addToSaveList(rel.getHybridName());
|
70
|
}
|
71
|
if (!rel.getParentName().isPersited()) {
|
72
|
addToSaveList(rel.getParentName());
|
73
|
}
|
74
|
}
|
75
|
addToSaveList(newSynonym);
|
76
|
monitor.worked(40);
|
77
|
|
78
|
return postExecute(newSynonym);
|
79
|
}
|
80
|
|
81
|
@Override
|
82
|
public IStatus redo(IProgressMonitor monitor, IAdaptable info)
|
83
|
throws ExecutionException {
|
84
|
return execute(monitor, info);
|
85
|
}
|
86
|
|
87
|
@Override
|
88
|
public IStatus undo(IProgressMonitor monitor, IAdaptable info)
|
89
|
throws ExecutionException {
|
90
|
|
91
|
// Remove the synonym
|
92
|
element.removeSynonym(newSynonym);
|
93
|
newSynonym = null;
|
94
|
|
95
|
return postExecute(null);
|
96
|
}
|
97
|
}
|