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
.api
.service
.ITaxonService
;
21 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
22 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
23 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationshipType
;
24 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
25 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
26 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
27 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
28 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
31 * <p>ChangeSynonymToMisapplicationOperation class.</p>
38 public class ChangeSynonymToMisapplicationOperation
extends AbstractPostOperation
{
40 private Synonym synonym
;
41 private Taxon misapplication
;
42 private Set
<SynonymRelationshipType
> synonymTypes
;
45 * <p>Constructor for ChangeSynonymToMisapplicationOperation.</p>
47 * @param label a {@link java.lang.String} object.
48 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
49 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
50 * @param synonym a {@link eu.etaxonomy.cdm.model.taxon.Synonym} object.
51 * @param editor a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
53 public ChangeSynonymToMisapplicationOperation(String label
,
54 IUndoContext undoContext
, Taxon taxon
, Synonym synonym
, IPostOperationEnabled editor
) {
55 super(label
, undoContext
, taxon
, editor
);
57 this.synonym
= synonym
;
62 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
63 throws ExecutionException
{
65 // get name from synonym
66 TaxonNameBase
<?
, ?
> synonymName
= synonym
.getName();
68 // make misapplied name with synonym name
69 misapplication
= Taxon
.NewInstance(synonymName
, null);
70 CdmStore
.getService(ITaxonService
.class).saveOrUpdate(misapplication
);
73 // store synonymRelationshipType for later undo operations
74 synonymTypes
= synonym
.getRelationType(taxon
);
76 // remove synonym from taxon
77 taxon
.removeSynonym(synonym
);
80 // add misapplied name to taxon
81 // TODO add microcitation for misapplied name to property sheet (if microcitation is indeed needed?!)
82 taxon
.addMisappliedName(misapplication
, null, null);
84 // redraw editor if exists
85 return postExecute(misapplication
);
90 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
91 throws ExecutionException
{
92 // add misapplied name to taxon
93 // TODO add citation for misapplied name to property sheet
94 taxon
.addMisappliedName(misapplication
, null, null);
96 // remove synonym from taxon
97 taxon
.removeSynonym(synonym
);
99 // redraw editor if exists
100 return postExecute(null);
105 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
106 throws ExecutionException
{
108 // remove misapplied name from taxon
109 taxon
.removeTaxon(misapplication
, TaxonRelationshipType
.MISAPPLIED_NAME_FOR());
111 // add synonym to taxon
112 for (SynonymRelationshipType synonymType
: synonymTypes
){
113 taxon
.addSynonym(synonym
, synonymType
);
116 // redraw editor if exists
117 return postExecute(null);