Project

General

Profile

Download (2.94 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
import eu.etaxonomy.taxeditor.store.StoreUtil;
23

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

    
33
	private ReferenceBase<?> citation;
34

    
35
	private String microcitation;
36

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

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

    
51
		// Find misapplication relation, save citation information
52
		for (TaxonRelationship relationship : taxon.getTaxonRelations()) {
53
			if (relationship.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())
54
					&& relationship.getFromTaxon().equals(misapplication)) {
55
				citation = relationship.getCitation();
56
				microcitation = relationship.getCitationMicroReference();
57
			}
58
		}
59
		monitor.worked(20);
60
		
61
		// Remove misapplied name relation from taxon
62
		taxon.removeTaxon(misapplication, TaxonRelationshipType.MISAPPLIED_NAME_FOR());
63
		monitor.worked(40);
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
}
(26-26/40)