Project

General

Profile

Download (4.06 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.ICdmApplicationConfiguration;
19
import eu.etaxonomy.cdm.api.service.ITaxonService;
20
import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
21
import eu.etaxonomy.cdm.model.reference.Reference;
22
import eu.etaxonomy.cdm.model.taxon.Taxon;
23
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
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
		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 = (ICdmApplicationConfiguration) CdmStore.getCurrentApplicationConfiguration();
83

    
84
		ITaxonService service = controller.getTaxonService();
85
		TaxonDeletionConfigurator config = new TaxonDeletionConfigurator();
86
		
87
		service.deleteTaxon(misapplication, config, null);
88
		monitor.worked(40);
89

    
90
		return postExecute(null);
91
	}
92

    
93
	/* (non-Javadoc)
94
	 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
95
	 */
96
	/** {@inheritDoc} */
97
	@Override
98
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
99
			throws ExecutionException {
100
		return execute(monitor, info);
101
	}
102

    
103
	/* (non-Javadoc)
104
	 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
105
	 */
106
	/** {@inheritDoc} */
107
	@Override
108
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
109
			throws ExecutionException {
110

    
111
		element.addMisappliedName(misapplication, citation, microcitation);
112

    
113
		return postExecute(misapplication);
114
	}
115
}
(12-12/18)