Correct versions
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / name / operation / ChangeSynonymToMisapplicationOperation.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
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.
8 */
9
10 package eu.etaxonomy.taxeditor.editor.name.operation;
11
12 import java.util.Set;
13
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;
19
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;
30
31 /**
32 * <p>ChangeSynonymToMisapplicationOperation class.</p>
33 *
34 * @author p.ciardelli
35 * @author n.hoffmann
36 * @created 14.01.2009
37 * @version 1.0
38 */
39 public class ChangeSynonymToMisapplicationOperation extends AbstractPostTaxonOperation {
40
41 private final Synonym synonym;
42 private Taxon misapplication;
43 private Set<SynonymRelationshipType> synonymTypes;
44
45 /**
46 * <p>Constructor for ChangeSynonymToMisapplicationOperation.</p>
47 *
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.
53 */
54 public ChangeSynonymToMisapplicationOperation(String label,
55 IUndoContext undoContext, Taxon taxon, Synonym synonym, IPostOperationEnabled editor) {
56 super(label, undoContext, taxon, editor);
57
58 this.synonym = synonym;
59 }
60
61 /** {@inheritDoc} */
62 @Override
63 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
64 throws ExecutionException {
65
66 /*// get name from synonym
67 TaxonNameBase<?, ?> synonymName = synonym.getName();
68
69 // make misapplied name with synonym name
70 misapplication = Taxon.NewInstance(synonymName, null);
71 CdmStore.getService(ITaxonService.class).saveOrUpdate(misapplication);
72 monitor.worked(20);
73
74 // store synonymRelationshipType for later undo operations
75 synonymTypes = synonym.getRelationType(element);
76
77 // remove synonym from taxon
78 element.removeSynonym(synonym);
79 monitor.worked(40);
80
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);
87 }
88
89 /** {@inheritDoc} */
90 @Override
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);
96
97 // remove synonym from taxon
98 element.removeSynonym(synonym);
99
100 // redraw editor if exists
101 return postExecute(null);
102 }
103
104 /** {@inheritDoc} */
105 @Override
106 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
107 throws ExecutionException {
108
109 // remove misapplied name from taxon
110 element.removeTaxon(misapplication, TaxonRelationshipType.MISAPPLIED_NAME_FOR());
111
112 // add synonym to taxon
113 for (SynonymRelationshipType synonymType : synonymTypes){
114 element.addSynonym(synonym, synonymType);
115 }
116
117 // redraw editor if exists
118 return postExecute(null);
119 }
120 }