Re-implemented taxonomic tree using Common Navigator Framework.
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / store / operations / 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.store.operations;
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.ReferenceBase;
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
23 /**
24 * @author p.ciardelli
25 * @created 16.01.2009
26 * @version 1.0
27 */
28 public class DeleteMisapplicationOperation extends AbstractPostOperation {
29
30 private Taxon misapplication;
31
32 private ReferenceBase<?> citation;
33
34 private String microcitation;
35
36 public DeleteMisapplicationOperation(String label, IUndoContext undoContext,
37 Taxon taxon, Taxon misapplication, IPostOperationEnabled postOperationEnabled) {
38 super(label, undoContext, taxon, postOperationEnabled);
39
40 this.misapplication = misapplication;
41 }
42
43 /* (non-Javadoc)
44 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
45 */
46 @Override
47 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
48 throws ExecutionException {
49
50 // Find misapplication relation, save citation information
51 for (TaxonRelationship relationship : taxon.getTaxonRelations()) {
52 if (relationship.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())
53 && relationship.getFromTaxon().equals(misapplication)) {
54 citation = relationship.getCitation();
55 microcitation = relationship.getCitationMicroReference();
56 }
57 }
58
59 // Remove misapplied name relation from taxon
60 taxon.removeTaxon(misapplication, TaxonRelationshipType.MISAPPLIED_NAME_FOR());
61
62 return postExecute(null);
63 }
64
65 /* (non-Javadoc)
66 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
67 */
68 @Override
69 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
70 throws ExecutionException {
71 return execute(monitor, info);
72 }
73
74 /* (non-Javadoc)
75 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
76 */
77 @Override
78 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
79 throws ExecutionException {
80
81 taxon.addMisappliedName(misapplication, citation, microcitation);
82
83 return postExecute(misapplication);
84 }
85 }