Project

General

Profile

Download (2.99 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.store.operations;
11

    
12
import org.apache.log4j.Logger;
13
import org.eclipse.core.commands.ExecutionException;
14
import org.eclipse.core.commands.operations.IUndoContext;
15
import org.eclipse.core.runtime.IAdaptable;
16
import org.eclipse.core.runtime.IProgressMonitor;
17
import org.eclipse.core.runtime.IStatus;
18

    
19
import eu.etaxonomy.cdm.model.reference.ReferenceBase;
20
import eu.etaxonomy.cdm.model.taxon.Taxon;
21
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
22
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
23

    
24
/**
25
 * @author p.ciardelli
26
 * @created 16.01.2009
27
 * @version 1.0
28
 */
29
public class DeleteMisapplicationOperation extends AbstractPostOperation {
30
	private static final Logger logger = Logger
31
			.getLogger(DeleteMisapplicationOperation.class);
32
	
33
	private Taxon misapplication;
34

    
35
	private ReferenceBase citation;
36

    
37
	private String microcitation;
38

    
39
	public DeleteMisapplicationOperation(String label, IUndoContext undoContext,
40
			Taxon taxon, Taxon misapplication, IPostOperationEnabled postOperationEnabled) {
41
		super(label, undoContext, taxon, postOperationEnabled);
42
		
43
		this.misapplication = misapplication;
44
	}
45

    
46
	/* (non-Javadoc)
47
	 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
48
	 */
49
	@Override
50
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
51
			throws ExecutionException {
52

    
53
		// Find misapplication relation, save citation information
54
		for (TaxonRelationship relationship : taxon.getTaxonRelations()) {
55
			if (relationship.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())
56
					&& relationship.getFromTaxon().equals(misapplication)) {
57
				citation = relationship.getCitation();
58
				microcitation = relationship.getCitationMicroReference();
59
			}
60
		}
61
		
62
		// Remove misapplied name relation from taxon
63
		taxon.removeTaxon(misapplication, TaxonRelationshipType.MISAPPLIED_NAME_FOR());
64
				
65
		return postExecute(null);
66
	}
67

    
68
	/* (non-Javadoc)
69
	 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
70
	 */
71
	@Override
72
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
73
			throws ExecutionException {
74
		return execute(monitor, info);
75
	}
76

    
77
	/* (non-Javadoc)
78
	 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
79
	 */
80
	@Override
81
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
82
			throws ExecutionException {
83
		
84
		taxon.addMisappliedName(misapplication, citation, microcitation);
85
		
86
		return postExecute(misapplication);
87
	}
88
}
(22-22/28)