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 org.apache.log4j.Logger;
|
13
|
import org.eclipse.core.commands.ExecutionException;
|
14
|
import org.eclipse.core.commands.operations.IUndoContext;
|
15
|
import org.eclipse.core.runtime.IAdaptable;
|
16
|
import org.eclipse.core.runtime.IProgressMonitor;
|
17
|
import org.eclipse.core.runtime.IStatus;
|
18
|
|
19
|
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
|
20
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
21
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
22
|
import eu.etaxonomy.cdm.model.taxon.SynonymRelationship;
|
23
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
24
|
import eu.etaxonomy.taxeditor.store.parser.CdmParserUtil;
|
25
|
|
26
|
/**
|
27
|
* @author n.hoffmann
|
28
|
* @created 02.02.2009
|
29
|
* @version 1.0
|
30
|
*/
|
31
|
public class CreateSynonymInExisitingHomotypicalGroupOperation extends
|
32
|
AbstractPostOperation {
|
33
|
private static final Logger logger = Logger
|
34
|
.getLogger(CreateSynonymInExisitingHomotypicalGroupOperation.class);
|
35
|
|
36
|
private HomotypicalGroup group;
|
37
|
private String newSynonymText;
|
38
|
|
39
|
private SynonymRelationship synonymRelationship;
|
40
|
|
41
|
public CreateSynonymInExisitingHomotypicalGroupOperation(String label,
|
42
|
IUndoContext undoContext, Taxon taxon, HomotypicalGroup group, String newSynonymText, IPostOperationEnabled postOperationEnabled) {
|
43
|
super(label, undoContext, taxon, postOperationEnabled);
|
44
|
this.group = group;
|
45
|
this.newSynonymText = newSynonymText;
|
46
|
}
|
47
|
|
48
|
/* (non-Javadoc)
|
49
|
* @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
50
|
*/
|
51
|
@Override
|
52
|
public IStatus execute(IProgressMonitor monitor, IAdaptable info)
|
53
|
throws ExecutionException {
|
54
|
|
55
|
// Create synonym name using newSynonymText
|
56
|
TaxonNameBase synonymName =
|
57
|
CdmParserUtil.parseFullReference(newSynonymText, null, null);
|
58
|
|
59
|
// Add name to given homotypic group
|
60
|
group.addTypifiedName(synonymName);
|
61
|
|
62
|
// Create a new synonym for the taxon
|
63
|
// TODO add citations
|
64
|
if(group.equals(taxon.getHomotypicGroup())){
|
65
|
synonymRelationship = taxon.addHomotypicSynonymName(synonymName, null, null);
|
66
|
}else{
|
67
|
synonymRelationship = taxon.addHeterotypicSynonymName(synonymName);
|
68
|
}
|
69
|
|
70
|
// Synonym affectedSynonym = null;
|
71
|
//
|
72
|
// for(Synonym synonym : group.getSynonymsInGroup(taxon.getSec())){
|
73
|
// if(synonym.getName() == synonymName){
|
74
|
// affectedSynonym = synonym;
|
75
|
// break;
|
76
|
// }
|
77
|
// }
|
78
|
|
79
|
return postExecute(synonymRelationship.getSynonym());
|
80
|
}
|
81
|
|
82
|
/* (non-Javadoc)
|
83
|
* @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
84
|
*/
|
85
|
@Override
|
86
|
public IStatus redo(IProgressMonitor monitor, IAdaptable info)
|
87
|
throws ExecutionException {
|
88
|
return execute(monitor, info);
|
89
|
}
|
90
|
|
91
|
/* (non-Javadoc)
|
92
|
* @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
93
|
*/
|
94
|
@Override
|
95
|
public IStatus undo(IProgressMonitor monitor, IAdaptable info)
|
96
|
throws ExecutionException {
|
97
|
|
98
|
taxon.removeSynonymRelation(synonymRelationship);
|
99
|
|
100
|
return postExecute(null);
|
101
|
}
|
102
|
}
|