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
;
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
.TaxonNameBase
;
21 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
22 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationshipType
;
23 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
24 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
32 public class ChangeSynonymToMisapplicationOperation
extends AbstractPostOperation
{
34 private Synonym synonym
;
35 private Taxon misapplication
;
36 private Set
<SynonymRelationshipType
> synonymTypes
;
38 public ChangeSynonymToMisapplicationOperation(String label
,
39 IUndoContext undoContext
, Taxon taxon
, Synonym synonym
, IPostOperationEnabled editor
) {
40 super(label
, undoContext
, taxon
, editor
);
42 this.synonym
= synonym
;
46 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
47 throws ExecutionException
{
49 // get name from synonym
50 TaxonNameBase
<?
, ?
> synonymName
= synonym
.getName();
52 // make misapplied name with synonym name
53 misapplication
= Taxon
.NewInstance(synonymName
, null);
55 // store synonymRelationshipType for later undo operations
56 synonymTypes
= synonym
.getRelationType(taxon
);
58 // remove synonym from taxon
59 taxon
.removeSynonym(synonym
);
61 // add misapplied name to taxon
62 // TODO add microcitation for misapplied name to property sheet (if microcitation is indeed needed?!)
63 taxon
.addMisappliedName(misapplication
, null, null);
65 // redraw editor if exists
66 return postExecute(misapplication
);
70 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
71 throws ExecutionException
{
72 // add misapplied name to taxon
73 // TODO add citation for misapplied name to property sheet
74 taxon
.addMisappliedName(misapplication
, null, null);
76 // remove synonym from taxon
77 taxon
.removeSynonym(synonym
);
79 // redraw editor if exists
80 return postExecute(null);
84 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
85 throws ExecutionException
{
87 // remove misapplied name from taxon
88 taxon
.removeTaxon(misapplication
, TaxonRelationshipType
.MISAPPLIED_NAME_FOR());
90 // add synonym to taxon
91 for (SynonymRelationshipType synonymType
: synonymTypes
){
92 taxon
.addSynonym(synonym
, synonymType
);
95 // redraw editor if exists
96 return postExecute(null);