p2izing the editor
[taxeditor.git] / eclipseprojects / eu.etaxonomy.taxeditor / src / eu / etaxonomy / taxeditor / operations / name / CreateSynonymInExisitingHomotypicalGroupOperation.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.name;
11
12 import org.apache.log4j.Logger;
13 import org.eclipse.core.commands.ExecutionException;
14 import org.eclipse.core.commands.operations.IUndoContext;
15 import org.eclipse.core.runtime.IAdaptable;
16 import org.eclipse.core.runtime.IProgressMonitor;
17 import org.eclipse.core.runtime.IStatus;
18
19 import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
20 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
21 import eu.etaxonomy.cdm.model.taxon.SynonymRelationship;
22 import eu.etaxonomy.cdm.model.taxon.Taxon;
23 import eu.etaxonomy.taxeditor.editor.name.CdmParserController;
24 import eu.etaxonomy.taxeditor.operations.AbstractEditorOperation;
25
26 /**
27 * @author n.hoffmann
28 * @created 02.02.2009
29 * @version 1.0
30 */
31 public class CreateSynonymInExisitingHomotypicalGroupOperation extends
32 AbstractEditorOperation {
33 private static final Logger logger = Logger
34 .getLogger(CreateSynonymInExisitingHomotypicalGroupOperation.class);
35
36 private HomotypicalGroup group;
37 private String newSynonymText;
38
39 private SynonymRelationship synonymRelationship;
40
41 public CreateSynonymInExisitingHomotypicalGroupOperation(String label,
42 IUndoContext undoContext, Taxon taxon, HomotypicalGroup group, String newSynonymText) {
43 super(label, undoContext, taxon);
44 this.group = group;
45 this.newSynonymText = newSynonymText;
46 }
47
48 /* (non-Javadoc)
49 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
50 */
51 @Override
52 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
53 throws ExecutionException {
54
55 // Create synonym name using newSynonymText
56 TaxonNameBase synonymName =
57 CdmParserController.parseFullReference(newSynonymText, null, null);
58
59 // Add name to given homotypic group
60 group.addTypifiedName(synonymName);
61
62 // Create a new synonym for the taxon
63 // TODO add citations
64 if(group.equals(taxon.getHomotypicGroup())){
65 synonymRelationship = taxon.addHomotypicSynonymName(synonymName, null, null);
66 }else{
67 synonymRelationship = taxon.addHeterotypicSynonymName(synonymName);
68 }
69 return redrawOpenEditor();
70 }
71
72 /* (non-Javadoc)
73 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
74 */
75 @Override
76 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
77 throws ExecutionException {
78 return execute(monitor, info);
79 }
80
81 /* (non-Javadoc)
82 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
83 */
84 @Override
85 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
86 throws ExecutionException {
87
88 taxon.removeSynonymRelation(synonymRelationship);
89
90 return redrawOpenEditor();
91 }
92 }