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
.name
;
14 import org
.apache
.log4j
.Logger
;
15 import org
.eclipse
.core
.commands
.ExecutionException
;
16 import org
.eclipse
.core
.commands
.operations
.IUndoContext
;
17 import org
.eclipse
.core
.runtime
.IAdaptable
;
18 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
19 import org
.eclipse
.core
.runtime
.IStatus
;
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
.operations
.AbstractEditorOperation
;
33 public class ChangeSynonymToMisappliedNameOperation
extends AbstractEditorOperation
{
34 private static final Logger logger
= Logger
35 .getLogger(ChangeSynonymToMisappliedNameOperation
.class);
37 private Synonym synonym
;
38 private Taxon misapplication
;
39 private Set
<SynonymRelationshipType
> synonymTypes
;
41 public ChangeSynonymToMisappliedNameOperation(String label
,
42 IUndoContext undoContext
, Taxon taxon
, Synonym synonym
) {
43 super(label
, undoContext
, taxon
);
45 this.synonym
= synonym
;
49 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
50 throws ExecutionException
{
52 // get name from synonym
53 TaxonNameBase synonymName
= synonym
.getName();
55 // make misapplied name with synonym name
56 misapplication
= Taxon
.NewInstance(synonymName
, null);
58 // store synonymRelationshipType for later undo operations
59 synonymTypes
= synonym
.getRelationType(taxon
);
61 // remove synonym from taxon
62 taxon
.removeSynonym(synonym
);
64 // add misapplied name to taxon
65 // TODO add microcitation for misapplied name to property sheet (if microcitation is indeed needed?!)
66 taxon
.addMisappliedName(misapplication
, null, null);
68 // redraw editor if exists
69 return redrawOpenEditor();
73 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
74 throws ExecutionException
{
75 // add misapplied name to taxon
76 // TODO add citation for misapplied name to property sheet
77 taxon
.addMisappliedName(misapplication
, null, null);
79 // remove synonym from taxon
80 taxon
.removeSynonym(synonym
);
82 // redraw editor if exists
83 return redrawOpenEditor();
87 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
88 throws ExecutionException
{
90 // remove misapplied name from taxon
91 taxon
.removeTaxon(misapplication
, TaxonRelationshipType
.MISAPPLIED_NAME_FOR());
93 // add synonym to taxon
94 for (SynonymRelationshipType synonymType
: synonymTypes
){
95 taxon
.addSynonym(synonym
, synonymType
);
98 // redraw editor if exists
99 return redrawOpenEditor();