Project

General

Profile

Download (3.58 KB) Statistics
| Branch: | Tag: | Revision:
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.ICdmRepository;
19
import eu.etaxonomy.cdm.api.service.ITaxonService;
20
import eu.etaxonomy.cdm.api.service.config.TaxonBaseDeletionConfigurator;
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.IPostOperationEnabled;
26
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
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 DeleteTaxonBaseOperation {
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, TaxonBaseDeletionConfigurator configurator,
53
            Taxon taxon, Taxon misapplication, IPostOperationEnabled postOperationEnabled, ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
54

    
55
	    super(label, undoContext, configurator, postOperationEnabled, cdmEntitySessionEnabled);
56
		this.misapplication = misapplication;
57
		this.element = taxon;
58
	}
59

    
60
	@Override
61
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
62
			throws ExecutionException {
63

    
64
		// Find misapplication relation, save citation information
65

    
66
//		for (TaxonRelationship relationship : element.getTaxonRelations()) {
67
//			if (relationship.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())
68
//					&& relationship.getFromTaxon().equals(misapplication)) {
69
//				citation = relationship.getCitation();
70
//				microcitation = relationship.getCitationMicroReference();
71
//			}
72
//		}
73
		monitor.worked(20);
74

    
75
		// Remove misapplied name relation from taxon
76
		element.removeTaxon(misapplication, TaxonRelationshipType.MISAPPLIED_NAME_FOR());
77
		ICdmRepository controller;
78

    
79
		controller = CdmStore.getCurrentApplicationConfiguration();
80

    
81
		ITaxonService service = controller.getTaxonService();
82

    
83
		result = service.deleteTaxon(misapplication.getUuid(), (TaxonDeletionConfigurator)configurator, null);
84
		monitor.worked(40);
85

    
86
		return postExecute(null);
87
	}
88

    
89
	@Override
90
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
91
			throws ExecutionException {
92
		return execute(monitor, info);
93
	}
94

    
95
	@Override
96
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
97
			throws ExecutionException {
98

    
99
		element.addMisappliedName(misapplication, citation, microcitation);
100

    
101
		return postExecute(misapplication);
102
	}
103
}
(12-12/15)