Project

General

Profile

Download (3.48 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.editor.name.operation;
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
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
23
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
24

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

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

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

    
75
		return postExecute(newSynonymRelationship.getSynonym());
76
	}
77

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

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