editor now updatable via updateSite
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / store / operations / 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.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 * @author n.hoffmann
26 * @created 02.02.2009
27 * @version 1.0
28 */
29 public class CreateSynonymInExisitingHomotypicalGroupOperation extends
30 AbstractPostOperation {
31
32 private HomotypicalGroup group;
33 private String newSynonymText;
34
35 private SynonymRelationship synonymRelationship;
36
37 public CreateSynonymInExisitingHomotypicalGroupOperation(String label,
38 IUndoContext undoContext, Taxon taxon, HomotypicalGroup group, String newSynonymText, IPostOperationEnabled postOperationEnabled) {
39 super(label, undoContext, taxon, postOperationEnabled);
40 this.group = group;
41 this.newSynonymText = newSynonymText;
42 }
43
44 /* (non-Javadoc)
45 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
46 */
47 @Override
48 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
49 throws ExecutionException {
50
51 // Create synonym name using newSynonymText
52 TaxonNameBase<?, ?> synonymName =
53 CdmParserUtil.parseFullReference(newSynonymText, null, null);
54
55 // Add name to given homotypic group
56 group.addTypifiedName(synonymName);
57
58 // Create a new synonym for the taxon
59 // TODO add citations
60 if(group.equals(taxon.getHomotypicGroup())){
61 synonymRelationship = taxon.addHomotypicSynonymName(synonymName, null, null);
62 }else{
63 synonymRelationship = taxon.addHeterotypicSynonymName(synonymName);
64 }
65
66 // Synonym affectedSynonym = null;
67 //
68 // for(Synonym synonym : group.getSynonymsInGroup(taxon.getSec())){
69 // if(synonym.getName() == synonymName){
70 // affectedSynonym = synonym;
71 // break;
72 // }
73 // }
74
75 return postExecute(synonymRelationship.getSynonym());
76 }
77
78 /* (non-Javadoc)
79 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
80 */
81 @Override
82 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
83 throws ExecutionException {
84 return execute(monitor, info);
85 }
86
87 /* (non-Javadoc)
88 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
89 */
90 @Override
91 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
92 throws ExecutionException {
93
94 taxon.removeSynonymRelation(synonymRelationship);
95
96 return postExecute(null);
97 }
98 }