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
.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
;
18 import eu
.etaxonomy
.cdm
.model
.name
.HomotypicalGroup
;
19 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
20 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationship
;
21 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
22 import eu
.etaxonomy
.taxeditor
.store
.parser
.CdmParserUtil
;
29 public class CreateSynonymInExisitingHomotypicalGroupOperation
extends
30 AbstractPostOperation
{
32 private HomotypicalGroup group
;
33 private String newSynonymText
;
35 private SynonymRelationship synonymRelationship
;
37 public CreateSynonymInExisitingHomotypicalGroupOperation(String label
,
38 IUndoContext undoContext
, Taxon taxon
, HomotypicalGroup group
, String newSynonymText
, IPostOperationEnabled postOperationEnabled
) {
39 super(label
, undoContext
, taxon
, postOperationEnabled
);
41 this.newSynonymText
= newSynonymText
;
45 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
48 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
49 throws ExecutionException
{
51 // Create synonym name using newSynonymText
52 TaxonNameBase
<?
, ?
> synonymName
=
53 CdmParserUtil
.parseFullReference(newSynonymText
, null, null);
55 // Add name to given homotypic group
56 group
.addTypifiedName(synonymName
);
58 // Create a new synonym for the taxon
60 if(group
.equals(taxon
.getHomotypicGroup())){
61 synonymRelationship
= taxon
.addHomotypicSynonymName(synonymName
, null, null);
63 synonymRelationship
= taxon
.addHeterotypicSynonymName(synonymName
);
66 // Synonym affectedSynonym = null;
68 // for(Synonym synonym : group.getSynonymsInGroup(taxon.getSec())){
69 // if(synonym.getName() == synonymName){
70 // affectedSynonym = synonym;
75 return postExecute(synonymRelationship
.getSynonym());
79 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
82 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
83 throws ExecutionException
{
84 return execute(monitor
, info
);
88 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
91 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
92 throws ExecutionException
{
94 taxon
.removeSynonymRelation(synonymRelationship
);
96 return postExecute(null);