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.model.name.HomotypicalGroup;
|
19
|
import eu.etaxonomy.cdm.model.name.HybridRelationship;
|
20
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
21
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
22
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
23
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
24
|
|
25
|
/**
|
26
|
* <p>CreateSynonymInExistingHomotypicalGroupOperation class.</p>
|
27
|
*
|
28
|
* @author n.hoffmann
|
29
|
* @created 02.02.2009
|
30
|
*/
|
31
|
public class CreateSynonymInExistingHomotypicalGroupOperation extends
|
32
|
CreateNewTaxonBaseOperation {
|
33
|
|
34
|
private final HomotypicalGroup group;
|
35
|
private final TaxonName newSynonymName;
|
36
|
|
37
|
private Synonym synonym;
|
38
|
|
39
|
/**
|
40
|
* <p>Constructor for CreateSynonymInExistingHomotypicalGroupOperation.</p>
|
41
|
*
|
42
|
* @param label a {@link java.lang.String} object.
|
43
|
* @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
|
44
|
* @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
|
45
|
* @param group a {@link eu.etaxonomy.cdm.model.name.HomotypicalGroup} object.
|
46
|
* @param newSynonymName a {@link eu.etaxonomy.cdm.model.name.TaxonNameBase} object.
|
47
|
* @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
|
48
|
*/
|
49
|
public CreateSynonymInExistingHomotypicalGroupOperation(String label,
|
50
|
IUndoContext undoContext, Taxon taxon, HomotypicalGroup group,
|
51
|
TaxonName newSynonymName, IPostOperationEnabled postOperationEnabled) {
|
52
|
super(label, undoContext, taxon, postOperationEnabled);
|
53
|
this.group = group;
|
54
|
this.newSynonymName = newSynonymName;
|
55
|
}
|
56
|
|
57
|
/** {@inheritDoc} */
|
58
|
@Override
|
59
|
public IStatus execute(IProgressMonitor monitor, IAdaptable info)
|
60
|
throws ExecutionException {
|
61
|
|
62
|
// Add name to given homotypic group
|
63
|
|
64
|
// HomotypicalSynonymGroupE4 groupContainer = ((TaxonNameEditorE4)postOperationEnabled).getHomotypicalGroupContainer(group);
|
65
|
group.addTypifiedName(newSynonymName);
|
66
|
// groupContainer.add(groupedContainer);
|
67
|
monitor.worked(20);
|
68
|
|
69
|
// Create a new synonym for the taxon
|
70
|
// TODO add citations
|
71
|
if(group.equals(element.getHomotypicGroup())){
|
72
|
synonym = element.addHomotypicSynonymName(newSynonymName);
|
73
|
}else{
|
74
|
synonym = element.addHeterotypicSynonymName(newSynonymName);
|
75
|
}
|
76
|
for (HybridRelationship rel : newSynonymName.getHybridChildRelations()){
|
77
|
if (!rel.getHybridName().isPersited()) {
|
78
|
addToSaveList(rel.getHybridName());
|
79
|
}
|
80
|
if (!rel.getParentName().isPersited()) {
|
81
|
addToSaveList(rel.getParentName());
|
82
|
}
|
83
|
}
|
84
|
addToSaveList(synonym);
|
85
|
monitor.worked(40);
|
86
|
|
87
|
// Synonym affectedSynonym = null;
|
88
|
//
|
89
|
// for(Synonym synonym : group.getSynonymsInGroup(taxon.getSec())){
|
90
|
// if(synonym.getName() == synonymName){
|
91
|
// affectedSynonym = synonym;
|
92
|
// break;
|
93
|
// }
|
94
|
// }
|
95
|
|
96
|
return postExecute(synonym);
|
97
|
}
|
98
|
|
99
|
/** {@inheritDoc} */
|
100
|
@Override
|
101
|
public IStatus redo(IProgressMonitor monitor, IAdaptable info)
|
102
|
throws ExecutionException {
|
103
|
return execute(monitor, info);
|
104
|
}
|
105
|
|
106
|
/** {@inheritDoc} */
|
107
|
@Override
|
108
|
public IStatus undo(IProgressMonitor monitor, IAdaptable info)
|
109
|
throws ExecutionException {
|
110
|
|
111
|
element.removeSynonym(synonym);
|
112
|
|
113
|
return postExecute(null);
|
114
|
}
|
115
|
}
|