ref #5974 Remove synonym relationships (compiling)
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / name / operation / CreateSynonymInExistingHomotypicalGroupOperation.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 org.eclipse.core.commands.ExecutionException;
13 import org.eclipse.core.commands.operations.IUndoContext;
14 import org.eclipse.core.runtime.IAdaptable;
15 import org.eclipse.core.runtime.IProgressMonitor;
16 import org.eclipse.core.runtime.IStatus;
17
18 import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
19 import eu.etaxonomy.cdm.model.name.NonViralName;
20 import eu.etaxonomy.cdm.model.taxon.Synonym;
21 import eu.etaxonomy.cdm.model.taxon.Taxon;
22 import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
23 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
24
25 /**
26 * <p>CreateSynonymInExistingHomotypicalGroupOperation class.</p>
27 *
28 * @author n.hoffmann
29 * @created 02.02.2009
30 */
31 public class CreateSynonymInExistingHomotypicalGroupOperation extends
32 AbstractPostTaxonOperation {
33
34 private final HomotypicalGroup group;
35 private final NonViralName newSynonymName;
36
37 private Synonym synonym;
38
39 /**
40 * <p>Constructor for CreateSynonymInExistingHomotypicalGroupOperation.</p>
41 *
42 * @param label a {@link java.lang.String} object.
43 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
44 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
45 * @param group a {@link eu.etaxonomy.cdm.model.name.HomotypicalGroup} object.
46 * @param newSynonymName a {@link eu.etaxonomy.cdm.model.name.TaxonNameBase} object.
47 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
48 */
49 public CreateSynonymInExistingHomotypicalGroupOperation(String label,
50 IUndoContext undoContext, Taxon taxon, HomotypicalGroup group, NonViralName newSynonymName, IPostOperationEnabled postOperationEnabled) {
51 super(label, undoContext, taxon, postOperationEnabled);
52 this.group = group;
53 this.newSynonymName = newSynonymName;
54 }
55
56 /** {@inheritDoc} */
57 @Override
58 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
59 throws ExecutionException {
60
61 // Add name to given homotypic group
62 group.addTypifiedName(newSynonymName);
63 monitor.worked(20);
64
65 // Create a new synonym for the taxon
66 // TODO add citations
67 if(group.equals(element.getHomotypicGroup())){
68 synonym = element.addHomotypicSynonymName(newSynonymName);
69 }else{
70 synonym = element.addHeterotypicSynonymName(newSynonymName);
71 }
72 monitor.worked(40);
73
74 // Synonym affectedSynonym = null;
75 //
76 // for(Synonym synonym : group.getSynonymsInGroup(taxon.getSec())){
77 // if(synonym.getName() == synonymName){
78 // affectedSynonym = synonym;
79 // break;
80 // }
81 // }
82
83 return postExecute(synonym);
84 }
85
86 /** {@inheritDoc} */
87 @Override
88 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
89 throws ExecutionException {
90 return execute(monitor, info);
91 }
92
93 /** {@inheritDoc} */
94 @Override
95 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
96 throws ExecutionException {
97
98 element.removeSynonym(synonym);
99
100 return postExecute(null);
101 }
102 }