1c0cc4d2d0acc7fee6afee45577bff9b4f6deb15
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / store / operations / CreateSynonymInNewGroupOperation.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 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 import eu.etaxonomy.taxeditor.store.parser.CdmParserUtil;
23
24 /**
25 * <ol>
26 * <li>Create synonym name using newSynonymText</li>
27 * <li>Add name to new homotypic group</li>
28 * <li>Create a new synonym for the taxon</li>
29 * </ol>
30 * @author p.ciardelli
31 * @created 16.01.2009
32 * @version 1.0
33 * @author n.hoffmann
34 */
35 public class CreateSynonymInNewGroupOperation extends AbstractPostOperation {
36
37 private String newSynonymText;
38 private SynonymRelationship newSynonymRelationship;
39
40 public CreateSynonymInNewGroupOperation(String label,
41 IUndoContext undoContext, Taxon taxon, String newSynonymText, IPostOperationEnabled postOperationEnabled) {
42 super(label, undoContext, taxon, postOperationEnabled);
43
44 this.newSynonymText = newSynonymText;
45 }
46
47 /* (non-Javadoc)
48 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
49 */
50 @Override
51 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
52 throws ExecutionException {
53
54 // Create synonym name using newSynonymText
55 TaxonNameBase<?, ?> synonymName =
56 CdmParserUtil.parseFullReference(newSynonymText, null, null);
57
58 // Add name to new homotypic group
59 HomotypicalGroup.NewInstance().addTypifiedName(synonymName);
60
61 // Create a new synonym for the taxon
62 newSynonymRelationship = taxon.addHeterotypicSynonymName(synonymName);
63
64 return postExecute(newSynonymRelationship.getSynonym());
65 }
66
67 /* (non-Javadoc)
68 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
69 */
70 @Override
71 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
72 throws ExecutionException {
73 return execute(monitor, info);
74 }
75
76 /* (non-Javadoc)
77 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
78 */
79 @Override
80 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
81 throws ExecutionException {
82
83 // Remove the synonym
84 taxon.removeSynonymRelation(newSynonymRelationship);
85 newSynonymRelationship = null;
86
87 return postExecute(null);
88 }
89 }