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