Project

General

Profile

Download (3.38 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.operations;
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.model.reference.ReferenceBase;
19
import eu.etaxonomy.cdm.model.taxon.Taxon;
20
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
21
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
22

    
23
/**
24
 * <p>DeleteMisapplicationOperation class.</p>
25
 *
26
 * @author p.ciardelli
27
 * @created 16.01.2009
28
 * @version 1.0
29
 */
30
public class DeleteMisapplicationOperation extends AbstractPostOperation {
31
	
32
	private Taxon misapplication;
33

    
34
	private ReferenceBase<?> citation;
35

    
36
	private String microcitation;
37

    
38
	/**
39
	 * <p>Constructor for DeleteMisapplicationOperation.</p>
40
	 *
41
	 * @param label a {@link java.lang.String} object.
42
	 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
43
	 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
44
	 * @param misapplication a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
45
	 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operations.IPostOperationEnabled} object.
46
	 */
47
	public DeleteMisapplicationOperation(String label, IUndoContext undoContext,
48
			Taxon taxon, Taxon misapplication, IPostOperationEnabled postOperationEnabled) {
49
		super(label, undoContext, taxon, postOperationEnabled);
50
		
51
		this.misapplication = misapplication;
52
	}
53

    
54
	/* (non-Javadoc)
55
	 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
56
	 */
57
	/** {@inheritDoc} */
58
	@Override
59
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
60
			throws ExecutionException {
61

    
62
		// Find misapplication relation, save citation information
63
		for (TaxonRelationship relationship : taxon.getTaxonRelations()) {
64
			if (relationship.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())
65
					&& relationship.getFromTaxon().equals(misapplication)) {
66
				citation = relationship.getCitation();
67
				microcitation = relationship.getCitationMicroReference();
68
			}
69
		}
70
		monitor.worked(20);
71
		
72
		// Remove misapplied name relation from taxon
73
		taxon.removeTaxon(misapplication, TaxonRelationshipType.MISAPPLIED_NAME_FOR());
74
		monitor.worked(40);
75

    
76
		return postExecute(null);
77
	}
78

    
79
	/* (non-Javadoc)
80
	 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
81
	 */
82
	/** {@inheritDoc} */
83
	@Override
84
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
85
			throws ExecutionException {
86
		return execute(monitor, info);
87
	}
88

    
89
	/* (non-Javadoc)
90
	 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
91
	 */
92
	/** {@inheritDoc} */
93
	@Override
94
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
95
			throws ExecutionException {
96
		
97
		taxon.addMisappliedName(misapplication, citation, microcitation);
98
		
99
		return postExecute(misapplication);
100
	}
101
}
(26-26/40)