performed javacscript:fix and worked on documentation
[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 java.util.Set;
13
14 import org.eclipse.core.commands.ExecutionException;
15 import org.eclipse.core.commands.operations.IUndoContext;
16 import org.eclipse.core.runtime.IAdaptable;
17 import org.eclipse.core.runtime.IProgressMonitor;
18 import org.eclipse.core.runtime.IStatus;
19
20 import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
21 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
22 import eu.etaxonomy.cdm.model.taxon.SynonymRelationship;
23 import eu.etaxonomy.cdm.model.taxon.Taxon;
24 import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
25 import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
26 import eu.etaxonomy.taxeditor.store.StoreUtil;
27
28 /**
29 * <p>ChangeConceptToSynonymOperation class.</p>
30 *
31 * @author p.ciardelli
32 * @author n.hoffmann
33 * @created 15.01.2009
34 * @version 1.0
35 */
36 public class ChangeConceptToSynonymOperation extends
37 AbstractPostOperation {
38
39 private Taxon concept;
40
41 private HomotypicalGroup homotypicalGroup;
42
43 private TaxonRelationship taxonRelationship;
44 private TaxonRelationshipType oldRelationshipType;
45
46 private SynonymRelationship newSynonymRelationship;
47
48 /**
49 * <p>Constructor for ChangeConceptToSynonymOperation.</p>
50 *
51 * @param label a {@link java.lang.String} object.
52 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
53 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
54 * @param concept a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
55 * @param homotypicalGroup a {@link eu.etaxonomy.cdm.model.name.HomotypicalGroup} object.
56 * @param editor a {@link eu.etaxonomy.taxeditor.operations.IPostOperationEnabled} object.
57 */
58 public ChangeConceptToSynonymOperation(String label,
59 IUndoContext undoContext, Taxon taxon, Taxon concept, HomotypicalGroup homotypicalGroup,
60 IPostOperationEnabled editor) {
61 super(label, undoContext, taxon, editor);
62
63 Set<TaxonRelationship> taxonRelationships = taxon.getTaxonRelations(concept);
64
65 if(taxonRelationships.size() > 1){
66 StoreUtil.warningDialog("Multiple relations between taxa", this, "There are multiple relations between the " +
67 "accepted and the related taxon. This case is not handled by the software yet");
68 return;
69 }
70
71 this.taxonRelationship = taxonRelationships.iterator().next();
72 this.oldRelationshipType = taxonRelationship.getType();
73
74 this.concept = concept;
75 this.homotypicalGroup = homotypicalGroup != null ? homotypicalGroup : HomotypicalGroup.NewInstance();
76 }
77
78 /* (non-Javadoc)
79 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
80 */
81 /** {@inheritDoc} */
82 @Override
83 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
84 throws ExecutionException {
85
86 // Create new synonym using concept name
87 TaxonNameBase<?, ?> synonymName = concept.getName();
88
89 // Remove concept relation from taxon
90 taxon.removeTaxon(concept, oldRelationshipType);
91 monitor.worked(20);
92
93 // Add name to new homotypic group
94 homotypicalGroup.addTypifiedName(synonymName);
95 monitor.worked(40);
96
97 // Create a new synonym for the taxon
98 newSynonymRelationship = taxon.addHeterotypicSynonymName(synonymName);
99
100 return postExecute(newSynonymRelationship.getSynonym());
101 }
102
103 /* (non-Javadoc)
104 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
105 */
106 /** {@inheritDoc} */
107 @Override
108 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
109 throws ExecutionException {
110 // TODO redo for change misapplied name ...
111 return null;
112 }
113
114 /* (non-Javadoc)
115 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
116 */
117 /** {@inheritDoc} */
118 @Override
119 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
120 throws ExecutionException {
121 // TODO undo for change misapplied name ...
122 return null;
123 }
124 }