1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.taxeditor.editor.name.operation;
|
12
|
|
13
|
import org.eclipse.core.commands.ExecutionException;
|
14
|
import org.eclipse.core.commands.operations.IUndoContext;
|
15
|
import org.eclipse.core.runtime.IAdaptable;
|
16
|
import org.eclipse.core.runtime.IProgressMonitor;
|
17
|
import org.eclipse.core.runtime.IStatus;
|
18
|
|
19
|
import eu.etaxonomy.cdm.model.name.NameRelationshipType;
|
20
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
21
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
22
|
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
|
23
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
24
|
|
25
|
/**
|
26
|
* <p>CreateNameRelationOperation class.</p>
|
27
|
*
|
28
|
* @author n.hoffmann
|
29
|
* @created Mar 30, 2010
|
30
|
* @version 1.0
|
31
|
*/
|
32
|
public class CreateNameRelationOperation extends AbstractPostTaxonOperation {
|
33
|
|
34
|
private TaxonBase taxonBase;
|
35
|
private TaxonNameBase relatedName;
|
36
|
private NameRelationshipType type;
|
37
|
|
38
|
/**
|
39
|
* <p>Constructor for CreateNameRelationOperation.</p>
|
40
|
*
|
41
|
* @param label a {@link java.lang.String} object.
|
42
|
* @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
|
43
|
* @param taxonBase a {@link eu.etaxonomy.cdm.model.taxon.TaxonBase} object.
|
44
|
* @param relatedName a {@link eu.etaxonomy.cdm.model.name.TaxonNameBase} object.
|
45
|
* @param type a {@link eu.etaxonomy.cdm.model.name.NameRelationshipType} object.
|
46
|
* @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
|
47
|
*/
|
48
|
public CreateNameRelationOperation(String label, IUndoContext undoContext, TaxonBase taxonBase, TaxonNameBase relatedName, NameRelationshipType type, IPostOperationEnabled postOperationEnabled) {
|
49
|
super(label, undoContext, postOperationEnabled);
|
50
|
this.taxonBase = taxonBase;
|
51
|
this.relatedName = relatedName;
|
52
|
this.type = type;
|
53
|
}
|
54
|
|
55
|
/* (non-Javadoc)
|
56
|
* @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
57
|
*/
|
58
|
/** {@inheritDoc} */
|
59
|
@Override
|
60
|
public IStatus execute(IProgressMonitor monitor, IAdaptable info)
|
61
|
throws ExecutionException {
|
62
|
|
63
|
TaxonNameBase fromName = taxonBase.getName();
|
64
|
|
65
|
fromName.addRelationshipToName(relatedName, type, null);
|
66
|
|
67
|
return postExecute(taxonBase);
|
68
|
}
|
69
|
|
70
|
/* (non-Javadoc)
|
71
|
* @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
72
|
*/
|
73
|
/** {@inheritDoc} */
|
74
|
@Override
|
75
|
public IStatus redo(IProgressMonitor monitor, IAdaptable info)
|
76
|
throws ExecutionException {
|
77
|
return execute(monitor, info);
|
78
|
}
|
79
|
|
80
|
/* (non-Javadoc)
|
81
|
* @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
82
|
*/
|
83
|
/** {@inheritDoc} */
|
84
|
@Override
|
85
|
public IStatus undo(IProgressMonitor monitor, IAdaptable info)
|
86
|
throws ExecutionException {
|
87
|
TaxonNameBase fromName = taxonBase.getName();
|
88
|
|
89
|
fromName.removeRelationToTaxonName(relatedName);
|
90
|
|
91
|
return postExecute(taxonBase);
|
92
|
}
|
93
|
}
|