- extracted super class from AbstractPostOperation (same name)
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / name / operation / DeleteMisapplicationOperation.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.reference.Reference;
19 import eu.etaxonomy.cdm.model.taxon.Taxon;
20 import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
21 import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
22 import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
23 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
24
25 /**
26 * <p>DeleteMisapplicationOperation class.</p>
27 *
28 * @author p.ciardelli
29 * @created 16.01.2009
30 * @version 1.0
31 */
32 public class DeleteMisapplicationOperation extends AbstractPostTaxonOperation {
33
34 private Taxon misapplication;
35
36 private Reference<?> citation;
37
38 private String microcitation;
39
40 /**
41 * <p>Constructor for DeleteMisapplicationOperation.</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 misapplication a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
47 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
48 */
49 public DeleteMisapplicationOperation(String label, IUndoContext undoContext,
50 Taxon taxon, Taxon misapplication, IPostOperationEnabled postOperationEnabled) {
51 super(label, undoContext, taxon, postOperationEnabled);
52
53 this.misapplication = misapplication;
54 }
55
56 /* (non-Javadoc)
57 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
58 */
59 /** {@inheritDoc} */
60 @Override
61 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
62 throws ExecutionException {
63
64 // Find misapplication relation, save citation information
65 for (TaxonRelationship relationship : taxon.getTaxonRelations()) {
66 if (relationship.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())
67 && relationship.getFromTaxon().equals(misapplication)) {
68 citation = relationship.getCitation();
69 microcitation = relationship.getCitationMicroReference();
70 }
71 }
72 monitor.worked(20);
73
74 // Remove misapplied name relation from taxon
75 taxon.removeTaxon(misapplication, TaxonRelationshipType.MISAPPLIED_NAME_FOR());
76 monitor.worked(40);
77
78 return postExecute(null);
79 }
80
81 /* (non-Javadoc)
82 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
83 */
84 /** {@inheritDoc} */
85 @Override
86 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
87 throws ExecutionException {
88 return execute(monitor, info);
89 }
90
91 /* (non-Javadoc)
92 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
93 */
94 /** {@inheritDoc} */
95 @Override
96 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
97 throws ExecutionException {
98
99 taxon.addMisappliedName(misapplication, citation, microcitation);
100
101 return postExecute(misapplication);
102 }
103 }