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
.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
;
25 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostTaxonOperation
;
26 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
27 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
30 * <p>ChangeSynonymToMisapplicationOperation class.</p>
37 public class ChangeSynonymToMisapplicationOperation
extends AbstractPostTaxonOperation
{
39 private final Synonym synonym
;
40 private Taxon misapplication
;
41 private Set
<SynonymRelationshipType
> synonymTypes
;
44 * <p>Constructor for ChangeSynonymToMisapplicationOperation.</p>
46 * @param label a {@link java.lang.String} object.
47 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
48 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
49 * @param synonym a {@link eu.etaxonomy.cdm.model.taxon.Synonym} object.
50 * @param editor a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
52 public ChangeSynonymToMisapplicationOperation(String label
,
53 IUndoContext undoContext
, Taxon taxon
, Synonym synonym
, IPostOperationEnabled editor
) {
54 super(label
, undoContext
, taxon
, editor
);
56 this.synonym
= synonym
;
61 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
62 throws ExecutionException
{
64 /*// get name from synonym
65 TaxonNameBase<?, ?> synonymName = synonym.getName();
67 // make misapplied name with synonym name
68 misapplication = Taxon.NewInstance(synonymName, null);
69 CdmStore.getService(ITaxonService.class).saveOrUpdate(misapplication);
72 // store synonymRelationshipType for later undo operations
73 synonymTypes = synonym.getRelationType(element);
75 // remove synonym from taxon
76 element.removeSynonym(synonym);
79 // add misapplied name to taxon
80 // TODO add microcitation for misapplied name to property sheet (if microcitation is indeed needed?!)
81 element.addMisappliedName(misapplication, null, null);*/
83 (Taxon
) CdmStore
.getService(ITaxonService
.class).changeSynonymToRelatedTaxon(synonym
.getUuid(),
85 TaxonRelationshipType
.MISAPPLIED_NAME_FOR(),
88 // redraw editor if exists
89 return postExecute(misapplication
);
94 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
95 throws ExecutionException
{
96 // add misapplied name to taxon
97 // TODO add citation for misapplied name to property sheet
98 element
.addMisappliedName(misapplication
, null, null);
100 // remove synonym from taxon
101 element
.removeSynonym(synonym
);
103 // redraw editor if exists
104 return postExecute(null);
109 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
110 throws ExecutionException
{
112 // remove misapplied name from taxon
113 element
.removeTaxon(misapplication
, TaxonRelationshipType
.MISAPPLIED_NAME_FOR());
115 // add synonym to taxon
116 for (SynonymRelationshipType synonymType
: synonymTypes
){
117 element
.addSynonym(synonym
, synonymType
);
120 // redraw editor if exists
121 return postExecute(null);