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
.editor
.name
.operation
;
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
.hibernate
.HibernateProxyHelper
;
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
.operation
.AbstractPostTaxonOperation
;
24 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
28 * <li>Create synonym name using newSynonymText</li>
29 * <li>Add name to new homotypic group</li>
30 * <li>Create a new synonym for the taxon</li>
38 public class CreateSynonymInNewGroupOperation
extends AbstractPostTaxonOperation
{
40 // TODO replace this with TaxonNameBase
41 private final TaxonNameBase newSynonymName
;
42 private SynonymRelationship newSynonymRelationship
;
45 * <p>Constructor for CreateSynonymInNewGroupOperation.</p>
47 * @param label a {@link java.lang.String} object.
48 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
49 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
50 * @param newSynonymName a {@link eu.etaxonomy.cdm.model.name.TaxonNameBase} object.
51 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
53 public CreateSynonymInNewGroupOperation(String label
,
54 IUndoContext undoContext
, Taxon taxon
, TaxonNameBase newSynonymName
, IPostOperationEnabled postOperationEnabled
) {
55 super(label
, undoContext
, taxon
, postOperationEnabled
);
57 this.newSynonymName
= newSynonymName
;
61 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
65 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
66 throws ExecutionException
{
68 // Add name to new homotypic group
69 HomotypicalGroup
.NewInstance().addTypifiedName(newSynonymName
);
71 HibernateProxyHelper
.deproxy(element
);
72 // Create a new synonym for the taxon
73 newSynonymRelationship
= element
.addHeterotypicSynonymName(newSynonymName
);
76 return postExecute(newSynonymRelationship
.getSynonym());
80 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
84 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
85 throws ExecutionException
{
86 return execute(monitor
, info
);
90 * @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 element
.removeSynonymRelation(newSynonymRelationship
);
99 newSynonymRelationship
= null;
101 return postExecute(null);