1120e707f019403f1c7aa4abb4f9b7f3685419fc
[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 /** {@inheritDoc} */
79 @Override
80 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
81 throws ExecutionException {
82 bind();
83 monitor.worked(20);
84 UpdateResult result;
85 switch(this.moveToParentNode){
86 case CHILD:
87 result = CdmStore.getService(ITaxonNodeService.class).moveTaxonNodes(this.taxonNodesUuid,newParentTreeNode.getUuid(), 0);
88 case PREVIOUS:
89 result = CdmStore.getService(ITaxonNodeService.class).moveTaxonNodes(this.taxonNodesUuid,newParentTreeNode.getUuid(), 1);
90 case BEHIND:
91 result = CdmStore.getService(ITaxonNodeService.class).moveTaxonNodes(this.taxonNodesUuid,newParentTreeNode.getUuid(), 2);
92 }
93
94 // try {
95 // for (TaxonNode taxonNode : taxonNodes){
96 // TaxonNode newTaxonNode = newParentTreeNode.addChildNode(taxonNode,
97 // newParentTreeNode.getReference(), newParentTreeNode.getMicroReference());
98 // //taxonNodes.add(newTaxonNode);
99 //
100 // monitor.worked(2);
101 // }
102 // } catch(IllegalAncestryException e) {
103 // MessagingUtils.warningDialog("Illegal ancestry", this, e.getMessage());
104 // }
105 monitor.worked(40);
106
107 return postExecute(null);
108 }
109
110 /** {@inheritDoc} */
111 @Override
112 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
113 throws ExecutionException {
114 return execute(monitor, info);
115 }
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 }