Project

General

Profile

Download (4 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.conversation.IConversationEnabled;
20
import eu.etaxonomy.cdm.api.service.ITaxonService;
21
import eu.etaxonomy.cdm.api.service.config.TaxonBaseDeletionConfigurator;
22
import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
23
import eu.etaxonomy.cdm.model.reference.Reference;
24
import eu.etaxonomy.cdm.model.taxon.Taxon;
25
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
26
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
27
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
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
 */
36
public class DeleteMisapplicationOperation extends DeleteTaxonBaseOperation {
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, TaxonBaseDeletionConfigurator configurator,
54
            Taxon taxon, Taxon misapplication, IPostOperationEnabled postOperationEnabled, IConversationEnabled conversationEnabled,ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
55
		//super(label, undoContext, taxon, postOperationEnabled);
56
	    super(label, undoContext, configurator, postOperationEnabled, conversationEnabled, cdmEntitySessionEnabled);
57
		this.misapplication = misapplication;
58
		this.element = taxon;
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
		ICdmRepository controller;
83

    
84
		controller = CdmStore.getCurrentApplicationConfiguration();
85

    
86
		ITaxonService service = controller.getTaxonService();
87

    
88
		result = service.deleteTaxon(misapplication.getUuid(), (TaxonDeletionConfigurator)configurator, null);
89
		monitor.worked(40);
90

    
91
		return postExecute(null);
92
	}
93

    
94
	/** {@inheritDoc} */
95
	@Override
96
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
97
			throws ExecutionException {
98
		return execute(monitor, info);
99
	}
100

    
101
	/** {@inheritDoc} */
102
	@Override
103
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
104
			throws ExecutionException {
105

    
106
		element.addMisappliedName(misapplication, citation, microcitation);
107

    
108

    
109
		return postExecute(misapplication);
110
	}
111
}
(12-12/15)