Project

General

Profile

Download (3.22 KB) Statistics
| Branch: | Tag: | Revision:
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
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
19 b8601e0c Andreas Müller
import eu.etaxonomy.cdm.model.name.INonViralName;
20 e3a4a3ff Andreas Müller
import eu.etaxonomy.cdm.model.name.TaxonName;
21 d34abf30 Andreas Müller
import eu.etaxonomy.cdm.model.taxon.Synonym;
22 3be6ef3e n.hoffmann
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
 * <p>CreateSynonymInExistingHomotypicalGroupOperation class.</p>
28
 *
29
 * @author n.hoffmann
30
 * @created 02.02.2009
31
 */
32
public class CreateSynonymInExistingHomotypicalGroupOperation extends
33 343457b6 Patric Plitzner
		AbstractPostTaxonOperation {
34 3be6ef3e n.hoffmann
35 0a534d09 Patric Plitzner
	private final HomotypicalGroup group;
36 e3a4a3ff Andreas Müller
	private final TaxonName newSynonymName;
37 3be6ef3e n.hoffmann
38 d34abf30 Andreas Müller
	private Synonym synonym;
39 0a534d09 Patric Plitzner
40 3be6ef3e n.hoffmann
	/**
41
	 * <p>Constructor for CreateSynonymInExistingHomotypicalGroupOperation.</p>
42
	 *
43
	 * @param label a {@link java.lang.String} object.
44
	 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
45
	 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
46
	 * @param group a {@link eu.etaxonomy.cdm.model.name.HomotypicalGroup} object.
47
	 * @param newSynonymName a {@link eu.etaxonomy.cdm.model.name.TaxonNameBase} object.
48 35861667 n.hoffmann
	 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
49 3be6ef3e n.hoffmann
	 */
50
	public CreateSynonymInExistingHomotypicalGroupOperation(String label,
51 b8601e0c Andreas Müller
			IUndoContext undoContext, Taxon taxon, HomotypicalGroup group, 
52 e3a4a3ff Andreas Müller
			TaxonName newSynonymName, IPostOperationEnabled postOperationEnabled) {
53 3be6ef3e n.hoffmann
		super(label, undoContext, taxon, postOperationEnabled);
54
		this.group = group;
55
		this.newSynonymName = newSynonymName;
56
	}
57
58
	/** {@inheritDoc} */
59
	@Override
60
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
61
			throws ExecutionException {
62 0a534d09 Patric Plitzner
63 3be6ef3e n.hoffmann
		// Add name to given homotypic group
64
		group.addTypifiedName(newSynonymName);
65
		monitor.worked(20);
66 0a534d09 Patric Plitzner
67 3be6ef3e n.hoffmann
		// Create a new synonym for the taxon
68
		// TODO add citations
69 0a534d09 Patric Plitzner
		if(group.equals(element.getHomotypicGroup())){
70 d34abf30 Andreas Müller
			synonym = element.addHomotypicSynonymName(newSynonymName);
71 3be6ef3e n.hoffmann
		}else{
72 d34abf30 Andreas Müller
			synonym = element.addHeterotypicSynonymName(newSynonymName);
73 3be6ef3e n.hoffmann
		}
74
		monitor.worked(40);
75 0a534d09 Patric Plitzner
76 3be6ef3e n.hoffmann
//		Synonym affectedSynonym = null;
77 0a534d09 Patric Plitzner
//
78 3be6ef3e n.hoffmann
//		for(Synonym synonym : group.getSynonymsInGroup(taxon.getSec())){
79
//			if(synonym.getName() == synonymName){
80
//				affectedSynonym = synonym;
81
//				break;
82
//			}
83
//		}
84 0a534d09 Patric Plitzner
85 d34abf30 Andreas Müller
		return postExecute(synonym);
86 3be6ef3e n.hoffmann
	}
87
88
	/** {@inheritDoc} */
89
	@Override
90
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
91
			throws ExecutionException {
92
		return execute(monitor, info);
93
	}
94
95
	/** {@inheritDoc} */
96
	@Override
97
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
98
			throws ExecutionException {
99
100 d34abf30 Andreas Müller
		element.removeSynonym(synonym);
101 0a534d09 Patric Plitzner
102 3be6ef3e n.hoffmann
		return postExecute(null);
103
	}
104
}