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
.Synonym
;
21 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationshipType
;
22 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
23 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
24 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
25 import eu
.etaxonomy
.taxeditor
.model
.TaxonUtil
;
33 public class ChangeConceptToSynonymOperation
extends
34 AbstractPostOperation
{
36 private Taxon concept
;
38 private HomotypicalGroup homotypicalGroup
;
40 private TaxonRelationship taxonRelationship
;
41 private TaxonRelationshipType oldRelationshipType
;
43 public ChangeConceptToSynonymOperation(String label
,
44 IUndoContext undoContext
, Taxon taxon
, Taxon concept
, HomotypicalGroup homotypicalGroup
,
45 IPostOperationEnabled editor
) {
46 super(label
, undoContext
, taxon
, editor
);
48 this.taxonRelationship
= TaxonUtil
.getRelationshipBetweenTwoTaxa(concept
, taxon
);
49 this.oldRelationshipType
= taxonRelationship
.getType();
51 this.concept
= concept
;
52 this.homotypicalGroup
= homotypicalGroup
;
56 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
59 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
60 throws ExecutionException
{
62 // Create new synonym using concept name
63 TaxonNameBase
<?
, ?
> synonymName
= concept
.getName();
64 Synonym synonym
= Synonym
.NewInstance(synonymName
, taxon
.getSec());
66 // Remove concept relation from taxon
67 taxon
.removeTaxon(concept
, oldRelationshipType
);
70 if(homotypicalGroup
!= null){
71 // // Add synonym to homotypical group
72 // homotypicalGroup.addTypifiedName(synonymName);
74 if (homotypicalGroup
.equals(taxon
.getHomotypicGroup())) {
75 taxon
.addHomotypicSynonym(synonym
, null, null);
77 taxon
.addHeterotypicSynonymName(synonymName
, homotypicalGroup
, null, null);
80 taxon
.addSynonym(synonym
, SynonymRelationshipType
.SYNONYM_OF());
83 return postExecute(synonym
);
87 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
90 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
91 throws ExecutionException
{
92 // TODO redo for change misapplied name ...
97 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
100 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
101 throws ExecutionException
{
102 // TODO undo for change misapplied name ...