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
;
25 * Change the homotypical group of a given synonym.
31 public class ChangeHomotypicGroupOperation
extends AbstractPostOperation
{
34 * The synonym to be moved.
36 private Synonym synonym
;
38 * The former homotypical group the synonym belonged to
40 private HomotypicalGroup oldHomotypicalGroup
;
42 * The homotypical group the synonym is to be moved to
44 private HomotypicalGroup newHomotypicalGroup
;
47 * <p>Constructor for ChangeHomotypicGroupOperation.</p>
49 * @param label a {@link java.lang.String} object.
50 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
51 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
52 * @param synonym a {@link eu.etaxonomy.cdm.model.taxon.Synonym} object.
53 * @param newHomotypicalGroup a {@link eu.etaxonomy.cdm.model.name.HomotypicalGroup} object.
54 * @param editor a {@link eu.etaxonomy.taxeditor.operations.IPostOperationEnabled} object.
56 public ChangeHomotypicGroupOperation(String label
, IUndoContext undoContext
,
57 Taxon taxon
, Synonym synonym
, HomotypicalGroup newHomotypicalGroup
, IPostOperationEnabled editor
) {
58 super(label
, undoContext
, taxon
, editor
);
60 this.synonym
= synonym
;
62 throw new IllegalArgumentException(
63 "A null synonym was provided.");
66 this.oldHomotypicalGroup
= synonym
.getHomotypicGroup();
67 this.newHomotypicalGroup
= newHomotypicalGroup
!= null ? newHomotypicalGroup
: HomotypicalGroup
.NewInstance();
71 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
75 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
76 throws ExecutionException
{
79 TaxonNameBase
<?
, ?
> synonymName
= synonym
.getName();
82 // TODO pass in homotypical group's taxon in case we are dragging from one editor to another
85 oldHomotypicalGroup
.removeTypifiedName(synonymName
);
88 newHomotypicalGroup
.addTypifiedName(synonymName
);
90 if(! synonym
.getAcceptedTaxa().contains(taxon
)){
91 for(Taxon acceptedTaxon
: synonym
.getAcceptedTaxa()){
92 acceptedTaxon
.removeSynonym(synonym
);
95 SynonymRelationshipType type
= SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF();
96 if(newHomotypicalGroup
.getTypifiedNames().contains(taxon
.getName())){
97 type
= SynonymRelationshipType
.HOMOTYPIC_SYNONYM_OF();
100 taxon
.addSynonym(synonym
, type
);
103 // Redraw editor if it exists
104 return postExecute(synonym
);
108 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
112 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
113 throws ExecutionException
{
114 return execute(monitor
, info
);
118 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
122 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
123 throws ExecutionException
{
126 TaxonNameBase
<?
, ?
> synonymName
= this.synonym
.getName();
127 if(synonymName
== null){
131 // TODO pass in homotypical group's taxon in case we are dragging from one editor to another
134 newHomotypicalGroup
.removeTypifiedName(synonymName
);
135 oldHomotypicalGroup
.addTypifiedName(synonymName
);
137 // Redraw editor if it exists
138 return postExecute(synonym
);