editor now updatable via updateSite
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / store / operations / ChangeConceptToSynonymOperation.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.Synonym;
21 import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
22 import eu.etaxonomy.cdm.model.taxon.Taxon;
23 import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
24
25 /**
26 * @author p.ciardelli
27 * @created 15.01.2009
28 * @version 1.0
29 * @author n.hoffmann
30 */
31 public class ChangeConceptToSynonymOperation extends
32 AbstractPostOperation {
33
34 private Taxon concept;
35
36 private HomotypicalGroup homotypicalGroup;
37
38 public ChangeConceptToSynonymOperation(String label,
39 IUndoContext undoContext, Taxon taxon, Taxon concept, HomotypicalGroup homotypicalGroup,
40 IPostOperationEnabled editor) {
41 super(label, undoContext, taxon, editor);
42
43 this.concept = concept;
44 this.homotypicalGroup = homotypicalGroup;
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 new synonym using concept name
55 TaxonNameBase<?, ?> synonymName = concept.getName();
56 Synonym synonym = Synonym.NewInstance(synonymName, taxon.getSec());
57
58 // Remove concept relation from taxon
59 taxon.removeTaxon(concept, TaxonRelationshipType.MISAPPLIED_NAME_FOR());
60
61
62
63 taxon.addSynonym(synonym, SynonymRelationshipType.SYNONYM_OF());
64
65 if(homotypicalGroup != null){
66 // Add synonym to homotypical group
67 homotypicalGroup.addTypifiedName(synonymName);
68 }
69
70 return postExecute(synonym);
71 }
72
73 /* (non-Javadoc)
74 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
75 */
76 @Override
77 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
78 throws ExecutionException {
79 // TODO redo for change misapplied name ...
80 return null;
81 }
82
83 /* (non-Javadoc)
84 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
85 */
86 @Override
87 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
88 throws ExecutionException {
89 // TODO undo for change misapplied name ...
90 return null;
91 }
92 }