ref #6190 removing svn property place holder in first line of code - java files
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / name / operation / CreateNameRelationOperation.java
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.TaxonNameBase;
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 * @version 1.0
30 */
31 public class CreateNameRelationOperation extends AbstractPostTaxonOperation {
32
33 private TaxonBase taxonBase;
34 private TaxonNameBase relatedName;
35 private NameRelationshipType type;
36
37 /**
38 * <p>Constructor for CreateNameRelationOperation.</p>
39 *
40 * @param label a {@link java.lang.String} object.
41 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
42 * @param taxonBase a {@link eu.etaxonomy.cdm.model.taxon.TaxonBase} object.
43 * @param relatedName a {@link eu.etaxonomy.cdm.model.name.TaxonNameBase} object.
44 * @param type a {@link eu.etaxonomy.cdm.model.name.NameRelationshipType} object.
45 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
46 */
47 public CreateNameRelationOperation(String label, IUndoContext undoContext, TaxonBase taxonBase, TaxonNameBase relatedName, NameRelationshipType type, IPostOperationEnabled postOperationEnabled) {
48 super(label, undoContext, postOperationEnabled);
49 this.taxonBase = taxonBase;
50 this.relatedName = relatedName;
51 this.type = type;
52 }
53
54 /* (non-Javadoc)
55 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
56 */
57 /** {@inheritDoc} */
58 @Override
59 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
60 throws ExecutionException {
61
62 TaxonNameBase fromName = taxonBase.getName();
63
64 fromName.addRelationshipToName(relatedName, type, null);
65
66 return postExecute(taxonBase);
67 }
68
69 /* (non-Javadoc)
70 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
71 */
72 /** {@inheritDoc} */
73 @Override
74 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
75 throws ExecutionException {
76 return execute(monitor, info);
77 }
78
79 /* (non-Javadoc)
80 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
81 */
82 /** {@inheritDoc} */
83 @Override
84 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
85 throws ExecutionException {
86 TaxonNameBase fromName = taxonBase.getName();
87
88 fromName.removeRelationToTaxonName(relatedName);
89
90 return postExecute(taxonBase);
91 }
92 }