Project

General

Profile

Download (4.22 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.navigation.navigator.operation;
11

    
12
import java.util.HashMap;
13
import java.util.Map;
14
import java.util.Set;
15

    
16
import org.eclipse.core.commands.ExecutionException;
17
import org.eclipse.core.commands.operations.IUndoContext;
18
import org.eclipse.core.runtime.IAdaptable;
19
import org.eclipse.core.runtime.IProgressMonitor;
20
import org.eclipse.core.runtime.IStatus;
21
import org.eclipse.core.runtime.Status;
22

    
23
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
24
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
25
import eu.etaxonomy.cdm.model.taxon.IllegalAncestryException;
26
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
27
import eu.etaxonomy.taxeditor.operation.AbstractPersistentPostOperation;
28
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
29
import eu.etaxonomy.taxeditor.store.StoreUtil;
30

    
31
/**
32
 * Change the taxonomic parent of a given taxon.
33
 *
34
 * @author n.hoffmann
35
 * @created 16.01.2009
36
 * @version 1.0
37
 */
38
public class MoveTaxonOperation extends AbstractPersistentPostOperation {
39

    
40
	/**
41
	 * A reference to the new taxonomical parent.
42
	 */
43
	private ITaxonTreeNode newParentTreeNode;
44
	/**
45
	 * A reference to the former taxonomical parents
46
	 */
47
	private Map<TaxonNode, ITaxonTreeNode> oldParentTreeNodes;
48

    
49
	private Set<TaxonNode> taxonNodes;
50

    
51
	/**
52
	 * <p>Constructor for MoveTaxonOperation.</p>
53
	 *
54
	 * @param label a {@link java.lang.String} object.
55
	 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
56
	 * @param taxonNodes a {@link java.util.Set} object.
57
	 * @param newParentTreeNode a {@link eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode} object.
58
	 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
59
	 * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
60
	 */
61
	public MoveTaxonOperation(String label, IUndoContext undoContext,
62
			Set<TaxonNode> taxonNodes, ITaxonTreeNode newParentTreeNode, IPostOperationEnabled postOperationEnabled, IConversationEnabled conversationEnabled) {
63
		super(label, undoContext, postOperationEnabled, conversationEnabled);
64

    
65
		this.taxonNodes = taxonNodes;
66

    
67
		this.newParentTreeNode = newParentTreeNode;
68

    
69
		// Save old parent ITaxonTreeNodes for undo
70
		oldParentTreeNodes = new HashMap<TaxonNode, ITaxonTreeNode>();
71
		for(TaxonNode taxonNode : taxonNodes){
72
			this.oldParentTreeNodes.put(taxonNode, taxonNode.getParent());
73
		}
74
	}
75

    
76
	/* (non-Javadoc)
77
	 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
78
	 */
79
	/** {@inheritDoc} */
80
	@Override
81
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
82
			throws ExecutionException {
83
		bind();
84
		monitor.worked(20);
85

    
86
		try {
87
			for (TaxonNode taxonNode : taxonNodes){
88
				TaxonNode newTaxonNode = newParentTreeNode.addChildNode(taxonNode,
89
						newParentTreeNode.getReference(), newParentTreeNode.getMicroReference());
90
				taxonNodes.add(newTaxonNode);
91
				monitor.worked(2);
92
			}
93
		} catch(IllegalAncestryException e) {
94
			StoreUtil.warningDialog("Illegal ancestry", this, e.getMessage());
95
		}
96
		monitor.worked(40);
97

    
98
		return postExecute(null);
99
	}
100

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

    
111
	/* (non-Javadoc)
112
	 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
113
	 */
114
	/** {@inheritDoc} */
115
	@Override
116
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
117
			throws ExecutionException {
118
		StoreUtil.warn(this.getClass(), "Not implemented yet.");
119

    
120
		// iterate over oldParentTreeNodes, delete each TaxonNode from its actual parent and add to its former parent
121

    
122
		return Status.OK_STATUS;
123
	}
124
}
(5-5/5)