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
;
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
.StoreUtil
;
26 * <li>Create synonym name using newSynonymText</li>
27 * <li>Add name to new homotypic group</li>
28 * <li>Create a new synonym for the taxon</li>
35 public class CreateSynonymInNewGroupOperation
extends AbstractPostOperation
{
37 // TODO replace this with TaxonNameBase
38 private TaxonNameBase newSynonymName
;
39 private SynonymRelationship newSynonymRelationship
;
41 public CreateSynonymInNewGroupOperation(String label
,
42 IUndoContext undoContext
, Taxon taxon
, TaxonNameBase newSynonymName
, IPostOperationEnabled postOperationEnabled
) {
43 super(label
, undoContext
, taxon
, postOperationEnabled
);
45 this.newSynonymName
= newSynonymName
;
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 // Start the main progress monitor.
56 IProgressMonitor newMonitor
= StoreUtil
.startMainMonitor(monitor
,"Creating Synonym in new Homotypic Group", 4);
64 // Add name to new homotypic group
65 HomotypicalGroup
.NewInstance().addTypifiedName(newSynonymName
);
66 StoreUtil
.isCanceled(newMonitor
, 1);
68 // Create a new synonym for the taxon
69 newSynonymRelationship
= taxon
.addHeterotypicSynonymName(newSynonymName
);
70 StoreUtil
.isCanceled(newMonitor
, 1);
74 // Stop the progress monitor.
78 return postExecute(newSynonymRelationship
.getSynonym());
82 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
85 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
86 throws ExecutionException
{
87 return execute(monitor
, info
);
91 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
94 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
95 throws ExecutionException
{
98 taxon
.removeSynonymRelation(newSynonymRelationship
);
99 newSynonymRelationship
= null;
101 return postExecute(null);