Fixed #528 - Dropping ConceptComposite onto other groups not yet implemented
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / 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.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.TaxonRelationship;
24 import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
25 import eu.etaxonomy.taxeditor.model.TaxonUtil;
26
27 /**
28 * @author p.ciardelli
29 * @created 15.01.2009
30 * @version 1.0
31 * @author n.hoffmann
32 */
33 public class ChangeConceptToSynonymOperation extends
34 AbstractPostOperation {
35
36 private Taxon concept;
37
38 private HomotypicalGroup homotypicalGroup;
39
40 private TaxonRelationship taxonRelationship;
41 private TaxonRelationshipType oldRelationshipType;
42
43 public ChangeConceptToSynonymOperation(String label,
44 IUndoContext undoContext, Taxon taxon, Taxon concept, HomotypicalGroup homotypicalGroup,
45 IPostOperationEnabled editor) {
46 super(label, undoContext, taxon, editor);
47
48 this.taxonRelationship = TaxonUtil.getRelationshipBetweenTwoTaxa(concept, taxon);
49 this.oldRelationshipType = taxonRelationship.getType();
50
51 this.concept = concept;
52 this.homotypicalGroup = homotypicalGroup;
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 @Override
59 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
60 throws ExecutionException {
61
62 // Create new synonym using concept name
63 TaxonNameBase<?, ?> synonymName = concept.getName();
64 Synonym synonym = Synonym.NewInstance(synonymName, taxon.getSec());
65
66 // Remove concept relation from taxon
67 taxon.removeTaxon(concept, oldRelationshipType);
68
69
70 if(homotypicalGroup != null){
71 // // Add synonym to homotypical group
72 // homotypicalGroup.addTypifiedName(synonymName);
73 //
74 if (homotypicalGroup.equals(taxon.getHomotypicGroup())) {
75 taxon.addHomotypicSynonym(synonym, null, null);
76 } else {
77 taxon.addHeterotypicSynonymName(synonymName, homotypicalGroup, null, null);
78 }
79 } else {
80 taxon.addSynonym(synonym, SynonymRelationshipType.SYNONYM_OF());
81 }
82
83 return postExecute(synonym);
84 }
85
86 /* (non-Javadoc)
87 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
88 */
89 @Override
90 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
91 throws ExecutionException {
92 // TODO redo for change misapplied name ...
93 return null;
94 }
95
96 /* (non-Javadoc)
97 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
98 */
99 @Override
100 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
101 throws ExecutionException {
102 // TODO undo for change misapplied name ...
103 return null;
104 }
105 }