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