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