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
;
14 import org
.eclipse
.core
.commands
.ExecutionException
;
15 import org
.eclipse
.core
.commands
.operations
.IUndoContext
;
16 import org
.eclipse
.core
.runtime
.IAdaptable
;
17 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
18 import org
.eclipse
.core
.runtime
.IStatus
;
20 import eu
.etaxonomy
.cdm
.model
.name
.HomotypicalGroup
;
21 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
22 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationship
;
23 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
24 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
25 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
26 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
29 * <p>ChangeConceptToSynonymOperation class.</p>
36 public class ChangeConceptToSynonymOperation
extends
37 AbstractPostOperation
{
39 private Taxon concept
;
41 private HomotypicalGroup homotypicalGroup
;
43 private TaxonRelationship taxonRelationship
;
44 private TaxonRelationshipType oldRelationshipType
;
46 private SynonymRelationship newSynonymRelationship
;
49 * <p>Constructor for ChangeConceptToSynonymOperation.</p>
51 * @param label a {@link java.lang.String} object.
52 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
53 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
54 * @param concept a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
55 * @param homotypicalGroup a {@link eu.etaxonomy.cdm.model.name.HomotypicalGroup} object.
56 * @param editor a {@link eu.etaxonomy.taxeditor.operations.IPostOperationEnabled} object.
58 public ChangeConceptToSynonymOperation(String label
,
59 IUndoContext undoContext
, Taxon taxon
, Taxon concept
, HomotypicalGroup homotypicalGroup
,
60 IPostOperationEnabled editor
) {
61 super(label
, undoContext
, taxon
, editor
);
63 Set
<TaxonRelationship
> taxonRelationships
= taxon
.getTaxonRelations(concept
);
65 if(taxonRelationships
.size() > 1){
66 StoreUtil
.warningDialog("Multiple relations between taxa", this, "There are multiple relations between the " +
67 "accepted and the related taxon. This case is not handled by the software yet");
71 this.taxonRelationship
= taxonRelationships
.iterator().next();
72 this.oldRelationshipType
= taxonRelationship
.getType();
74 this.concept
= concept
;
75 this.homotypicalGroup
= homotypicalGroup
!= null ? homotypicalGroup
: HomotypicalGroup
.NewInstance();
79 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
83 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
84 throws ExecutionException
{
86 // Create new synonym using concept name
87 TaxonNameBase
<?
, ?
> synonymName
= concept
.getName();
89 // Remove concept relation from taxon
90 taxon
.removeTaxon(concept
, oldRelationshipType
);
93 // Add name to new homotypic group
94 homotypicalGroup
.addTypifiedName(synonymName
);
97 // Create a new synonym for the taxon
98 newSynonymRelationship
= taxon
.addHeterotypicSynonymName(synonymName
);
100 return postExecute(newSynonymRelationship
.getSynonym());
104 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
108 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
109 throws ExecutionException
{
110 // TODO redo for change misapplied name ...
115 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
119 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
120 throws ExecutionException
{
121 // TODO undo for change misapplied name ...