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
;
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
.operation
.AbstractPostTaxonOperation
;
27 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
28 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
31 * <p>ChangeConceptToSynonymOperation class.</p>
38 public class ChangeConceptToSynonymOperation
extends
39 AbstractPostTaxonOperation
{
41 private Taxon concept
;
43 private HomotypicalGroup homotypicalGroup
;
45 private TaxonRelationship taxonRelationship
;
46 private TaxonRelationshipType oldRelationshipType
;
48 private SynonymRelationship newSynonymRelationship
;
51 * <p>Constructor for ChangeConceptToSynonymOperation.</p>
53 * @param label a {@link java.lang.String} object.
54 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
55 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
56 * @param concept a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
57 * @param homotypicalGroup a {@link eu.etaxonomy.cdm.model.name.HomotypicalGroup} object.
58 * @param editor a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
60 public ChangeConceptToSynonymOperation(String label
,
61 IUndoContext undoContext
, Taxon taxon
, Taxon concept
, HomotypicalGroup homotypicalGroup
,
62 IPostOperationEnabled editor
) {
63 super(label
, undoContext
, taxon
, editor
);
65 Set
<TaxonRelationship
> taxonRelationships
= taxon
.getTaxonRelations(concept
);
67 if(taxonRelationships
.size() > 1){
68 StoreUtil
.warningDialog("Multiple relations between taxa", this, "There are multiple relations between the " +
69 "accepted and the related taxon. This case is not handled by the software yet");
73 this.taxonRelationship
= taxonRelationships
.iterator().next();
74 this.oldRelationshipType
= taxonRelationship
.getType();
76 this.concept
= concept
;
77 this.homotypicalGroup
= homotypicalGroup
!= null ? homotypicalGroup
: HomotypicalGroup
.NewInstance();
81 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
85 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
86 throws ExecutionException
{
88 // Create new synonym using concept name
89 TaxonNameBase
<?
, ?
> synonymName
= concept
.getName();
91 // Remove concept relation from taxon
92 taxon
.removeTaxon(concept
, oldRelationshipType
);
95 // Add name to new homotypic group
96 homotypicalGroup
.addTypifiedName(synonymName
);
99 // Create a new synonym for the taxon
100 newSynonymRelationship
= taxon
.addHeterotypicSynonymName(synonymName
);
102 return postExecute(newSynonymRelationship
.getSynonym());
106 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
110 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
111 throws ExecutionException
{
112 // TODO redo for change misapplied name ...
117 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
121 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
122 throws ExecutionException
{
123 // TODO undo for change misapplied name ...