Project

General

Profile

Download (2.67 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.NameRelationshipType;
19
import eu.etaxonomy.cdm.model.name.TaxonName;
20
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
21
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
22
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
23

    
24
/**
25
 * <p>CreateNameRelationOperation class.</p>
26
 *
27
 * @author n.hoffmann
28
 * @created Mar 30, 2010
29
 */
30
public class CreateNameRelationOperation extends AbstractPostTaxonOperation {
31

    
32
	private TaxonBase taxonBase;
33
	private TaxonName relatedName;
34
	private NameRelationshipType type;
35

    
36
	/**
37
	 * <p>Constructor for CreateNameRelationOperation.</p>
38
	 *
39
	 * @param label a {@link java.lang.String} object.
40
	 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
41
	 * @param taxonBase a {@link eu.etaxonomy.cdm.model.taxon.TaxonBase} object.
42
	 * @param relatedName a {@link eu.etaxonomy.cdm.model.name.TaxonNameBase} object.
43
	 * @param type a {@link eu.etaxonomy.cdm.model.name.NameRelationshipType} object.
44
	 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
45
	 */
46
	public CreateNameRelationOperation(String label, IUndoContext undoContext, TaxonBase taxonBase, TaxonName relatedName, NameRelationshipType type, IPostOperationEnabled postOperationEnabled) {
47
		super(label, undoContext, postOperationEnabled);
48
		this.taxonBase = taxonBase;
49
		this.relatedName = relatedName;
50
		this.type = type;
51
	}
52
	
53
	/** {@inheritDoc} */
54
	@Override
55
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
56
			throws ExecutionException {
57
		
58
		TaxonName fromName = taxonBase.getName();
59
		
60
		fromName.addRelationshipToName(relatedName, type, null);
61
		
62
		return postExecute(taxonBase);
63
	}
64

    
65
	/** {@inheritDoc} */
66
	@Override
67
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
68
			throws ExecutionException {
69
		return execute(monitor, info);
70
	}
71

    
72
	/** {@inheritDoc} */
73
	@Override
74
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
75
			throws ExecutionException {
76
		TaxonName fromName = taxonBase.getName();
77
		
78
		fromName.removeRelationToTaxonName(relatedName);
79
		
80
		return postExecute(taxonBase);
81
	}
82
}
(9-9/19)