1 |
3be6ef3e
|
n.hoffmann
|
/**
|
2 |
|
|
* Copyright (C) 2007 EDIT
|
3 |
0a534d09
|
Patric Plitzner
|
* European Distributed Institute of Taxonomy
|
4 |
3be6ef3e
|
n.hoffmann
|
* http://www.e-taxonomy.eu
|
5 |
0a534d09
|
Patric Plitzner
|
*
|
6 |
3be6ef3e
|
n.hoffmann
|
* 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 |
35861667
|
n.hoffmann
|
package eu.etaxonomy.taxeditor.editor.name.operation;
|
11 |
3be6ef3e
|
n.hoffmann
|
|
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 |
dc39d372
|
Katja Luther
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
19 |
3be6ef3e
|
n.hoffmann
|
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 |
343457b6
|
Patric Plitzner
|
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
|
24 |
35861667
|
n.hoffmann
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
25 |
3be6ef3e
|
n.hoffmann
|
|
26 |
|
|
/**
|
27 |
|
|
* <ol>
|
28 |
|
|
* <li>Create synonym name using newSynonymText</li>
|
29 |
|
|
* <li>Add name to new homotypic group</li>
|
30 |
|
|
* <li>Create a new synonym for the taxon</li>
|
31 |
|
|
* </ol>
|
32 |
|
|
*
|
33 |
|
|
* @author p.ciardelli
|
34 |
|
|
* @author n.hoffmann
|
35 |
|
|
* @created 16.01.2009
|
36 |
|
|
* @version 1.0
|
37 |
|
|
*/
|
38 |
343457b6
|
Patric Plitzner
|
public class CreateSynonymInNewGroupOperation extends AbstractPostTaxonOperation {
|
39 |
0a534d09
|
Patric Plitzner
|
|
40 |
3be6ef3e
|
n.hoffmann
|
// TODO replace this with TaxonNameBase
|
41 |
0a534d09
|
Patric Plitzner
|
private final TaxonNameBase newSynonymName;
|
42 |
3be6ef3e
|
n.hoffmann
|
private SynonymRelationship newSynonymRelationship;
|
43 |
|
|
|
44 |
|
|
/**
|
45 |
|
|
* <p>Constructor for CreateSynonymInNewGroupOperation.</p>
|
46 |
|
|
*
|
47 |
|
|
* @param label a {@link java.lang.String} object.
|
48 |
|
|
* @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
|
49 |
|
|
* @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
|
50 |
|
|
* @param newSynonymName a {@link eu.etaxonomy.cdm.model.name.TaxonNameBase} object.
|
51 |
35861667
|
n.hoffmann
|
* @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
|
52 |
3be6ef3e
|
n.hoffmann
|
*/
|
53 |
|
|
public CreateSynonymInNewGroupOperation(String label,
|
54 |
|
|
IUndoContext undoContext, Taxon taxon, TaxonNameBase newSynonymName, IPostOperationEnabled postOperationEnabled) {
|
55 |
|
|
super(label, undoContext, taxon, postOperationEnabled);
|
56 |
0a534d09
|
Patric Plitzner
|
|
57 |
3be6ef3e
|
n.hoffmann
|
this.newSynonymName = newSynonymName;
|
58 |
|
|
}
|
59 |
|
|
|
60 |
|
|
/* (non-Javadoc)
|
61 |
|
|
* @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
62 |
|
|
*/
|
63 |
|
|
/** {@inheritDoc} */
|
64 |
|
|
@Override
|
65 |
|
|
public IStatus execute(IProgressMonitor monitor, IAdaptable info)
|
66 |
|
|
throws ExecutionException {
|
67 |
0a534d09
|
Patric Plitzner
|
|
68 |
3be6ef3e
|
n.hoffmann
|
// Add name to new homotypic group
|
69 |
|
|
HomotypicalGroup.NewInstance().addTypifiedName(newSynonymName);
|
70 |
|
|
monitor.worked(20);
|
71 |
dc39d372
|
Katja Luther
|
HibernateProxyHelper.deproxy(element);
|
72 |
3be6ef3e
|
n.hoffmann
|
// Create a new synonym for the taxon
|
73 |
0a534d09
|
Patric Plitzner
|
newSynonymRelationship = element.addHeterotypicSynonymName(newSynonymName);
|
74 |
3be6ef3e
|
n.hoffmann
|
monitor.worked(40);
|
75 |
dc39d372
|
Katja Luther
|
|
76 |
3be6ef3e
|
n.hoffmann
|
return postExecute(newSynonymRelationship.getSynonym());
|
77 |
|
|
}
|
78 |
|
|
|
79 |
|
|
/* (non-Javadoc)
|
80 |
|
|
* @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
81 |
|
|
*/
|
82 |
|
|
/** {@inheritDoc} */
|
83 |
|
|
@Override
|
84 |
|
|
public IStatus redo(IProgressMonitor monitor, IAdaptable info)
|
85 |
|
|
throws ExecutionException {
|
86 |
|
|
return execute(monitor, info);
|
87 |
|
|
}
|
88 |
|
|
|
89 |
|
|
/* (non-Javadoc)
|
90 |
|
|
* @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
91 |
|
|
*/
|
92 |
|
|
/** {@inheritDoc} */
|
93 |
|
|
@Override
|
94 |
|
|
public IStatus undo(IProgressMonitor monitor, IAdaptable info)
|
95 |
|
|
throws ExecutionException {
|
96 |
0a534d09
|
Patric Plitzner
|
|
97 |
|
|
// Remove the synonym
|
98 |
|
|
element.removeSynonymRelation(newSynonymRelationship);
|
99 |
3be6ef3e
|
n.hoffmann
|
newSynonymRelationship = null;
|
100 |
0a534d09
|
Patric Plitzner
|
|
101 |
3be6ef3e
|
n.hoffmann
|
return postExecute(null);
|
102 |
|
|
}
|
103 |
|
|
}
|