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
.ITaxonNodeService
;
21 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
22 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
23 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
24 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationshipType
;
25 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
27 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostTaxonOperation
;
28 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
29 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
32 * <p>ChangeSynonymToMisapplicationOperation class.</p>
39 public class ChangeSynonymToMisapplicationOperation
extends AbstractPostTaxonOperation
{
41 private final Synonym synonym
;
42 private Taxon misapplication
;
43 private Set
<SynonymRelationshipType
> synonymTypes
;
46 * <p>Constructor for ChangeSynonymToMisapplicationOperation.</p>
48 * @param label a {@link java.lang.String} object.
49 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
50 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
51 * @param synonym a {@link eu.etaxonomy.cdm.model.taxon.Synonym} object.
52 * @param editor a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
54 public ChangeSynonymToMisapplicationOperation(String label
,
55 IUndoContext undoContext
, Taxon taxon
, Synonym synonym
, IPostOperationEnabled editor
) {
56 super(label
, undoContext
, taxon
, editor
);
58 this.synonym
= synonym
;
63 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
64 throws ExecutionException
{
66 /*// get name from synonym
67 TaxonNameBase<?, ?> synonymName = synonym.getName();
69 // make misapplied name with synonym name
70 misapplication = Taxon.NewInstance(synonymName, null);
71 CdmStore.getService(ITaxonService.class).saveOrUpdate(misapplication);
74 // store synonymRelationshipType for later undo operations
75 synonymTypes = synonym.getRelationType(element);
77 // remove synonym from taxon
78 element.removeSynonym(synonym);
81 // add misapplied name to taxon
82 // TODO add microcitation for misapplied name to property sheet (if microcitation is indeed needed?!)
83 element.addMisappliedName(misapplication, null, null);*/
84 misapplication
= CdmStore
.getService(ITaxonService
.class).changeSynonymToRelatedTaxon(synonym
, element
, TaxonRelationshipType
.MISAPPLIED_NAME_FOR(), null, null);
85 // redraw editor if exists
86 return postExecute(misapplication
);
91 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
92 throws ExecutionException
{
93 // add misapplied name to taxon
94 // TODO add citation for misapplied name to property sheet
95 element
.addMisappliedName(misapplication
, null, null);
97 // remove synonym from taxon
98 element
.removeSynonym(synonym
);
100 // redraw editor if exists
101 return postExecute(null);
106 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
107 throws ExecutionException
{
109 // remove misapplied name from taxon
110 element
.removeTaxon(misapplication
, TaxonRelationshipType
.MISAPPLIED_NAME_FOR());
112 // add synonym to taxon
113 for (SynonymRelationshipType synonymType
: synonymTypes
){
114 element
.addSynonym(synonym
, synonymType
);
117 // redraw editor if exists
118 return postExecute(null);