Merge branch 'develop' into remoting-4.0
[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.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;
28
29 /**
30 * <p>ChangeSynonymToMisapplicationOperation class.</p>
31 *
32 * @author p.ciardelli
33 * @author n.hoffmann
34 * @created 14.01.2009
35 * @version 1.0
36 */
37 public class ChangeSynonymToMisapplicationOperation extends AbstractPostTaxonOperation {
38
39 private final Synonym synonym;
40 private Taxon misapplication;
41 private Set<SynonymRelationshipType> synonymTypes;
42
43 /**
44 * <p>Constructor for ChangeSynonymToMisapplicationOperation.</p>
45 *
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.
51 */
52 public ChangeSynonymToMisapplicationOperation(String label,
53 IUndoContext undoContext, Taxon taxon, Synonym synonym, IPostOperationEnabled editor) {
54 super(label, undoContext, taxon, editor);
55
56 this.synonym = synonym;
57 }
58
59 /** {@inheritDoc} */
60 @Override
61 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
62 throws ExecutionException {
63
64 /*// get name from synonym
65 TaxonNameBase<?, ?> synonymName = synonym.getName();
66
67 // make misapplied name with synonym name
68 misapplication = Taxon.NewInstance(synonymName, null);
69 CdmStore.getService(ITaxonService.class).saveOrUpdate(misapplication);
70 monitor.worked(20);
71
72 // store synonymRelationshipType for later undo operations
73 synonymTypes = synonym.getRelationType(element);
74
75 // remove synonym from taxon
76 element.removeSynonym(synonym);
77 monitor.worked(40);
78
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);*/
82 misapplication =
83 (Taxon) CdmStore.getService(ITaxonService.class).changeSynonymToRelatedTaxon(synonym.getUuid(),
84 element.getUuid(),
85 TaxonRelationshipType.MISAPPLIED_NAME_FOR(),
86 null,
87 null).getCdmEntity();
88 // redraw editor if exists
89 return postExecute(misapplication);
90 }
91
92 /** {@inheritDoc} */
93 @Override
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);
99
100 // remove synonym from taxon
101 element.removeSynonym(synonym);
102
103 // redraw editor if exists
104 return postExecute(null);
105 }
106
107 /** {@inheritDoc} */
108 @Override
109 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
110 throws ExecutionException {
111
112 // remove misapplied name from taxon
113 element.removeTaxon(misapplication, TaxonRelationshipType.MISAPPLIED_NAME_FOR());
114
115 // add synonym to taxon
116 for (SynonymRelationshipType synonymType : synonymTypes){
117 element.addSynonym(synonym, synonymType);
118 }
119
120 // redraw editor if exists
121 return postExecute(null);
122 }
123 }