ecd062b5cc7f908ae5a34a378783d206bb3953a0
[taxeditor.git] / eu.etaxonomy.taxeditor.navigation / src / main / java / eu / etaxonomy / taxeditor / navigation / navigator / operation / MoveTaxonOperation.java
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.navigation.navigator.TreeNodeDropAdapter.MovingType;
28 import eu.etaxonomy.taxeditor.operation.AbstractPersistentPostOperation;
29 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
30 import eu.etaxonomy.taxeditor.store.CdmStore;
31
32 /**
33 * Change the taxonomic parent of a given taxon.
34 *
35 * @author n.hoffmann
36 * @created 16.01.2009
37 * @version 1.0
38 */
39 public class MoveTaxonOperation extends AbstractPersistentPostOperation {
40
41 /**
42 * A reference to the new taxonomical parent.
43 */
44 private final ITaxonTreeNode newParentTreeNode;
45 /**
46 * A reference to the former taxonomical parents
47 */
48 //private Map<TaxonNode, ITaxonTreeNode> oldParentTreeNodes;
49
50 private final Set<UUID> taxonNodesUuid;
51 private final MovingType moveToParentNode;
52 /**
53 * <p>Constructor for MoveTaxonOperation.</p>
54 *
55 * @param label a {@link java.lang.String} object.
56 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
57 * @param taxonNodes a {@link java.util.Set} object.
58 * @param newParentTreeNode a {@link eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode} object.
59 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
60 * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
61 */
62 public MoveTaxonOperation(String label, IUndoContext undoContext,
63 Set<UUID> taxonNodesUUIDToMove, ITaxonTreeNode newParentTreeNode, IPostOperationEnabled postOperationEnabled, IConversationEnabled conversationEnabled, MovingType moveToParentNode) {
64 super(label, undoContext, postOperationEnabled, conversationEnabled);
65
66 this.taxonNodesUuid = taxonNodesUUIDToMove;
67 /*for (TaxonNode node:taxonNodes){
68 this.taxonNodes.add(service.load(node.getUuid()));
69 }*/
70
71 this.newParentTreeNode = newParentTreeNode;
72 this.moveToParentNode = moveToParentNode;
73 // Save old parent ITaxonTreeNodes for undo
74
75 //this.parentNode = taxonNode.getParent();
76 }
77
78 /* (non-Javadoc)
79 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
80 */
81 /** {@inheritDoc} */
82 @Override
83 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
84 throws ExecutionException {
85 bind();
86 monitor.worked(20);
87 UpdateResult result;
88 switch(this.moveToParentNode){
89 case CHILD:
90 result = CdmStore.getService(ITaxonNodeService.class).moveTaxonNodes(this.taxonNodesUuid,newParentTreeNode.getUuid(), 0);
91 case PREVIOUS:
92 result = CdmStore.getService(ITaxonNodeService.class).moveTaxonNodes(this.taxonNodesUuid,newParentTreeNode.getUuid(), 1);
93 case BEHIND:
94 result = CdmStore.getService(ITaxonNodeService.class).moveTaxonNodes(this.taxonNodesUuid,newParentTreeNode.getUuid(), 2);
95 }
96
97 // try {
98 // for (TaxonNode taxonNode : taxonNodes){
99 // TaxonNode newTaxonNode = newParentTreeNode.addChildNode(taxonNode,
100 // newParentTreeNode.getReference(), newParentTreeNode.getMicroReference());
101 // //taxonNodes.add(newTaxonNode);
102 //
103 // monitor.worked(2);
104 // }
105 // } catch(IllegalAncestryException e) {
106 // MessagingUtils.warningDialog("Illegal ancestry", this, e.getMessage());
107 // }
108 monitor.worked(40);
109
110 return postExecute(null);
111 }
112
113 /* (non-Javadoc)
114 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
115 */
116 /** {@inheritDoc} */
117 @Override
118 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
119 throws ExecutionException {
120 return execute(monitor, info);
121 }
122
123 /* (non-Javadoc)
124 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
125 */
126 /** {@inheritDoc} */
127 @Override
128 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
129 throws ExecutionException {
130 MessagingUtils.warn(this.getClass(), "Not implemented yet.");
131
132 // iterate over oldParentTreeNodes, delete each TaxonNode from its actual parent and add to its former parent
133
134 return Status.OK_STATUS;
135 }
136 }