2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.store
.operations
;
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
;
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
;
31 public class CreateSynonymInExisitingHomotypicalGroupOperation
extends
32 AbstractPostOperation
{
33 private static final Logger logger
= Logger
34 .getLogger(CreateSynonymInExisitingHomotypicalGroupOperation
.class);
36 private HomotypicalGroup group
;
37 private String newSynonymText
;
39 private SynonymRelationship synonymRelationship
;
41 public CreateSynonymInExisitingHomotypicalGroupOperation(String label
,
42 IUndoContext undoContext
, Taxon taxon
, HomotypicalGroup group
, String newSynonymText
, IPostOperationEnabled postOperationEnabled
) {
43 super(label
, undoContext
, taxon
, postOperationEnabled
);
45 this.newSynonymText
= newSynonymText
;
49 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
52 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
53 throws ExecutionException
{
55 // Create synonym name using newSynonymText
56 TaxonNameBase synonymName
=
57 CdmParserUtil
.parseFullReference(newSynonymText
, null, null);
59 // Add name to given homotypic group
60 group
.addTypifiedName(synonymName
);
62 // Create a new synonym for the taxon
64 if(group
.equals(taxon
.getHomotypicGroup())){
65 synonymRelationship
= taxon
.addHomotypicSynonymName(synonymName
, null, null);
67 synonymRelationship
= taxon
.addHeterotypicSynonymName(synonymName
);
70 // Synonym affectedSynonym = null;
72 // for(Synonym synonym : group.getSynonymsInGroup(taxon.getSec())){
73 // if(synonym.getName() == synonymName){
74 // affectedSynonym = synonym;
79 return postExecute(synonymRelationship
.getSynonym());
83 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
86 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
87 throws ExecutionException
{
88 return execute(monitor
, info
);
92 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
95 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
96 throws ExecutionException
{
98 taxon
.removeSynonymRelation(synonymRelationship
);
100 return postExecute(null);