Project

General

Profile

Download (3.34 KB) Statistics
| Branch: | Tag: | Revision:
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.SynonymRelationship;
21
import eu.etaxonomy.cdm.model.taxon.Taxon;
22

    
23
/**
24
 * <ol>
25
 * 	<li>Create synonym name using newSynonymText</li>
26
 * 	<li>Add name to new homotypic group</li>
27
 * 	<li>Create a new synonym for the taxon</li>
28
 * </ol>
29
 *
30
 * @author p.ciardelli
31
 * @author n.hoffmann
32
 * @created 16.01.2009
33
 * @version 1.0
34
 */
35
public class CreateSynonymInNewGroupOperation extends AbstractPostOperation {
36
	
37
	// TODO replace this with TaxonNameBase
38
	private TaxonNameBase newSynonymName;
39
	private SynonymRelationship newSynonymRelationship;
40

    
41
	/**
42
	 * <p>Constructor for CreateSynonymInNewGroupOperation.</p>
43
	 *
44
	 * @param label a {@link java.lang.String} object.
45
	 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
46
	 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
47
	 * @param newSynonymName a {@link eu.etaxonomy.cdm.model.name.TaxonNameBase} object.
48
	 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operations.IPostOperationEnabled} object.
49
	 */
50
	public CreateSynonymInNewGroupOperation(String label,
51
			IUndoContext undoContext, Taxon taxon, TaxonNameBase newSynonymName, IPostOperationEnabled postOperationEnabled) {
52
		super(label, undoContext, taxon, postOperationEnabled);
53
		
54
		this.newSynonymName = newSynonymName;
55
	}
56

    
57
	/* (non-Javadoc)
58
	 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
59
	 */
60
	/** {@inheritDoc} */
61
	@Override
62
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
63
			throws ExecutionException {
64
		
65
		// Add name to new homotypic group
66
		HomotypicalGroup.NewInstance().addTypifiedName(newSynonymName);
67
		monitor.worked(20);
68
		
69
		// Create a new synonym for the taxon
70
		newSynonymRelationship = taxon.addHeterotypicSynonymName(newSynonymName);
71
		monitor.worked(40);
72

    
73
		return postExecute(newSynonymRelationship.getSynonym());
74
	}
75

    
76
	/* (non-Javadoc)
77
	 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
78
	 */
79
	/** {@inheritDoc} */
80
	@Override
81
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
82
			throws ExecutionException {
83
		return execute(monitor, info);
84
	}
85

    
86
	/* (non-Javadoc)
87
	 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
88
	 */
89
	/** {@inheritDoc} */
90
	@Override
91
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
92
			throws ExecutionException {
93
		
94
		// Remove the synonym 
95
		taxon.removeSynonymRelation(newSynonymRelationship);
96
		newSynonymRelationship = null;
97
		
98
		return postExecute(null);
99
	}
100
}
(19-19/40)