Merge branch 'release/4.0.0'
[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.api.application.ICdmApplicationConfiguration;
19 import eu.etaxonomy.cdm.api.service.ITaxonService;
20 import eu.etaxonomy.cdm.api.service.config.NameDeletionConfigurator;
21 import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
22 import eu.etaxonomy.cdm.model.reference.Reference;
23 import eu.etaxonomy.cdm.model.taxon.Taxon;
24 import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
25 import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
26 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
27 import eu.etaxonomy.taxeditor.store.CdmStore;
28
29 /**
30 * <p>DeleteMisapplicationOperation class.</p>
31 *
32 * @author p.ciardelli
33 * @created 16.01.2009
34 * @version 1.0
35 */
36 public class DeleteMisapplicationOperation extends AbstractPostTaxonOperation {
37
38 private final Taxon misapplication;
39
40 private Reference<?> citation;
41
42 private String microcitation;
43
44 /**
45 * <p>Constructor for DeleteMisapplicationOperation.</p>
46 *
47 * @param label a {@link java.lang.String} object.
48 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
49 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
50 * @param misapplication a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
51 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
52 */
53 public DeleteMisapplicationOperation(String label, IUndoContext undoContext,
54 Taxon taxon, Taxon misapplication, IPostOperationEnabled postOperationEnabled) {
55 super(label, undoContext, taxon, postOperationEnabled);
56
57 this.misapplication = misapplication;
58 }
59
60 /* (non-Javadoc)
61 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
62 */
63 /** {@inheritDoc} */
64 @Override
65 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
66 throws ExecutionException {
67
68 // Find misapplication relation, save citation information
69
70 // for (TaxonRelationship relationship : element.getTaxonRelations()) {
71 // if (relationship.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())
72 // && relationship.getFromTaxon().equals(misapplication)) {
73 // citation = relationship.getCitation();
74 // microcitation = relationship.getCitationMicroReference();
75 // }
76 // }
77 monitor.worked(20);
78
79 // Remove misapplied name relation from taxon
80 element.removeTaxon(misapplication, TaxonRelationshipType.MISAPPLIED_NAME_FOR());
81 ICdmApplicationConfiguration controller;
82
83 controller = CdmStore.getCurrentApplicationConfiguration();
84
85 ITaxonService service = controller.getTaxonService();
86 TaxonDeletionConfigurator config = new TaxonDeletionConfigurator();
87 NameDeletionConfigurator nameConfig = new NameDeletionConfigurator();
88 nameConfig.setRemoveAllNameRelationships(true);
89 config.setNameDeletionConfig(nameConfig);
90 service.deleteTaxon(misapplication.getUuid(), config, null);
91 monitor.worked(40);
92
93 return postExecute(null);
94 }
95
96 /* (non-Javadoc)
97 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
98 */
99 /** {@inheritDoc} */
100 @Override
101 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
102 throws ExecutionException {
103 return execute(monitor, info);
104 }
105
106 /* (non-Javadoc)
107 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
108 */
109 /** {@inheritDoc} */
110 @Override
111 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
112 throws ExecutionException {
113
114 element.addMisappliedName(misapplication, citation, microcitation);
115
116 return postExecute(misapplication);
117 }
118 }