2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.navigation
.navigator
.operation
;
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
;
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
.cdm
.model
.taxon
.TaxonNode
;
27 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
28 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPersistentPostOperation
;
29 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
30 import eu
.etaxonomy
.taxeditor
.session
.ICdmEntitySessionEnabled
;
31 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
34 * Change the taxonomic parent of a given taxon.
40 public class MoveTaxonOperation
extends AbstractPersistentPostOperation
{
43 * A reference to the new taxonomical parent.
45 private final ITaxonTreeNode newParentTreeNode
;
47 * A reference to the former taxonomical parents
50 private final Map
<TaxonNode
, ITaxonTreeNode
> oldParentTreeNodes
;
52 private final Set
<TaxonNode
> taxonNodes
;
55 private final TaxonNode taxonNode
;
56 private final boolean moveToParentNode
;
58 * <p>Constructor for MoveTaxonOperation.</p>
60 * @param label a {@link java.lang.String} object.
61 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
62 * @param taxonNodes a {@link java.util.Set} object.
63 * @param newParentTreeNode a {@link eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode} object.
64 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
65 * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
68 public MoveTaxonOperation(String label
,
69 IUndoContext undoContext
,
70 TaxonNode taxonNodeToMove
,
71 ITaxonTreeNode newParentTreeNode
,
72 IPostOperationEnabled postOperationEnabled
,
73 IConversationEnabled conversationEnabled
,
74 ICdmEntitySessionEnabled cdmEntitySessionEnabled
,
75 boolean moveToParentNode
) {
76 super(label
, undoContext
, postOperationEnabled
, conversationEnabled
, cdmEntitySessionEnabled
);
78 this.taxonNode
= taxonNodeToMove
;
79 /*for (TaxonNode node:taxonNodes){
80 this.taxonNodes.add(service.load(node.getUuid()));
84 this.newParentTreeNode
= newParentTreeNode
;
85 this.moveToParentNode
= moveToParentNode
;
86 // Save old parent ITaxonTreeNodes for undo
88 //this.parentNode = taxonNode.getParent();
93 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
97 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
98 throws ExecutionException
{
102 UpdateResult result
= CdmStore
.getService(ITaxonNodeService
.class).moveTaxonNode(this.taxonNode
.getUuid(),newParentTreeNode
.getUuid(), moveToParentNode
);
104 // for (TaxonNode taxonNode : taxonNodes){
105 // TaxonNode newTaxonNode = newParentTreeNode.addChildNode(taxonNode,
106 // newParentTreeNode.getReference(), newParentTreeNode.getMicroReference());
107 // //taxonNodes.add(newTaxonNode);
109 // monitor.worked(2);
111 // } catch(IllegalAncestryException e) {
112 // MessagingUtils.warningDialog("Illegal ancestry", this, e.getMessage());
116 return postExecute(null);
120 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
124 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
125 throws ExecutionException
{
126 return execute(monitor
, info
);
130 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
134 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
135 throws ExecutionException
{
136 MessagingUtils
.warn(this.getClass(), "Not implemented yet.");
138 // iterate over oldParentTreeNodes, delete each TaxonNode from its actual parent and add to its former parent
140 return Status
.OK_STATUS
;