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
;
12 import org
.eclipse
.core
.commands
.ExecutionException
;
13 import org
.eclipse
.core
.commands
.operations
.IUndoContext
;
14 import org
.eclipse
.core
.runtime
.IAdaptable
;
15 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
16 import org
.eclipse
.core
.runtime
.IStatus
;
17 import org
.eclipse
.core
.runtime
.Status
;
19 import eu
.etaxonomy
.cdm
.api
.conversation
.IConversationEnabled
;
20 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonNodeService
;
21 import eu
.etaxonomy
.cdm
.api
.service
.UpdateResult
;
22 import eu
.etaxonomy
.cdm
.model
.taxon
.ITaxonTreeNode
;
23 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
24 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
25 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPersistentPostOperation
;
26 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
27 import eu
.etaxonomy
.taxeditor
.session
.ICdmEntitySessionEnabled
;
28 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
31 * Change the taxonomic parent of a given taxon.
37 public class MoveTaxonOperation
extends AbstractPersistentPostOperation
{
40 * A reference to the new taxonomical parent.
42 private final ITaxonTreeNode newParentTreeNode
;
44 * A reference to the former taxonomical parents
49 private final TaxonNode taxonNode
;
50 private final boolean moveToParentNode
;
53 * <p>Constructor for MoveTaxonOperation.</p>
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.
63 public MoveTaxonOperation(String label
,
64 IUndoContext undoContext
,
65 TaxonNode taxonNodeToMove
,
66 ITaxonTreeNode newParentTreeNode
,
67 IPostOperationEnabled postOperationEnabled
,
68 IConversationEnabled conversationEnabled
,
69 boolean moveToParentNode
) {
70 this(label
, undoContext
, taxonNodeToMove
, newParentTreeNode
, postOperationEnabled
, conversationEnabled
, null, moveToParentNode
);
74 * <p>Constructor for MoveTaxonOperation.</p>
76 * @param label a {@link java.lang.String} object.
77 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
78 * @param taxonNodes a {@link java.util.Set} object.
79 * @param newParentTreeNode a {@link eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode} object.
80 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
81 * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
84 public MoveTaxonOperation(String label
,
85 IUndoContext undoContext
,
86 TaxonNode taxonNodeToMove
,
87 ITaxonTreeNode newParentTreeNode
,
88 IPostOperationEnabled postOperationEnabled
,
89 IConversationEnabled conversationEnabled
,
90 ICdmEntitySessionEnabled cdmEntitySessionEnabled
,
91 boolean moveToParentNode
) {
92 super(label
, undoContext
, postOperationEnabled
, conversationEnabled
, cdmEntitySessionEnabled
);
94 this.taxonNode
= taxonNodeToMove
;
95 /*for (TaxonNode node:taxonNodes){
96 this.taxonNodes.add(service.load(node.getUuid()));
100 this.newParentTreeNode
= newParentTreeNode
;
101 this.moveToParentNode
= moveToParentNode
;
102 // Save old parent ITaxonTreeNodes for undo
104 //this.parentNode = taxonNode.getParent();
109 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
113 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
114 throws ExecutionException
{
118 UpdateResult result
= CdmStore
.getService(ITaxonNodeService
.class).moveTaxonNode(this.taxonNode
.getUuid(),newParentTreeNode
.getUuid(), moveToParentNode
);
120 // for (TaxonNode taxonNode : taxonNodes){
121 // TaxonNode newTaxonNode = newParentTreeNode.addChildNode(taxonNode,
122 // newParentTreeNode.getReference(), newParentTreeNode.getMicroReference());
123 // //taxonNodes.add(newTaxonNode);
125 // monitor.worked(2);
127 // } catch(IllegalAncestryException e) {
128 // MessagingUtils.warningDialog("Illegal ancestry", this, e.getMessage());
132 return postExecute(null);
136 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
140 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
141 throws ExecutionException
{
142 return execute(monitor
, info
);
146 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
150 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
151 throws ExecutionException
{
152 MessagingUtils
.warn(this.getClass(), "Not implemented yet.");
154 // iterate over oldParentTreeNodes, delete each TaxonNode from its actual parent and add to its former parent
156 return Status
.OK_STATUS
;