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
;
24 * <p>CreateSynonymInExistingHomotypicalGroupOperation class.</p>
30 public class CreateSynonymInExistingHomotypicalGroupOperation
extends
31 AbstractPostOperation
{
33 private HomotypicalGroup group
;
34 private TaxonNameBase newSynonymName
;
36 private SynonymRelationship synonymRelationship
;
39 * <p>Constructor for CreateSynonymInExistingHomotypicalGroupOperation.</p>
41 * @param label a {@link java.lang.String} object.
42 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
43 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
44 * @param group a {@link eu.etaxonomy.cdm.model.name.HomotypicalGroup} object.
45 * @param newSynonymName a {@link eu.etaxonomy.cdm.model.name.TaxonNameBase} object.
46 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operations.IPostOperationEnabled} object.
48 public CreateSynonymInExistingHomotypicalGroupOperation(String label
,
49 IUndoContext undoContext
, Taxon taxon
, HomotypicalGroup group
, TaxonNameBase newSynonymName
, IPostOperationEnabled postOperationEnabled
) {
50 super(label
, undoContext
, taxon
, postOperationEnabled
);
52 this.newSynonymName
= newSynonymName
;
56 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
60 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
61 throws ExecutionException
{
63 // Add name to given homotypic group
64 group
.addTypifiedName(newSynonymName
);
67 // Create a new synonym for the taxon
69 if(group
.equals(taxon
.getHomotypicGroup())){
70 synonymRelationship
= taxon
.addHomotypicSynonymName(newSynonymName
, null, null);
72 synonymRelationship
= taxon
.addHeterotypicSynonymName(newSynonymName
);
76 // Synonym affectedSynonym = null;
78 // for(Synonym synonym : group.getSynonymsInGroup(taxon.getSec())){
79 // if(synonym.getName() == synonymName){
80 // affectedSynonym = synonym;
85 return postExecute(synonymRelationship
.getSynonym());
89 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
93 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
94 throws ExecutionException
{
95 return execute(monitor
, info
);
99 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
103 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
104 throws ExecutionException
{
106 taxon
.removeSynonymRelation(synonymRelationship
);
108 return postExecute(null);