Project

General

Profile

Download (4.53 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.Set;
13
import java.util.UUID;
14

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

    
22
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
23
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
24
import eu.etaxonomy.cdm.api.service.UpdateResult;
25
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
26
import eu.etaxonomy.taxeditor.model.MessagingUtils;
27
import eu.etaxonomy.taxeditor.operation.AbstractPersistentPostOperation;
28
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
29
import eu.etaxonomy.taxeditor.store.CdmStore;
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 final ITaxonTreeNode newParentTreeNode;
44
	/**
45
	 * A reference to the former taxonomical parents
46
	 */
47
	//private Map<TaxonNode, ITaxonTreeNode> oldParentTreeNodes;
48

    
49
	private final Set<UUID> taxonNodesUuid;
50
	private final boolean moveToParentNode;
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<UUID> taxonNodesUUIDToMove, ITaxonTreeNode newParentTreeNode, IPostOperationEnabled postOperationEnabled, IConversationEnabled conversationEnabled, boolean moveToParentNode) {
63
		super(label, undoContext, postOperationEnabled, conversationEnabled);
64

    
65
		this.taxonNodesUuid = taxonNodesUUIDToMove;
66
		/*for (TaxonNode node:taxonNodes){
67
			this.taxonNodes.add(service.load(node.getUuid()));
68
		}*/
69

    
70
		this.newParentTreeNode = newParentTreeNode;
71
		this.moveToParentNode = moveToParentNode;
72
		// Save old parent ITaxonTreeNodes for undo
73

    
74
		//this.parentNode = taxonNode.getParent();
75
	}
76

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

    
87
		UpdateResult result = CdmStore.getService(ITaxonNodeService.class).moveTaxonNodes(this.taxonNodesUuid,newParentTreeNode.getUuid(), moveToParentNode);
88
//		try {
89
//			for (TaxonNode taxonNode : taxonNodes){
90
//				TaxonNode newTaxonNode = newParentTreeNode.addChildNode(taxonNode,
91
//						newParentTreeNode.getReference(), newParentTreeNode.getMicroReference());
92
//				//taxonNodes.add(newTaxonNode);
93
//
94
//				monitor.worked(2);
95
//			}
96
//		} catch(IllegalAncestryException e) {
97
//			MessagingUtils.warningDialog("Illegal ancestry", this, e.getMessage());
98
//		}
99
		monitor.worked(40);
100

    
101
		return postExecute(null);
102
	}
103

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

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

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

    
125
		return Status.OK_STATUS;
126
	}
127
}
(5-5/9)