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
.operations
.name
;
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
.SynonymRelationship
;
22 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
23 import eu
.etaxonomy
.taxeditor
.editor
.name
.CdmParserController
;
24 import eu
.etaxonomy
.taxeditor
.operations
.AbstractEditorOperation
;
31 public class CreateSynonymInExisitingHomotypicalGroupOperation
extends
32 AbstractEditorOperation
{
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
) {
43 super(label
, undoContext
, taxon
);
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 CdmParserController
.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
);
69 return redrawOpenEditor();
73 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
76 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
77 throws ExecutionException
{
78 return execute(monitor
, info
);
82 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
85 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
86 throws ExecutionException
{
88 taxon
.removeSynonymRelation(synonymRelationship
);
90 return redrawOpenEditor();