Project

General

Profile

Download (2.62 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
import org.eclipse.core.runtime.Status;
19

    
20
import eu.etaxonomy.cdm.model.taxon.Taxon;
21
import eu.etaxonomy.taxeditor.store.model.TaxonUtil;
22

    
23
/**
24
 * Change the taxonomic parent of a given taxon.
25
 * 
26
 * @author n.hoffmann
27
 * @created 16.01.2009
28
 * @version 1.0
29
 */
30
public class MoveTaxonOperation extends AbstractPostOperation {
31
	
32
	@SuppressWarnings("unused")
33
	private static final Logger logger = Logger.getLogger(MoveTaxonOperation.class);
34
	/**
35
	 * A reference to the new taxonomical parent.
36
	 */
37
	private Taxon newParentTaxon;
38
	/**
39
	 * A reference to the former taxonomical parent
40
	 */
41
	private Taxon oldParentTaxon;
42

    
43
	public MoveTaxonOperation(String label, IUndoContext undoContext,
44
			Taxon taxon, Taxon newParentTaxon) {
45
		super(label, undoContext, taxon);
46

    
47
		this.newParentTaxon = newParentTaxon;
48
		
49
		// Save old parent taxon for undo
50
		this.oldParentTaxon = taxon.getTaxonomicParent();
51
	}
52
	
53
	/* (non-Javadoc)
54
	 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
55
	 */
56
	@Override
57
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
58
			throws ExecutionException {
59
		
60
		TaxonUtil.moveTaxonBaseIsolated(taxon.getUuid(), newParentTaxon.getUuid());
61
		
62
		return Status.OK_STATUS;
63
	}
64

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

    
74
	/* (non-Javadoc)
75
	 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
76
	 */
77
	@Override
78
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
79
			throws ExecutionException {
80
		
81
		TaxonUtil.moveTaxonBaseIsolated(taxon.getUuid(), oldParentTaxon.getUuid());
82
		
83
		return Status.OK_STATUS;
84
	}
85
}
(26-26/28)