editor now updatable via updateSite
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / store / operations / 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.store.operations;
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.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;
25
26 /**
27 * @author p.ciardelli
28 * @created 14.01.2009
29 * @version 1.0
30 * @author n.hoffmann
31 */
32 public class ChangeSynonymToMisapplicationOperation extends AbstractPostOperation {
33
34 private Synonym synonym;
35 private Taxon misapplication;
36 private Set<SynonymRelationshipType> synonymTypes;
37
38 public ChangeSynonymToMisapplicationOperation(String label,
39 IUndoContext undoContext, Taxon taxon, Synonym synonym, IPostOperationEnabled editor) {
40 super(label, undoContext, taxon, editor);
41
42 this.synonym = synonym;
43 }
44
45 @Override
46 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
47 throws ExecutionException {
48
49 // get name from synonym
50 TaxonNameBase<?, ?> synonymName = synonym.getName();
51
52 // make misapplied name with synonym name
53 misapplication = Taxon.NewInstance(synonymName, null);
54
55 // store synonymRelationshipType for later undo operations
56 synonymTypes = synonym.getRelationType(taxon);
57
58 // remove synonym from taxon
59 taxon.removeSynonym(synonym);
60
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);
64
65 // redraw editor if exists
66 return postExecute(misapplication);
67 }
68
69 @Override
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);
75
76 // remove synonym from taxon
77 taxon.removeSynonym(synonym);
78
79 // redraw editor if exists
80 return postExecute(null);
81 }
82
83 @Override
84 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
85 throws ExecutionException {
86
87 // remove misapplied name from taxon
88 taxon.removeTaxon(misapplication, TaxonRelationshipType.MISAPPLIED_NAME_FOR());
89
90 // add synonym to taxon
91 for (SynonymRelationshipType synonymType : synonymTypes){
92 taxon.addSynonym(synonym, synonymType);
93 }
94
95 // redraw editor if exists
96 return postExecute(null);
97 }
98 }