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
.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
.taxeditor
.operation
.AbstractPostOperation
;
24 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
27 * Change the homotypical group of a given synonym.
33 public class ChangeHomotypicGroupOperation
extends AbstractPostOperation
{
36 * The synonym to be moved.
38 private Synonym synonym
;
40 * The former homotypical group the synonym belonged to
42 private HomotypicalGroup oldHomotypicalGroup
;
44 * The homotypical group the synonym is to be moved to
46 private HomotypicalGroup newHomotypicalGroup
;
49 * <p>Constructor for ChangeHomotypicGroupOperation.</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 synonym a {@link eu.etaxonomy.cdm.model.taxon.Synonym} object.
55 * @param newHomotypicalGroup a {@link eu.etaxonomy.cdm.model.name.HomotypicalGroup} object.
56 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
58 public ChangeHomotypicGroupOperation(String label
, IUndoContext undoContext
,
59 Taxon taxon
, Synonym synonym
, HomotypicalGroup newHomotypicalGroup
, IPostOperationEnabled postOperationEnabled
) {
60 super(label
, undoContext
, taxon
, postOperationEnabled
);
62 this.synonym
= synonym
;
64 throw new IllegalArgumentException(
65 "A null synonym was provided.");
68 this.oldHomotypicalGroup
= synonym
.getHomotypicGroup();
69 this.newHomotypicalGroup
= newHomotypicalGroup
!= null ? newHomotypicalGroup
: HomotypicalGroup
.NewInstance();
73 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
77 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
78 throws ExecutionException
{
81 TaxonNameBase
<?
, ?
> synonymName
= synonym
.getName();
84 // TODO pass in homotypical group's taxon in case we are dragging from one editor to another
87 oldHomotypicalGroup
.removeTypifiedName(synonymName
);
90 newHomotypicalGroup
.addTypifiedName(synonymName
);
92 if(! synonym
.getAcceptedTaxa().contains(taxon
)){
93 for(Taxon acceptedTaxon
: synonym
.getAcceptedTaxa()){
94 acceptedTaxon
.removeSynonym(synonym
);
97 SynonymRelationshipType type
= SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF();
98 if(newHomotypicalGroup
.getTypifiedNames().contains(taxon
.getName())){
99 type
= SynonymRelationshipType
.HOMOTYPIC_SYNONYM_OF();
102 taxon
.addSynonym(synonym
, type
);
105 // Redraw editor if it exists
106 return postExecute(synonym
);
110 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
114 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
115 throws ExecutionException
{
116 return execute(monitor
, info
);
120 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
124 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
125 throws ExecutionException
{
128 TaxonNameBase
<?
, ?
> synonymName
= this.synonym
.getName();
129 if(synonymName
== null){
133 // TODO pass in homotypical group's taxon in case we are dragging from one editor to another
136 newHomotypicalGroup
.removeTypifiedName(synonymName
);
137 oldHomotypicalGroup
.addTypifiedName(synonymName
);
139 // Redraw editor if it exists
140 return postExecute(synonym
);